ua_connection_internal.h 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  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. #ifdef __cplusplus
  13. extern "C" {
  14. #endif
  15. #include "ua_plugin_network.h"
  16. #include "ua_transport_generated.h"
  17. /* The application can be the client or the server */
  18. typedef UA_StatusCode (*UA_Connection_processChunk)(void *application,
  19. UA_Connection *connection,
  20. UA_ByteString *chunk);
  21. /* The network layer may receive chopped up messages since TCP is a streaming
  22. * protocol. This method calls the processChunk callback on all full chunks that
  23. * were received. Dangling half-complete chunks are buffered in the connection
  24. * and considered for the next received packet.
  25. *
  26. * If an entire chunk is received, it is forwarded directly. But the memory
  27. * needs to be freed with the networklayer-specific mechanism. If a half message
  28. * is received, we copy it into a local buffer. Then, the stack-specific free
  29. * needs to be used.
  30. *
  31. * @param connection The connection
  32. * @param application The client or server application
  33. * @param processCallback The function pointer for processing each chunk
  34. * @param packet The received packet.
  35. * @return Returns UA_STATUSCODE_GOOD or an error code. When an error occurs,
  36. * the ingoing message and the current buffer in the connection are
  37. * freed. */
  38. UA_StatusCode
  39. UA_Connection_processChunks(UA_Connection *connection, void *application,
  40. UA_Connection_processChunk processCallback,
  41. const UA_ByteString *packet);
  42. /*
  43. * @param connection The connection
  44. * @param message The received message. The content may be overwritten when a
  45. * previsouly received buffer is completed.
  46. * @param realloced The Boolean value is set to true if the outgoing message has
  47. * been reallocated from the network layer.
  48. * @return Returns UA_STATUSCODE_GOOD or an error code. When an error occurs,
  49. * the ingoing message and the current buffer in the connection are
  50. * freed. */
  51. UA_StatusCode
  52. UA_Connection_completeMessages(UA_Connection *connection,
  53. UA_ByteString * UA_RESTRICT message,
  54. UA_Boolean * UA_RESTRICT realloced);
  55. /* Try to receive at least one complete chunk on the connection. This blocks the
  56. * current thread up to the given timeout.
  57. *
  58. * @param connection The connection
  59. * @param application The client or server application
  60. * @param processCallback The function pointer for processing each chunk
  61. * @param timeout The timeout (in milliseconds) the method will block at most.
  62. * @return Returns UA_STATUSCODE_GOOD or an error code. When an timeout occurs,
  63. * UA_STATUSCODE_GOODNONCRITICALTIMEOUT is returned. */
  64. UA_StatusCode
  65. UA_Connection_receiveChunksBlocking(UA_Connection *connection, void *application,
  66. UA_Connection_processChunk processCallback,
  67. UA_UInt32 timeout);
  68. UA_StatusCode
  69. UA_Connection_receiveChunksNonBlocking(UA_Connection *connection, void *application,
  70. UA_Connection_processChunk processCallback);
  71. /* When a fatal error occurs the Server shall send an Error Message to the
  72. * Client and close the socket. When a Client encounters one of these errors, it
  73. * shall also close the socket but does not send an Error Message. After the
  74. * socket is closed a Client shall try to reconnect automatically using the
  75. * mechanisms described in [...]. */
  76. void
  77. UA_Connection_sendError(UA_Connection *connection,
  78. UA_TcpErrorMessage *error);
  79. void UA_Connection_detachSecureChannel(UA_Connection *connection);
  80. void UA_Connection_attachSecureChannel(UA_Connection *connection,
  81. UA_SecureChannel *channel);
  82. #ifdef __cplusplus
  83. } // extern "C"
  84. #endif
  85. #endif /* UA_CONNECTION_INTERNAL_H_ */