ua_connection.h 3.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  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. typedef enum UA_ConnectionState {
  27. UA_CONNECTION_OPENING, ///< The socket is open, but the HEL/ACK handshake is not done
  28. UA_CONNECTION_ESTABLISHED, ///< The socket is open and the connection configured
  29. UA_CONNECTION_CLOSED, ///< The socket has been closed and the connection will be deleted
  30. } UA_ConnectionState;
  31. typedef struct UA_ConnectionConfig {
  32. UA_UInt32 protocolVersion;
  33. UA_UInt32 sendBufferSize;
  34. UA_UInt32 recvBufferSize;
  35. UA_UInt32 maxMessageSize;
  36. UA_UInt32 maxChunkCount;
  37. } UA_ConnectionConfig;
  38. extern const UA_EXPORT UA_ConnectionConfig UA_ConnectionConfig_standard;
  39. /* Forward declaration */
  40. struct UA_SecureChannel;
  41. typedef struct UA_SecureChannel UA_SecureChannel;
  42. struct UA_Connection;
  43. typedef struct UA_Connection UA_Connection;
  44. /**
  45. * The connection to a single client (or server). The connection is defined independent of the
  46. * underlying network layer implementation. This allows a plugging-in custom implementations (e.g.
  47. * an embedded TCP stack)
  48. */
  49. struct UA_Connection {
  50. UA_ConnectionState state;
  51. UA_ConnectionConfig localConf;
  52. UA_ConnectionConfig remoteConf;
  53. UA_SecureChannel *channel; ///> The securechannel that is attached to this connection (or null)
  54. UA_Int32 sockfd; ///> Most connectivity solutions run on sockets. Having the socket id here simplifies the design.
  55. void *handle; ///> A pointer to the networklayer
  56. UA_ByteString incompleteMessage; ///> Half-received messages (tcp is a streaming protocol) get stored here
  57. 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
  58. void (*releaseBuffer)(UA_Connection *connection, UA_ByteString *buf); ///> Release the buffer
  59. UA_StatusCode (*write)(UA_Connection *connection, const UA_ByteString *buf); ///> The bytestrings cannot be reused after sending!
  60. UA_StatusCode (*recv)(UA_Connection *connection, UA_ByteString *response, UA_UInt32 timeout); // timeout in milliseconds
  61. void (*close)(UA_Connection *connection);
  62. };
  63. void UA_EXPORT UA_Connection_init(UA_Connection *connection);
  64. void UA_EXPORT UA_Connection_deleteMembers(UA_Connection *connection);
  65. void UA_EXPORT UA_Connection_detachSecureChannel(UA_Connection *connection);
  66. void UA_EXPORT UA_Connection_attachSecureChannel(UA_Connection *connection, UA_SecureChannel *channel);
  67. /** Returns a string of complete message (the length entry is decoded for that).
  68. If the received message is incomplete, it is retained in the connection. */
  69. UA_ByteString UA_EXPORT UA_Connection_completeMessages(UA_Connection *connection, UA_ByteString received);
  70. /** @} */
  71. #ifdef __cplusplus
  72. } // extern "C"
  73. #endif
  74. #endif /* UA_CONNECTION_H_ */