ua_connection.h 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  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. /* Forward declaration */
  22. struct UA_SecureChannel;
  23. typedef struct UA_SecureChannel UA_SecureChannel;
  24. typedef struct UA_ConnectionConfig {
  25. UA_UInt32 protocolVersion;
  26. UA_UInt32 sendBufferSize;
  27. UA_UInt32 recvBufferSize;
  28. UA_UInt32 maxMessageSize;
  29. UA_UInt32 maxChunkCount;
  30. } UA_ConnectionConfig;
  31. extern const UA_EXPORT UA_ConnectionConfig UA_ConnectionConfig_standard;
  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. struct UA_Connection;
  38. typedef struct UA_Connection UA_Connection;
  39. /**
  40. * The connection to a single client (or server). The connection is defined independent of the
  41. * underlying network layer implementation. This allows a plugging-in custom implementations (e.g.
  42. * an embedded TCP stack)
  43. */
  44. struct UA_Connection {
  45. UA_ConnectionState state;
  46. UA_ConnectionConfig localConf;
  47. UA_ConnectionConfig remoteConf;
  48. UA_SecureChannel *channel; /* The securechannel that is attached to this connection */
  49. UA_Int32 sockfd; /* Most connectivity solutions run on sockets. Having the
  50. socket id here simplifies the design. */
  51. void *handle; /* A pointer to the networklayer */
  52. UA_ByteString incompleteMessage; /* A half-received message (TCP is a streaming protocol) is
  53. stored here */
  54. /* Get a buffer for sending */
  55. UA_StatusCode (*getSendBuffer)(UA_Connection *connection, size_t length, UA_ByteString *buf);
  56. /* Release the send buffer manually */
  57. void (*releaseSendBuffer)(UA_Connection *connection, UA_ByteString *buf);
  58. /* Sends a message over the connection. The message buffer is always freed, even if sending
  59. * fails.
  60. *
  61. * @param connection The connection
  62. * @param buf The message buffer
  63. * @return Returns an error code or UA_STATUSCODE_GOOD. */
  64. UA_StatusCode (*send)(UA_Connection *connection, UA_ByteString *buf);
  65. /* Receive a message from the remote connection
  66. *
  67. * @param connection The connection
  68. * @param response The response string. It is allocated by the connection and needs to be freed
  69. with connection->releaseBuffer
  70. * @param timeout Timeout of the recv operation in milliseconds
  71. * @return Returns UA_STATUSCODE_BADCOMMUNICATIONERROR if the recv operation can be repeated,
  72. * UA_STATUSCODE_GOOD if it succeeded and UA_STATUSCODE_BADCONNECTIONCLOSED if the
  73. * connection was closed. */
  74. UA_StatusCode (*recv)(UA_Connection *connection, UA_ByteString *response, UA_UInt32 timeout);
  75. /* Release the buffer of a received message */
  76. void (*releaseRecvBuffer)(UA_Connection *connection, UA_ByteString *buf);
  77. /* Close the connection */
  78. void (*close)(UA_Connection *connection);
  79. };
  80. void UA_EXPORT UA_Connection_init(UA_Connection *connection);
  81. void UA_EXPORT UA_Connection_deleteMembers(UA_Connection *connection);
  82. #ifdef __cplusplus
  83. } // extern "C"
  84. #endif
  85. #endif /* UA_CONNECTION_H_ */