ua_connection.h 3.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. /*
  2. * Copyright (C) 2014 the contributors as stated in the AUTHORS file
  3. *
  4. * This file is part of open62541. open62541 is free software: you can
  5. * redistribute it and/or modify it under the terms of the GNU Lesser General
  6. * Public License, version 3 (as published by the Free Software Foundation) with
  7. * a static linking exception as stated in the LICENSE file provided with
  8. * open62541.
  9. *
  10. * open62541 is distributed in the hope that it will be useful, but WITHOUT ANY
  11. * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
  12. * A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
  13. * details.
  14. */
  15. #ifndef UA_CONNECTION_H_
  16. #define UA_CONNECTION_H_
  17. #ifdef __cplusplus
  18. extern "C" {
  19. #endif
  20. #include "ua_types.h"
  21. /**
  22. * @defgroup communication Communication
  23. *
  24. * @{
  25. */
  26. /** Used for zero-copy communication. The array of bytestrings is sent over the
  27. network as a single buffer. */
  28. typedef struct UA_ByteStringArray {
  29. UA_UInt32 stringsSize;
  30. UA_ByteString *strings;
  31. } UA_ByteStringArray;
  32. typedef enum UA_ConnectionState {
  33. UA_CONNECTION_OPENING, ///< The socket is open, but the HEL/ACK handshake is not done
  34. UA_CONNECTION_ESTABLISHED, ///< The socket is open and the connection configured
  35. UA_CONNECTION_CLOSED, ///< The socket has been closed and the connection will be deleted
  36. } UA_ConnectionState;
  37. typedef struct UA_ConnectionConfig {
  38. UA_UInt32 protocolVersion;
  39. UA_UInt32 sendBufferSize;
  40. UA_UInt32 recvBufferSize;
  41. UA_UInt32 maxMessageSize;
  42. UA_UInt32 maxChunkCount;
  43. } UA_ConnectionConfig;
  44. extern const UA_EXPORT UA_ConnectionConfig UA_ConnectionConfig_standard;
  45. /* Forward declaration */
  46. struct UA_SecureChannel;
  47. typedef struct UA_SecureChannel UA_SecureChannel;
  48. struct UA_Connection;
  49. typedef struct UA_Connection UA_Connection;
  50. /**
  51. * The connection to a single client (or server). The connection is defined independent of the
  52. * underlying network layer implementation. This allows a plugging-in custom implementations (e.g.
  53. * an embedded TCP stack)
  54. */
  55. struct UA_Connection {
  56. UA_ConnectionState state;
  57. UA_ConnectionConfig localConf;
  58. UA_ConnectionConfig remoteConf;
  59. UA_SecureChannel *channel; ///> The securechannel that is attached to this connection (or null)
  60. UA_Int32 sockfd; ///> Most connectivity solutions run on sockets. Having the socket id here simplifies the design.
  61. void *handle; ///> A pointer to the networklayer
  62. UA_ByteString incompleteMessage; ///> Half-received messages (tcp is a streaming protocol) get stored here
  63. UA_StatusCode (*getBuffer)(UA_Connection *connection, UA_ByteString *buf, size_t minSize); ///> Attach the data array to the buffer. Fails if minSize is larger than remoteConf allows
  64. void (*releaseBuffer)(UA_Connection *connection, UA_ByteString *buf); ///> Release the buffer
  65. UA_StatusCode (*write)(UA_Connection *connection, UA_ByteStringArray buf); ///> The bytestrings cannot be reused after sending!
  66. UA_StatusCode (*recv)(UA_Connection *connection, UA_ByteString *response, UA_UInt32 timeout); // timeout in milliseconds
  67. void (*close)(UA_Connection *connection);
  68. };
  69. void UA_EXPORT UA_Connection_init(UA_Connection *connection);
  70. void UA_EXPORT UA_Connection_deleteMembers(UA_Connection *connection);
  71. void UA_EXPORT UA_Connection_detachSecureChannel(UA_Connection *connection);
  72. void UA_EXPORT UA_Connection_attachSecureChannel(UA_Connection *connection, UA_SecureChannel *channel);
  73. /** Returns a string of complete message (the length entry is decoded for that).
  74. If the received message is incomplete, it is retained in the connection. */
  75. UA_ByteString UA_EXPORT UA_Connection_completeMessages(UA_Connection *connection, UA_ByteString received);
  76. /** @} */
  77. #ifdef __cplusplus
  78. } // extern "C"
  79. #endif
  80. #endif /* UA_CONNECTION_H_ */