ua_connection_internal.h 3.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  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. /* Try to receive at least one complete chunk on the connection. This blocks the
  43. * current thread up to the given timeout.
  44. *
  45. * @param connection The connection
  46. * @param application The client or server application
  47. * @param processCallback The function pointer for processing each chunk
  48. * @param timeout The timeout (in milliseconds) the method will block at most.
  49. * @return Returns UA_STATUSCODE_GOOD or an error code. When an timeout occurs,
  50. * UA_STATUSCODE_GOODNONCRITICALTIMEOUT is returned. */
  51. UA_StatusCode
  52. UA_Connection_receiveChunksBlocking(UA_Connection *connection, void *application,
  53. UA_Connection_processChunk processCallback,
  54. UA_UInt32 timeout);
  55. /* When a fatal error occurs the Server shall send an Error Message to the
  56. * Client and close the socket. When a Client encounters one of these errors, it
  57. * shall also close the socket but does not send an Error Message. After the
  58. * socket is closed a Client shall try to reconnect automatically using the
  59. * mechanisms described in [...]. */
  60. void
  61. UA_Connection_sendError(UA_Connection *connection,
  62. UA_TcpErrorMessage *error);
  63. void UA_Connection_detachSecureChannel(UA_Connection *connection);
  64. void UA_Connection_attachSecureChannel(UA_Connection *connection,
  65. UA_SecureChannel *channel);
  66. #ifdef __cplusplus
  67. } // extern "C"
  68. #endif
  69. #endif /* UA_CONNECTION_INTERNAL_H_ */