ua_connection_internal.h 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. /* This Source Code Form is subject to the terms of the Mozilla Public
  2. * License, v. 2.0. If a copy of the MPL was not distributed with this
  3. * file, You can obtain one at http://mozilla.org/MPL/2.0/.
  4. *
  5. * Copyright 2016-2017 (c) Fraunhofer IOSB (Author: Julius Pfrommer)
  6. * Copyright 2016-2017 (c) Stefan Profanter, fortiss GmbH
  7. * Copyright 2017 (c) Florian Palm
  8. * Copyright 2017 (c) Mark Giraud, Fraunhofer IOSB
  9. */
  10. #ifndef UA_CONNECTION_INTERNAL_H_
  11. #define UA_CONNECTION_INTERNAL_H_
  12. #include "ua_plugin_network.h"
  13. #include "ua_transport_generated.h"
  14. _UA_BEGIN_DECLS
  15. /* Process the remote configuration in the HEL/ACK handshake. The connection
  16. * config is initialized with the local settings. */
  17. UA_StatusCode
  18. UA_Connection_processHELACK(UA_Connection *connection,
  19. const UA_ConnectionConfig *localConfig,
  20. const UA_ConnectionConfig *remoteConfig);
  21. /* The application can be the client or the server */
  22. typedef UA_StatusCode (*UA_Connection_processChunk)(void *application,
  23. UA_Connection *connection,
  24. UA_ByteString *chunk);
  25. /* The network layer may receive chopped up messages since TCP is a streaming
  26. * protocol. This method calls the processChunk callback on all full chunks that
  27. * were received. Dangling half-complete chunks are buffered in the connection
  28. * and considered for the next received packet.
  29. *
  30. * If an entire chunk is received, it is forwarded directly. But the memory
  31. * needs to be freed with the networklayer-specific mechanism. If a half message
  32. * is received, we copy it into a local buffer. Then, the stack-specific free
  33. * needs to be used.
  34. *
  35. * @param connection The connection
  36. * @param application The client or server application
  37. * @param processCallback The function pointer for processing each chunk
  38. * @param packet The received packet.
  39. * @return Returns UA_STATUSCODE_GOOD or an error code. When an error occurs,
  40. * the ingoing message and the current buffer in the connection are
  41. * freed. */
  42. UA_StatusCode
  43. UA_Connection_processChunks(UA_Connection *connection, void *application,
  44. UA_Connection_processChunk processCallback,
  45. const UA_ByteString *packet);
  46. /* Try to receive at least one complete chunk on the connection. This blocks the
  47. * current thread up to the given timeout.
  48. *
  49. * @param connection The connection
  50. * @param application The client or server application
  51. * @param processCallback The function pointer for processing each chunk
  52. * @param timeout The timeout (in milliseconds) the method will block at most.
  53. * @return Returns UA_STATUSCODE_GOOD or an error code. When an timeout occurs,
  54. * UA_STATUSCODE_GOODNONCRITICALTIMEOUT is returned. */
  55. UA_StatusCode
  56. UA_Connection_receiveChunksBlocking(UA_Connection *connection, void *application,
  57. UA_Connection_processChunk processCallback,
  58. UA_UInt32 timeout);
  59. UA_StatusCode
  60. UA_Connection_receiveChunksNonBlocking(UA_Connection *connection, void *application,
  61. UA_Connection_processChunk processCallback);
  62. /* When a fatal error occurs the Server shall send an Error Message to the
  63. * Client and close the socket. When a Client encounters one of these errors, it
  64. * shall also close the socket but does not send an Error Message. After the
  65. * socket is closed a Client shall try to reconnect automatically using the
  66. * mechanisms described in [...]. */
  67. void
  68. UA_Connection_sendError(UA_Connection *connection,
  69. UA_TcpErrorMessage *error);
  70. void UA_Connection_detachSecureChannel(UA_Connection *connection);
  71. void UA_Connection_attachSecureChannel(UA_Connection *connection,
  72. UA_SecureChannel *channel);
  73. _UA_END_DECLS
  74. #endif /* UA_CONNECTION_INTERNAL_H_ */