High Performance OPC UA Server SDK
1.1.0.158
|
Modules | |
Operation Control Flags | |
Bitmask values used by ua_socket_op. | |
Operation Initialization | |
Data Structures | |
struct | ua_socket_op |
Structure representing an asynchronous IO operation. More... | |
struct | ua_socket |
Internal structure of an async socket. More... | |
struct | ua_net_base |
Network base object. More... | |
struct | ua_ipaddress |
Storage for an IP address. More... | |
struct | ua_net_addr |
Structure for storing a network/IP address. More... | |
Macros | |
#define | UA_NET_CCV |
calling convention | |
#define | UA_NET_API |
API definition. | |
#define | UA_NET_E_GOOD 0 |
Result codes. More... | |
#define | UA_NET_E_ASYNC 1 |
Operation will complete asynchronously. More... | |
#define | UA_NET_E_PARTIAL 2 |
Operation completed partially (completion pending)(support optional). More... | |
#define | UA_NET_E_BAD -1 |
Operation or call failed (unspecific or unexpected reason). More... | |
#define | UA_NET_E_BADDISCONNECT -2 |
Connection is closed. More... | |
#define | UA_NET_E_BADSHUTDOWN -3 |
Peer shutdown connection in required direction. More... | |
#define | UA_NET_E_BADINVALIDARGUMENT -4 |
Function called with invalid arguments. More... | |
#define | UA_NET_E_BADNOMEM -5 |
Operation failed because of not enough memory. More... | |
#define | UA_NET_E_BADNOTIMPL -6 |
Function not implemented. More... | |
#define | UA_NET_E_BADHOSTUNKNOWN -7 |
Connect failed because host is not known or unreacheable. More... | |
#define | UA_NET_E_BADSYSCALL -8 |
Underlying system call failed. More... | |
#define | UA_NET_E_BADOPCANCELLED -9 |
Operation has been cancelled before completion. More... | |
#define | UA_NET_E_BADOPTIMEOUT -10 |
Operation timed out. More... | |
#define | UA_NET_E_BADIOPENDING -11 |
Operation cannot be started because a prior operation is still pending. More... | |
#define | UA_NET_E_BADINVALIDSTATE -12 |
An object is in an invalid state for the operation. More... | |
#define | UA_NET_E_BADWOULDBLOCK -13 |
Operation would cause the thread to block. More... | |
#define | UA_NET_E_BADNOTSUPPORTED -14 |
Operation is not supported. More... | |
#define | UA_NET_E_BADTOOSMALL -15 |
A given destination was too small. More... | |
#define | UA_NET_E_BADHOSTUNREACHABLE -16 |
Connect to given address failed. More... | |
#define | UA_NET_E_BADSOCKETCLOSED -17 |
Operation interrupted because socket has been closed. More... | |
#define | UA_NET_E_BADUNEXPECTED -18 |
Unexpected error. More... | |
#define | UA_NET_E_BADNOTFOUND -19 |
Requested element not found. More... | |
#define | UA_NET_EVENT_NULL 0x00000000 |
Placeholder event type. More... | |
#define | UA_NET_EVENT_CLOSE_COMPLETE 0x00000001 |
These events should be handled in ua_socket_cb. More... | |
#define | UA_NET_EVENT_TIMEOUT 0x00000002 |
No communication during the configured timespan. More... | |
Typedefs | |
typedef void( | ua_net_resolve_callback )(int iResult, int iNoOfAddresses, struct ua_net_addr *pAddresses, void *pvCallbackData) |
Receive addresses after completion of asynchronous address resolution. More... | |
typedef int( | ua_socket_cb )(struct ua_socket *pSocket, unsigned int iEventType, int iResult, void *pvCallbackData) |
Signature of a socket callback. More... | |
typedef int( | ua_socket_op_cb )(struct ua_socket *pSocket, struct ua_socket_op *pOperation, int iResult) |
Signature of an operation callback. More... | |
Enumerations | |
enum | ua_net_af { ua_net_af_none = 0, ua_net_af_ipv4 = 1, ua_net_af_ipv6 = 2, ua_net_af_any = 3 } |
Identifiers for supported network address families. More... | |
enum | ua_socket_type { ua_socket_type_none = 0, ua_socket_type_stream, ua_socket_type_dgram } |
Socket types for ua_socket_init call. More... | |
enum | ua_net_state { UA_NET_STATE_NONE = 0, UA_NET_STATE_LISTEN = 1, UA_NET_STATE_CONNECTING = 2, UA_NET_STATE_ACCEPTING = 3, UA_NET_STATE_SHUTDOWN_SEND = 4, UA_NET_STATE_SHUTDOWN_READ = 5, UA_NET_STATE_ESTABLISHED = 6, UA_NET_STATE_CLOSING = 7, UA_NET_STATE_ABORTING = 8, UA_NET_STATE_UDP } |
Internal socket state. More... | |
Functions | |
UA_NET_API int UA_NET_CCV | ua_net_resolve (struct ua_net_base *pNetBase, const char *sHost, int *piNoOfAddresses, struct ua_net_addr *pAddresses, ua_net_resolve_callback *pfCallback, void *pvCallbackData) |
Resolve the hostname and store the results in the given array. More... | |
UA_NET_API int | ua_ipaddress_set (struct ua_ipaddress *ip, const unsigned char *addr, unsigned char len) |
Assigns the given IP address in ip . More... | |
UA_NET_API int UA_NET_CCV | ua_net_formataddr (struct ua_net_addr *pAddr, size_t iBufLen, char *pBuf) |
Convert the address in binary form into its string representation. More... | |
UA_NET_API int UA_NET_CCV | ua_net_getaddr (const char *sIP, struct ua_net_addr *pAddr) |
Converts numeric address into binary format and determins address family. More... | |
UA_NET_API int UA_NET_CCV | ua_net_makeanyaddr (struct ua_net_addr *pAddr) |
Set given address to ANY_IP for use in bind. More... | |
UA_NET_API int UA_NET_CCV | ua_net_init (void) |
Initialize network library. More... | |
UA_NET_API int UA_NET_CCV | ua_net_clear (void) |
Cleanup network library. More... | |
UA_NET_API int UA_NET_CCV | ua_socket_init (struct ua_net_base *pNetworkBase, struct ua_socket *pSocket, enum ua_net_af AddressFamily, enum ua_socket_type SocketType, ua_socket_cb *pfCallback, void *pvCallbackData) |
Create an usable struct ua_socket within the given memory and assigns to base object. More... | |
UA_NET_API int UA_NET_CCV | ua_socket_initset (struct ua_net_base *pNetworkBase, struct ua_socket *pSocket, UA_NET_P_SOCKET hSocket, ua_socket_cb *pfCallback, void *pvCallbackData) |
Create an usable struct ua_socket within the given memory and assigns to base object. More... | |
UA_NET_API int UA_NET_CCV | ua_socket_set_reuse_address (struct ua_socket *pSocket) |
Set SO_REUSEADDR as socket option for the given socket. More... | |
UA_NET_API int UA_NET_CCV | ua_socket_get_peer_addr (struct ua_socket *pSocket, struct ua_net_addr *pAddress) |
Get information about the peer address through a connected socket. More... | |
UA_NET_API void UA_NET_CCV | ua_socket_set_timeout (struct ua_socket *pSocket, int iTimeOutMS) |
Set timeout value of a socket (<= 0 to deactivate). More... | |
UA_NET_API unsigned int UA_NET_CCV | ua_net_get_last_error (struct ua_net_base *pNetworkBase) |
Retrieve last socket error. More... | |
UA_NET_API int UA_NET_CCV | ua_socket_bind (struct ua_socket *pSocket, struct ua_net_addr *pAddress) |
Bind socket to given address and port. More... | |
UA_NET_API int UA_NET_CCV | ua_socket_listen (struct ua_socket *pSocket) |
Put socket into listen mode. More... | |
UA_NET_API int UA_NET_CCV | ua_socket_accept (struct ua_socket *pListenSocket, struct ua_socket *pAcceptSocket, struct ua_socket_op *pAcceptOperation) |
Start asynchronous accept and notify completion through operation object. More... | |
UA_NET_API int UA_NET_CCV | ua_socket_connect (struct ua_socket *pSocket, struct ua_net_addr *pServerAddress, struct ua_net_addr *pLocalAddress, struct ua_socket_op *pConnectOperation) |
Start asynchronous connect and notify completion through operation object. More... | |
UA_NET_API int UA_NET_CCV | ua_socket_write (struct ua_socket *pSocket, struct ua_socket_op *pSendOperation) |
Start asynchronous write operation and notify completion through operation object. More... | |
UA_NET_API int UA_NET_CCV | ua_socket_read (struct ua_socket *pSocket, struct ua_socket_op *pReadOperation) |
Start asynchronous read operation and notify completion through operation object. More... | |
UA_NET_API int UA_NET_CCV | ua_socket_sendto (struct ua_socket *pSocket, struct ua_socket_op *pOperation, const struct ua_net_addr *pDestAddr) |
Starts an asynchronous sendto operation and notify completion through operation object. More... | |
UA_NET_API int UA_NET_CCV | ua_socket_recvfrom (struct ua_socket *pSocket, struct ua_socket_op *pOperation) |
Starts an asynchronous recvfrom operation and notify completion through operation object. More... | |
UA_NET_API void UA_NET_CCV | ua_socket_shutdown (struct ua_socket *pSocket) |
Shutdown connection in send direction. More... | |
UA_NET_API int UA_NET_CCV | ua_socket_close (struct ua_socket *pSocket) |
Close socket, remove from base and clear memory. More... | |
UA_NET_API unsigned int UA_NET_CCV | ua_net_base_size (unsigned int num_sockets) |
Calculate the size of the data to be passed to ua_net_base_init. More... | |
UA_NET_API int UA_NET_CCV | ua_net_base_init (struct ua_net_base *pNetworkBase, void *data, unsigned int num_sockets) |
Initialize base object. More... | |
UA_NET_API void *UA_NET_CCV | ua_net_base_clear (struct ua_net_base *pNetworkBase) |
Clear base object. More... | |
UA_NET_API int UA_NET_CCV | ua_net_do_events (struct ua_net_base *pNetworkBase, int iTimeOutMSec) |
Process events of sockets organized by a network base object. More... | |
#define UA_NET_E_ASYNC 1 |
Operation will complete asynchronously.
#define UA_NET_E_BAD -1 |
Operation or call failed (unspecific or unexpected reason).
#define UA_NET_E_BADDISCONNECT -2 |
Connection is closed.
#define UA_NET_E_BADHOSTUNKNOWN -7 |
Connect failed because host is not known or unreacheable.
#define UA_NET_E_BADHOSTUNREACHABLE -16 |
Connect to given address failed.
#define UA_NET_E_BADINVALIDARGUMENT -4 |
Function called with invalid arguments.
#define UA_NET_E_BADINVALIDSTATE -12 |
An object is in an invalid state for the operation.
#define UA_NET_E_BADIOPENDING -11 |
Operation cannot be started because a prior operation is still pending.
#define UA_NET_E_BADNOMEM -5 |
Operation failed because of not enough memory.
#define UA_NET_E_BADNOTFOUND -19 |
Requested element not found.
#define UA_NET_E_BADNOTIMPL -6 |
Function not implemented.
#define UA_NET_E_BADNOTSUPPORTED -14 |
Operation is not supported.
#define UA_NET_E_BADOPCANCELLED -9 |
Operation has been cancelled before completion.
#define UA_NET_E_BADOPTIMEOUT -10 |
Operation timed out.
#define UA_NET_E_BADSHUTDOWN -3 |
Peer shutdown connection in required direction.
#define UA_NET_E_BADSOCKETCLOSED -17 |
Operation interrupted because socket has been closed.
#define UA_NET_E_BADSYSCALL -8 |
Underlying system call failed.
#define UA_NET_E_BADTOOSMALL -15 |
A given destination was too small.
#define UA_NET_E_BADUNEXPECTED -18 |
Unexpected error.
#define UA_NET_E_BADWOULDBLOCK -13 |
Operation would cause the thread to block.
#define UA_NET_E_GOOD 0 |
Result codes.
Operation completed successfully.
#define UA_NET_E_PARTIAL 2 |
Operation completed partially (completion pending)(support optional).
#define UA_NET_EVENT_CLOSE_COMPLETE 0x00000001 |
These events should be handled in ua_socket_cb.
The connection was closed locally.
#define UA_NET_EVENT_NULL 0x00000000 |
Placeholder event type.
#define UA_NET_EVENT_TIMEOUT 0x00000002 |
No communication during the configured timespan.
typedef void( ua_net_resolve_callback)(int iResult, int iNoOfAddresses, struct ua_net_addr *pAddresses, void *pvCallbackData) |
Receive addresses after completion of asynchronous address resolution.
Only called if ua_net_resolve returned UA_NET_E_ASYNC.
iResult | Result of the operation. |
iNoOfAddresses | Number of used slots in address array. |
pAddresses | Filled array passed into resolve function. |
pvCallbackData | User data passed into resolve function. |
typedef int( ua_socket_cb)(struct ua_socket *pSocket, unsigned int iEventType, int iResult, void *pvCallbackData) |
Signature of a socket callback.
pSocket | The socket object on which the event occured. |
iEventType | UA_NET_EVENT_* |
iResult | UA_NET_E_* result assigned to the event. |
pvCallbackData | The user data specified at socket initialization. |
typedef int( ua_socket_op_cb)(struct ua_socket *pSocket, struct ua_socket_op *pOperation, int iResult) |
Signature of an operation callback.
pSocket | The socket object to which the operation was assigned to. |
pOperation | The structure defining the completed operation. |
iResult | UA_NET_E_* describing wether the operation succeeded or failed. |
enum ua_net_af |
Identifiers for supported network address families.
enum ua_net_state |
Internal socket state.
enum ua_socket_type |
UA_NET_API int ua_ipaddress_set | ( | struct ua_ipaddress * | ip, |
const unsigned char * | addr, | ||
unsigned char | len | ||
) |
Assigns the given IP address in ip
.
ip | destination to assign to |
addr | pointer to byte array which contains the IP address (e.g. from sockaddr_in.sin_addr or sockaddr_in6.sin6_addr. |
len | length in bytes. 4 for IPv4, 16 for IPv6. |
UA_NET_API void* UA_NET_CCV ua_net_base_clear | ( | struct ua_net_base * | pNetworkBase | ) |
Clear base object.
pNetworkBase | The network base object to be cleared. |
UA_NET_API int UA_NET_CCV ua_net_base_init | ( | struct ua_net_base * | pNetworkBase, |
void * | data, | ||
unsigned int | num_sockets | ||
) |
Initialize base object.
pNetworkBase | The network base object to be initialized. |
data | Preallocated data of size calculated by ua_net_base_size. |
num_sockets | Number of sockets for the network base, must be the same as when calculating the data size. |
UA_NET_API unsigned int UA_NET_CCV ua_net_base_size | ( | unsigned int | num_sockets | ) |
Calculate the size of the data to be passed to ua_net_base_init.
num_sockets | Number of sockets for the base to initialize. |
UA_NET_API int UA_NET_CCV ua_net_clear | ( | void | ) |
Cleanup network library.
Must be the last call to this API.
UA_NET_API int UA_NET_CCV ua_net_do_events | ( | struct ua_net_base * | pNetworkBase, |
int | iTimeOutMSec | ||
) |
Process events of sockets organized by a network base object.
pNetworkBase | The network base object. |
iTimeOutMSec | Maximum wait time. |
UA_NET_API int UA_NET_CCV ua_net_formataddr | ( | struct ua_net_addr * | a_pAddr, |
size_t | a_BufLen, | ||
char * | a_pBuf | ||
) |
Convert the address in binary form into its string representation.
The string is stored in the buffer which must be large enough to store the address plus the zero terminator.(ie. IPv4 address has 15 characters). The resulting string will be zero terminated. If the buffer is too small the resulting string may be truncated.
a_pAddr | Address storage with the address to be converted. |
a_BufLen | Size of the destination buffer. |
a_pBuf | Destination buffer. |
UA_NET_API unsigned int UA_NET_CCV ua_net_get_last_error | ( | struct ua_net_base * | pNetworkBase | ) |
Retrieve last socket error.
pNetworkBase | The network base object. |
UA_NET_API int UA_NET_CCV ua_net_getaddr | ( | const char * | a_sIP, |
struct ua_net_addr * | a_pAddr | ||
) |
Converts numeric address into binary format and determins address family.
Uses getaddrinfo when IPv6 support is enabled to get automatic format check. Without IPv6 support inet_addr is used for backward compatibility. This function is deprecated but the newer alternative inet_pton() is problably only available on platforms with IPv6 support anyway. This function is not meant to resolve hostnames! Use ua_net_resolve() instead.
a_sAddr | The IP address in string form. |
a_pAddr | Target for storing the address information. |
UA_NET_API int UA_NET_CCV ua_net_init | ( | void | ) |
Initialize network library.
Must be called first.
UA_NET_API int UA_NET_CCV ua_net_makeanyaddr | ( | struct ua_net_addr * | a_pAddr | ) |
Set given address to ANY_IP for use in bind.
a_pAddr | Address storage with the address to be set to ANY_IP. |
UA_NET_API int UA_NET_CCV ua_net_resolve | ( | struct ua_net_base * | a_pNetBase, |
const char * | a_sHost, | ||
int * | a_piNoOfAddrs, | ||
struct ua_net_addr * | a_pAddrs, | ||
ua_net_resolve_callback * | a_pfCallback, | ||
void * | a_pvCallbackData | ||
) |
Resolve the hostname and store the results in the given array.
Depending on the implementation the process may complete immediatly or asynchronously by invoking the given callback. The function only returns as many addresses as are requested in a_piNoOfAddrs. There might be more available. The function returns UA_NET_E_GOOD if the operation completed synchronously. The callback won't be invoked in this case. UA_NET_E_ASYNC is returned if the result will be reported in the callback function. If no callback function is given in this case the function returns UA_NET_E_BADWOULDBLOCK. If the result is reported asynchronously the destination array has be be valid until the callback function has been called.
a_pNetBase | Network base which sockets are regularly polled for events. |
a_sHost | String containing the hostname to be resolved. |
a_piNoOfAddrs | Size of the a_pAddrs array. Contains number of used slots on sync completion. |
a_pAddrs | Destination for storing the resolved addresses. |
a_pfCallback | Function for reporting async completion. |
a_pvCallbackData | User data passed to callback function. |
UA_NET_API int UA_NET_CCV ua_socket_accept | ( | struct ua_socket * | pListenSocket, |
struct ua_socket * | pAcceptSocket, | ||
struct ua_socket_op * | pAcceptOperation | ||
) |
Start asynchronous accept and notify completion through operation object.
pListenSocket | Socket which has been put into listening mode. |
pAcceptSocket | Socket which will represent the accepted connection. Handle must be empty (use ua_socket_initset with UA_NET_P_SOCKET_INVALID). |
pAcceptOperation | Operation object which will be notified when a client is accepted. |
UA_NET_API int UA_NET_CCV ua_socket_bind | ( | struct ua_socket * | pSocket, |
struct ua_net_addr * | pAddress | ||
) |
Bind socket to given address and port.
pSocket | The socket object. |
pAddress | The address information for binding the socket. |
UA_NET_API int UA_NET_CCV ua_socket_close | ( | struct ua_socket * | pSocket | ) |
Close socket, remove from base and clear memory.
pSocket | The socket object. |
UA_NET_API int UA_NET_CCV ua_socket_connect | ( | struct ua_socket * | pSocket, |
struct ua_net_addr * | pServerAddress, | ||
struct ua_net_addr * | pLocalAddress, | ||
struct ua_socket_op * | pConnectOperation | ||
) |
Start asynchronous connect and notify completion through operation object.
pSocket | The socket object. |
pServerAddress | Address information of the host. |
uPort | Port number at the host. |
pLocalAddress | Bind the client socket to this local address. |
pConnectOperation | Initialized async operation structure. |
UA_NET_API int UA_NET_CCV ua_socket_get_peer_addr | ( | struct ua_socket * | pSocket, |
struct ua_net_addr * | pAddress | ||
) |
Get information about the peer address through a connected socket.
pSocket | The socket object. |
pAddress | The address information of the peer. |
UA_NET_API int UA_NET_CCV ua_socket_init | ( | struct ua_net_base * | pNetworkBase, |
struct ua_socket * | pSocket, | ||
enum ua_net_af | AddressFamily, | ||
enum ua_socket_type | SocketType, | ||
ua_socket_cb * | pfCallback, | ||
void * | pvCallbackData | ||
) |
Create an usable struct ua_socket within the given memory and assigns to base object.
Creates new socket handle based on address family and type.
pNetworkBase | The network base object |
pSocket | The socket object. |
AddressFamily | The address family of the socket to be created. |
SocketType | Type of the socket to be created. |
pfCallback | Function which will be called if non-operation events occur on the socket. |
pvCallbackData | User data passed back to the callback function. |
UA_NET_API int UA_NET_CCV ua_socket_initset | ( | struct ua_net_base * | pNetworkBase, |
struct ua_socket * | pSocket, | ||
UA_NET_P_SOCKET | hSocket, | ||
ua_socket_cb * | pfCallback, | ||
void * | pvCallbackData | ||
) |
Create an usable struct ua_socket within the given memory and assigns to base object.
Uses given system socket handle instead of creating a new one. Socket is set to non-blocking.
pNetworkBase | The network base object |
pSocket | The socket object. |
hSocket | A platform dependent socket or file descriptor which will be assigned to the socket. |
pfCallback | Function which will be called if non-operation events occur on the socket. |
pvCallbackData | User data passed back to the callback function. |
UA_NET_API int UA_NET_CCV ua_socket_listen | ( | struct ua_socket * | pSocket | ) |
Put socket into listen mode.
pSocket | The socket object. |
pAddress | The address information for binding the socket. |
UA_NET_API int UA_NET_CCV ua_socket_read | ( | struct ua_socket * | pSocket, |
struct ua_socket_op * | pReadOperation | ||
) |
Start asynchronous read operation and notify completion through operation object.
pSocket | The socket object. |
pReadOperation | Initialized operation structure. |
UA_NET_API int UA_NET_CCV ua_socket_recvfrom | ( | struct ua_socket * | pSocket, |
struct ua_socket_op * | pOperation | ||
) |
Starts an asynchronous recvfrom operation and notify completion through operation object.
Note that the operation object contains the sender address once the operation is completed.
pSocket | The socket object. |
pOperation | Initialized operation structure. |
UA_NET_API int UA_NET_CCV ua_socket_sendto | ( | struct ua_socket * | pSocket, |
struct ua_socket_op * | pOperation, | ||
const struct ua_net_addr * | pDestAddr | ||
) |
Starts an asynchronous sendto operation and notify completion through operation object.
pSocket | The socket object. |
pOperation | Initialized operation structure. |
pDestAddr | Destination address for this UDP packet. |
UA_NET_API int UA_NET_CCV ua_socket_set_reuse_address | ( | struct ua_socket * | pSocket | ) |
Set SO_REUSEADDR as socket option for the given socket.
pSocket | The socket object. |
UA_NET_API void UA_NET_CCV ua_socket_set_timeout | ( | struct ua_socket * | pSocket, |
int | iTimeOutMS | ||
) |
Set timeout value of a socket (<= 0 to deactivate).
pSocket | |
iTimeOutMS |
UA_NET_API void UA_NET_CCV ua_socket_shutdown | ( | struct ua_socket * | pSocket | ) |
Shutdown connection in send direction.
pSocket | The socket object. |
UA_NET_API int UA_NET_CCV ua_socket_write | ( | struct ua_socket * | pSocket, |
struct ua_socket_op * | pSendOperation | ||
) |
Start asynchronous write operation and notify completion through operation object.
pSocket | The socket object. |
pSendOperation | Initialized operation structure. |