|
@@ -21,13 +21,10 @@ extern "C" {
|
|
#endif
|
|
#endif
|
|
|
|
|
|
#include "ua_types.h"
|
|
#include "ua_types.h"
|
|
-#include "ua_job.h"
|
|
|
|
|
|
|
|
-typedef enum UA_ConnectionState {
|
|
|
|
- UA_CONNECTION_OPENING, ///< The socket is open, but the HEL/ACK handshake is not done
|
|
|
|
- UA_CONNECTION_ESTABLISHED, ///< The socket is open and the connection configured
|
|
|
|
- UA_CONNECTION_CLOSED, ///< The socket has been closed and the connection will be deleted
|
|
|
|
-} UA_ConnectionState;
|
|
|
|
|
|
+/* Forward declaration */
|
|
|
|
+struct UA_SecureChannel;
|
|
|
|
+typedef struct UA_SecureChannel UA_SecureChannel;
|
|
|
|
|
|
typedef struct UA_ConnectionConfig {
|
|
typedef struct UA_ConnectionConfig {
|
|
UA_UInt32 protocolVersion;
|
|
UA_UInt32 protocolVersion;
|
|
@@ -39,9 +36,14 @@ typedef struct UA_ConnectionConfig {
|
|
|
|
|
|
extern const UA_EXPORT UA_ConnectionConfig UA_ConnectionConfig_standard;
|
|
extern const UA_EXPORT UA_ConnectionConfig UA_ConnectionConfig_standard;
|
|
|
|
|
|
-/* Forward declaration */
|
|
|
|
-struct UA_SecureChannel;
|
|
|
|
-typedef struct UA_SecureChannel UA_SecureChannel;
|
|
|
|
|
|
+typedef enum UA_ConnectionState {
|
|
|
|
+ UA_CONNECTION_OPENING, /* The socket is open, but the HEL/ACK handshake is not done */
|
|
|
|
+ UA_CONNECTION_ESTABLISHED, /* The socket is open and the connection configured */
|
|
|
|
+ UA_CONNECTION_CLOSED, /* The socket has been closed and the connection will be deleted */
|
|
|
|
+} UA_ConnectionState;
|
|
|
|
+
|
|
|
|
+struct UA_Connection;
|
|
|
|
+typedef struct UA_Connection UA_Connection;
|
|
|
|
|
|
/**
|
|
/**
|
|
* The connection to a single client (or server). The connection is defined independent of the
|
|
* The connection to a single client (or server). The connection is defined independent of the
|
|
@@ -52,73 +54,48 @@ struct UA_Connection {
|
|
UA_ConnectionState state;
|
|
UA_ConnectionState state;
|
|
UA_ConnectionConfig localConf;
|
|
UA_ConnectionConfig localConf;
|
|
UA_ConnectionConfig remoteConf;
|
|
UA_ConnectionConfig remoteConf;
|
|
- UA_SecureChannel *channel; ///< The securechannel that is attached to this connection (or null)
|
|
|
|
- UA_Int32 sockfd; ///< Most connectivity solutions run on sockets. Having the socket id here
|
|
|
|
- /// simplifies the design.
|
|
|
|
- void *handle; ///< A pointer to the networklayer
|
|
|
|
- UA_ByteString incompleteMessage; ///< A half-received message (TCP is a streaming protocol) is stored here
|
|
|
|
-
|
|
|
|
- /** Get a buffer for sending */
|
|
|
|
|
|
+ UA_SecureChannel *channel; /* The securechannel that is attached to this connection */
|
|
|
|
+ UA_Int32 sockfd; /* Most connectivity solutions run on sockets. Having the
|
|
|
|
+ socket id here simplifies the design. */
|
|
|
|
+ void *handle; /* A pointer to the networklayer */
|
|
|
|
+ UA_ByteString incompleteMessage; /* A half-received message (TCP is a streaming protocol) is
|
|
|
|
+ stored here */
|
|
|
|
+
|
|
|
|
+ /* Get a buffer for sending */
|
|
UA_StatusCode (*getSendBuffer)(UA_Connection *connection, size_t length, UA_ByteString *buf);
|
|
UA_StatusCode (*getSendBuffer)(UA_Connection *connection, size_t length, UA_ByteString *buf);
|
|
|
|
|
|
- /** Release the send buffer manually */
|
|
|
|
|
|
+ /* Release the send buffer manually */
|
|
void (*releaseSendBuffer)(UA_Connection *connection, UA_ByteString *buf);
|
|
void (*releaseSendBuffer)(UA_Connection *connection, UA_ByteString *buf);
|
|
|
|
|
|
- /**
|
|
|
|
- * Sends a message over the connection.
|
|
|
|
|
|
+ /* Sends a message over the connection. The message buffer is always freed, even if sending
|
|
|
|
+ * fails.
|
|
|
|
+ *
|
|
* @param connection The connection
|
|
* @param connection The connection
|
|
- * @param buf The message buffer is always released (freed) internally
|
|
|
|
- * @return Returns an error code or UA_STATUSCODE_GOOD.
|
|
|
|
- */
|
|
|
|
|
|
+ * @param buf The message buffer
|
|
|
|
+ * @return Returns an error code or UA_STATUSCODE_GOOD. */
|
|
UA_StatusCode (*send)(UA_Connection *connection, UA_ByteString *buf);
|
|
UA_StatusCode (*send)(UA_Connection *connection, UA_ByteString *buf);
|
|
|
|
|
|
- /**
|
|
|
|
- * Receive a message from the remote connection
|
|
|
|
|
|
+ /* Receive a message from the remote connection
|
|
|
|
+ *
|
|
* @param connection The connection
|
|
* @param connection The connection
|
|
* @param response The response string. It is allocated by the connection and needs to be freed
|
|
* @param response The response string. It is allocated by the connection and needs to be freed
|
|
with connection->releaseBuffer
|
|
with connection->releaseBuffer
|
|
* @param timeout Timeout of the recv operation in milliseconds
|
|
* @param timeout Timeout of the recv operation in milliseconds
|
|
* @return Returns UA_STATUSCODE_BADCOMMUNICATIONERROR if the recv operation can be repeated,
|
|
* @return Returns UA_STATUSCODE_BADCOMMUNICATIONERROR if the recv operation can be repeated,
|
|
* UA_STATUSCODE_GOOD if it succeeded and UA_STATUSCODE_BADCONNECTIONCLOSED if the
|
|
* UA_STATUSCODE_GOOD if it succeeded and UA_STATUSCODE_BADCONNECTIONCLOSED if the
|
|
- * connection was closed.
|
|
|
|
- */
|
|
|
|
|
|
+ * connection was closed. */
|
|
UA_StatusCode (*recv)(UA_Connection *connection, UA_ByteString *response, UA_UInt32 timeout);
|
|
UA_StatusCode (*recv)(UA_Connection *connection, UA_ByteString *response, UA_UInt32 timeout);
|
|
|
|
|
|
- /** Release the buffer of a received message */
|
|
|
|
|
|
+ /* Release the buffer of a received message */
|
|
void (*releaseRecvBuffer)(UA_Connection *connection, UA_ByteString *buf);
|
|
void (*releaseRecvBuffer)(UA_Connection *connection, UA_ByteString *buf);
|
|
|
|
|
|
- /** Close the connection */
|
|
|
|
|
|
+ /* Close the connection */
|
|
void (*close)(UA_Connection *connection);
|
|
void (*close)(UA_Connection *connection);
|
|
};
|
|
};
|
|
|
|
|
|
void UA_EXPORT UA_Connection_init(UA_Connection *connection);
|
|
void UA_EXPORT UA_Connection_init(UA_Connection *connection);
|
|
void UA_EXPORT UA_Connection_deleteMembers(UA_Connection *connection);
|
|
void UA_EXPORT UA_Connection_deleteMembers(UA_Connection *connection);
|
|
|
|
|
|
-void UA_EXPORT UA_Connection_detachSecureChannel(UA_Connection *connection);
|
|
|
|
-void UA_EXPORT UA_Connection_attachSecureChannel(UA_Connection *connection, UA_SecureChannel *channel);
|
|
|
|
-
|
|
|
|
-/**
|
|
|
|
- * The network layer may receive chopped up messages since TCP is a streaming
|
|
|
|
- * protocol. Furthermore, the networklayer may operate on ringbuffers or
|
|
|
|
- * statically assigned memory.
|
|
|
|
- *
|
|
|
|
- * If an entire message is received, it is forwarded directly. But the memory
|
|
|
|
- * needs to be freed with the networklayer-specific mechanism. If a half message
|
|
|
|
- * is received, we copy it into a local buffer. Then, the stack-specific free
|
|
|
|
- * needs to be used.
|
|
|
|
- *
|
|
|
|
- * @param connection The connection
|
|
|
|
- * @param message The received message. The content may be overwritten when a
|
|
|
|
- * previsouly received buffer is completed.
|
|
|
|
- * @param realloced The Boolean value is set to true if the outgoing message has
|
|
|
|
- * been reallocated from the network layer.
|
|
|
|
- * @return Returns UA_STATUSCODE_GOOD or an error code. When an error occurs, the ingoing message
|
|
|
|
- * and the current buffer in the connection are freed.
|
|
|
|
- */
|
|
|
|
-UA_StatusCode UA_EXPORT
|
|
|
|
-UA_Connection_completeMessages(UA_Connection *connection, UA_ByteString * UA_RESTRICT message,
|
|
|
|
- UA_Boolean * UA_RESTRICT realloced);
|
|
|
|
-
|
|
|
|
#ifdef __cplusplus
|
|
#ifdef __cplusplus
|
|
} // extern "C"
|
|
} // extern "C"
|
|
#endif
|
|
#endif
|