open62541 1.3.12
Open source implementation of OPC UA
Loading...
Searching...
No Matches
network.h
Go to the documentation of this file.
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 2017 (c) Fraunhofer IOSB (Author: Julius Pfrommer)
6 * Copyright 2017 (c) Stefan Profanter, fortiss GmbH
7 */
8
9#ifndef UA_PLUGIN_NETWORK_H_
10#define UA_PLUGIN_NETWORK_H_
11
12#include <open62541/util.h>
14
16
17/** Forward declarations */
18struct UA_Connection;
20
21struct UA_SecureChannel;
23
26
27
28
38
39typedef enum {
40 UA_CONNECTIONSTATE_CLOSED, /* The socket has been closed and the connection
41 * will be deleted */
42 UA_CONNECTIONSTATE_OPENING, /* The socket is open, but the HEL/ACK handshake
43 * is not done */
44 UA_CONNECTIONSTATE_ESTABLISHED /* The socket is open and the connection
45 * configured */
47
50 UA_SecureChannel *channel; /* The securechannel that is attached to
51 * this connection */
52 UA_SOCKET sockfd; /* Most connectivity solutions run on
53 * sockets. Having the socket id here
54 * simplifies the design. */
55 UA_DateTime openingDate; /* The date the connection was created */
56 void *handle; /* A pointer to internal data */
57
58 /* Get a buffer for sending */
59 UA_StatusCode (*getSendBuffer)(UA_Connection *connection, size_t length,
60 UA_ByteString *buf);
61
62 /* Release the send buffer manually */
63 void (*releaseSendBuffer)(UA_Connection *connection, UA_ByteString *buf);
64
65 /* Sends a message over the connection. The message buffer is always freed,
66 * even if sending fails.
67 *
68 * @param connection The connection
69 * @param buf The message buffer
70 * @return Returns an error code or UA_STATUSCODE_GOOD. */
72
73 /* Receive a message from the remote connection
74 *
75 * @param connection The connection
76
77 * @param response The response string. If this is empty, it will be
78 * allocated by the connection and needs to be freed with
79 * connection->releaseBuffer. If the response string is non-empty, it
80 * will be used as the receive buffer. If bytes are received, the
81 * length of the buffer is adjusted to match the length of the
82 * received bytes.
83 * @param timeout Timeout of the recv operation in milliseconds
84 * @return Returns UA_STATUSCODE_BADCOMMUNICATIONERROR if the recv operation
85 * can be repeated, UA_STATUSCODE_GOOD if it succeeded and
86 * UA_STATUSCODE_BADCONNECTIONCLOSED if the connection was
87 * closed. */
88 UA_StatusCode (*recv)(UA_Connection *connection, UA_ByteString *response,
89 UA_UInt32 timeout);
90
91 /* Release the buffer of a received message */
92 void (*releaseRecvBuffer)(UA_Connection *connection, UA_ByteString *buf);
93
94 /* Close the connection. The network layer closes the socket. This is picked
95 * up during the next 'listen' and the connection is freed in the network
96 * layer. */
97 void (*close)(UA_Connection *connection);
98
99 /* To be called only from within the server (and not the network layer).
100 * Frees up the connection's memory. */
101 void (*free)(UA_Connection *connection);
102};
103
104
105
106/** Process a binary message (TCP packet). The message can contain partial
107 * chunks. (TCP is a streaming protocol and packets may be split/merge during
108 * transport.) After processing, the message is freed with
109 * connection->releaseRecvBuffer. */
110void
113
114/** The server internally cleans up the connection and then calls
115 * connection->free. */
116void
118
120 void *handle; /* Internal data */
121
122 /* Points to external memory, i.e. handled by server or client */
124
126
128
129 /* Start listening on the network layer.
130 *
131 * @param nl The network layer
132 * @return Returns UA_STATUSCODE_GOOD or an error code. */
134 const UA_String *customHostname);
135
136 /* Listen for new and closed connections and arriving packets. Calls
137 * UA_Server_processBinaryMessage for the arriving packets. Closed
138 * connections are picked up here and forwarded to
139 * UA_Server_removeConnection where they are cleaned up and freed.
140 *
141 * @param nl The network layer
142 * @param server The server for processing the incoming packets and for
143 * closing connections.
144 * @param timeout The timeout during which an event must arrive in
145 * milliseconds
146 * @return A statuscode for the status of the network layer. */
148 UA_UInt16 timeout);
149
150 /* Close the network socket and all open connections. Afterwards, the
151 * network layer can be safely deleted.
152 *
153 * @param nl The network layer
154 * @param server The server that processes the incoming packets and for
155 * closing connections before deleting them.
156 * @return A statuscode for the status of the closing operation. */
157 void (*stop)(UA_ServerNetworkLayer *nl, UA_Server *server);
158
159 /* Deletes the network layer context. Call only after stopping. */
161};
162
163
164
165/** @param config the connection config for this client
166 * @param endpointUrl to where to connect
167 * @param timeout in ms until the connection try times out if remote not reachable
168 * @param logger the logger to use */
171 UA_UInt32 timeout, const UA_Logger *logger);
172
174
175#endif /* UA_PLUGIN_NETWORK_H_ */
#define _UA_BEGIN_DECLS
#undef UA_DEBUG_DUMP_PKGS
Definition config.h:89
#define _UA_END_DECLS
Definition config.h:96
UA_Connection(* UA_ConnectClientConnection)(UA_ConnectionConfig config, UA_String endpointUrl, UA_UInt32 timeout, const UA_Logger *logger)
Definition network.h:170
struct UA_Connection UA_Connection
Definition network.h:19
UA_ConnectionState
Definition network.h:39
@ UA_CONNECTIONSTATE_ESTABLISHED
Definition network.h:44
@ UA_CONNECTIONSTATE_CLOSED
Definition network.h:40
@ UA_CONNECTIONSTATE_OPENING
Definition network.h:42
void UA_Server_removeConnection(UA_Server *server, UA_Connection *connection)
The server internally cleans up the connection and then calls connection->free.
void UA_Server_processBinaryMessage(UA_Server *server, UA_Connection *connection, UA_ByteString *message)
Process a binary message (TCP packet).
UA_UInt32 sendBufferSize
Definition network.h:32
UA_UInt32 remoteMaxChunkCount
Definition network.h:36
UA_UInt32 localMaxMessageSize
Definition network.h:33
UA_UInt32 localMaxChunkCount
Definition network.h:35
UA_UInt32 protocolVersion
Definition network.h:30
UA_UInt32 recvBufferSize
Definition network.h:31
UA_UInt32 remoteMaxMessageSize
Definition network.h:34
UA_SecureChannel * channel
Definition network.h:50
UA_StatusCode(* send)(UA_Connection *connection, UA_ByteString *buf)
Definition network.h:71
UA_SOCKET sockfd
Definition network.h:52
UA_DateTime openingDate
Definition network.h:55
UA_ConnectionState state
Definition network.h:49
void(* close)(UA_Connection *connection)
Definition network.h:97
void(* releaseRecvBuffer)(UA_Connection *connection, UA_ByteString *buf)
Definition network.h:92
UA_StatusCode(* getSendBuffer)(UA_Connection *connection, size_t length, UA_ByteString *buf)
Definition network.h:59
void * handle
Definition network.h:56
void(* free)(UA_Connection *connection)
Definition network.h:101
UA_StatusCode(* recv)(UA_Connection *connection, UA_ByteString *response, UA_UInt32 timeout)
Definition network.h:88
void(* releaseSendBuffer)(UA_Connection *connection, UA_ByteString *buf)
Definition network.h:63
void(* clear)(UA_ServerNetworkLayer *nl)
Definition network.h:160
UA_String discoveryUrl
Definition network.h:125
UA_StatusCode(* listen)(UA_ServerNetworkLayer *nl, UA_Server *server, UA_UInt16 timeout)
Definition network.h:147
UA_ConnectionConfig localConnectionConfig
Definition network.h:127
void(* stop)(UA_ServerNetworkLayer *nl, UA_Server *server)
Definition network.h:157
UA_StatusCode(* start)(UA_ServerNetworkLayer *nl, const UA_Logger *logger, const UA_String *customHostname)
Definition network.h:133
UA_NetworkStatistics * statistics
Definition network.h:123
uint16_t UA_UInt16
Definition types.h:46
uint32_t UA_UInt32
Definition types.h:56
int64_t UA_DateTime
Definition types.h:144
uint32_t UA_StatusCode
Definition types.h:77
#define UA_SOCKET
Definition ua_lwip.h:31