S2OPC OPCUA Toolkit
|
A platform independent API to use sockets. More...
Go to the source code of this file.
Macros | |
#define | SOPC_INVALID_SOCKET NULL |
Typedefs | |
typedef struct SOPC_Socket_Impl | SOPC_Socket_Impl |
Provides a socket implementation. | |
typedef SOPC_Socket_Impl * | SOPC_Socket |
typedef struct SOPC_Socket_AddressInfo | SOPC_Socket_AddressInfo |
Provides a socket address info implementation. | |
typedef struct SOPC_Socket_Address | SOPC_Socket_Address |
Provides a socket address implementation. | |
typedef struct SOPC_SocketSet | SOPC_SocketSet |
Provides a socket set implementation. | |
Functions | |
SOPC_ReturnStatus | SOPC_Socket_Network_Enable_Keepalive (SOPC_Socket sock, unsigned int firstProbeDelay, unsigned int interval, unsigned int counter) |
Activate the keep alive mechanism. According to RFC1122, this mechanism shall be used with care: deactivated by default, ability to enable or disable it run time for each connection at runtime. | |
SOPC_ReturnStatus | SOPC_Socket_Network_Disable_Keepalive (SOPC_Socket sock) |
Deactivate the keep alive mechanism. | |
bool | SOPC_Socket_Network_Initialize (void) |
Initialize the network communication allowing to use sockets. | |
bool | SOPC_Socket_Network_Clear (void) |
Clear the network communication when sockets not used anymore. | |
SOPC_ReturnStatus | SOPC_Socket_AddrInfo_Get (const char *hostname, const char *port, SOPC_Socket_AddressInfo **addrs) |
Provide a linked list of socket addressing information for establishing TCP connections over IPV4 and IPV6 using the hostname and/or port if provided. | |
SOPC_Socket_AddressInfo * | SOPC_Socket_AddrInfo_IterNext (SOPC_Socket_AddressInfo *addr) |
Given a socket addressing information element of a linked list, provides the next addressing information or NULL if no more are available. | |
uint8_t | SOPC_Socket_AddrInfo_IsIPV6 (const SOPC_Socket_AddressInfo *addr) |
Given a socket addressing information element, returns 0 if address is not IPV6 and not 0 value otherwise. | |
void | SOPC_Socket_AddrInfoDelete (SOPC_Socket_AddressInfo **addrs) |
Deallocate a linked list of socket addressing information. | |
SOPC_Socket_Address * | SOPC_Socket_GetPeerAddress (SOPC_Socket sock) |
Given a socket get the address information associated to the peer connected to the socket. | |
SOPC_Socket_Address * | SOPC_Socket_CopyAddress (SOPC_Socket_AddressInfo *addr) |
Copy the socket address from a socket address information. | |
SOPC_ReturnStatus | SOPC_SocketAddress_GetNameInfo (const SOPC_Socket_Address *addr, char **host, char **service) |
Get address information as C strings from the given socket address. | |
void | SOPC_SocketAddress_Delete (SOPC_Socket_Address **addr) |
Deallocate a socket address obtained with SOPC_Socket_GetPeerAddress or SOPC_Socket_CopyAddress. | |
void | SOPC_Socket_Clear (SOPC_Socket *sock) |
Clear socket state to an invalid socket. | |
SOPC_ReturnStatus | SOPC_Socket_CreateNew (SOPC_Socket_AddressInfo *addr, bool setReuseAddr, bool setNonBlocking, SOPC_Socket *sock) |
Create a new socket using the addressing information provided. | |
SOPC_ReturnStatus | SOPC_Socket_Listen (SOPC_Socket sock, SOPC_Socket_AddressInfo *addr) |
Configure the socket to listen connections using the given addressing information Connection on a listening socket is detected when receiving a read event on the socket. | |
SOPC_ReturnStatus | SOPC_Socket_Accept (SOPC_Socket listeningSock, bool setNonBlocking, SOPC_Socket *acceptedSock) |
Operation to accept a connection on a listening socket Connection on a listening socket is detected when receiving a read event on the socket. | |
SOPC_ReturnStatus | SOPC_Socket_Connect (SOPC_Socket sock, SOPC_Socket_AddressInfo *addr) |
Operation to establish a connection using the given socket and addressing information Connection establishment result must be detected when receiving a read event on the socket and then by calling the SOPC_Socket_CheckAckConnect operation. | |
SOPC_ReturnStatus | SOPC_Socket_ConnectToLocal (SOPC_Socket from, SOPC_Socket to) |
Operation to establish a connection using the given socket to the given local socket. Both sockets shall have been created with same addressing information protocol. The address to connected to is extracted from the target socket. | |
SOPC_ReturnStatus | SOPC_Socket_CheckAckConnect (SOPC_Socket sock) |
Operation to check connection establishment result on a connecting socket After using SOPC_Socket_Connect on a socket and receiving a write event on the socket this operation returns the failure or success of the connection. | |
SOPC_SocketSet * | SOPC_SocketSet_Create (void) |
Create a socket set. | |
void | SOPC_SocketSet_Delete (SOPC_SocketSet **set) |
Delete the pointed socket set and set the pointer to NULL. | |
void | SOPC_SocketSet_Add (SOPC_Socket sock, SOPC_SocketSet *sockSet) |
Add a socket to the given socket set. | |
bool | SOPC_SocketSet_IsPresent (SOPC_Socket sock, SOPC_SocketSet *sockSet) |
Returns if a socket is present in the given socket set. | |
void | SOPC_SocketSet_Clear (SOPC_SocketSet *sockSet) |
Clear a socket set. | |
int32_t | SOPC_Socket_WaitSocketEvents (SOPC_SocketSet *readSet, SOPC_SocketSet *writeSet, SOPC_SocketSet *exceptSet, uint32_t waitMs) |
Wait for events (read, write and exception) on the sockets in the given sets for a given duration. If events are received on sockets or waiting reached timeout it returns and the socket sets contain only the sockets on which events occurred. | |
SOPC_ReturnStatus | SOPC_Socket_Write (SOPC_Socket sock, const uint8_t *data, uint32_t count, uint32_t *sentBytes) |
Write data through the socket. | |
SOPC_ReturnStatus | SOPC_Socket_Read (SOPC_Socket sock, uint8_t *data, uint32_t dataSize, uint32_t *readCount) |
Read data through the socket. | |
SOPC_ReturnStatus | SOPC_Socket_BytesToRead (SOPC_Socket sock, uint32_t *bytesToRead) |
Retrieve number of bytes available to read on the socket. | |
void | SOPC_Socket_Close (SOPC_Socket *sock) |
Close the socket connection and/or clear the socket. | |
A platform independent API to use sockets.
#define SOPC_INVALID_SOCKET NULL |
typedef struct SOPC_Socket_Impl SOPC_Socket_Impl |
Provides a socket implementation.
typedef SOPC_Socket_Impl* SOPC_Socket |
typedef struct SOPC_Socket_AddressInfo SOPC_Socket_AddressInfo |
Provides a socket address info implementation.
typedef struct SOPC_Socket_Address SOPC_Socket_Address |
Provides a socket address implementation.
typedef struct SOPC_SocketSet SOPC_SocketSet |
Provides a socket set implementation.
SOPC_ReturnStatus SOPC_Socket_Network_Enable_Keepalive | ( | SOPC_Socket | sock, |
unsigned int | firstProbeDelay, | ||
unsigned int | interval, | ||
unsigned int | counter ) |
Activate the keep alive mechanism. According to RFC1122, this mechanism shall be used with care: deactivated by default, ability to enable or disable it run time for each connection at runtime.
sock | The socket to activate keep alive probes |
firstProbeDelay | The time (in seconds) the connection needs to remain idle before TCP starts sendingkeepalive probes |
interval | The time (in seconds) between individual keepalive probes |
counter | The maximum number of keepalive probes TCP should send before dropping the connection |
SOPC_ReturnStatus SOPC_Socket_Network_Disable_Keepalive | ( | SOPC_Socket | sock | ) |
Deactivate the keep alive mechanism.
sock | The socket to activate keep alive probes |
bool SOPC_Socket_Network_Initialize | ( | void | ) |
Initialize the network communication allowing to use sockets.
bool SOPC_Socket_Network_Clear | ( | void | ) |
Clear the network communication when sockets not used anymore.
SOPC_ReturnStatus SOPC_Socket_AddrInfo_Get | ( | const char * | hostname, |
const char * | port, | ||
SOPC_Socket_AddressInfo ** | addrs ) |
Provide a linked list of socket addressing information for establishing TCP connections over IPV4 and IPV6 using the hostname and/or port if provided.
hostname | The hostname of the machine to connect or used to listen (optional for listening) |
port | The port number on which to connect or to listen to (optional for listening if hostname set) |
addrs | The addressing information to establish or listen a TCP connection over IPV4 and IPV6 |
SOPC_Socket_AddressInfo * SOPC_Socket_AddrInfo_IterNext | ( | SOPC_Socket_AddressInfo * | addr | ) |
Given a socket addressing information element of a linked list, provides the next addressing information or NULL if no more are available.
addr | A socket addressing information element |
uint8_t SOPC_Socket_AddrInfo_IsIPV6 | ( | const SOPC_Socket_AddressInfo * | addr | ) |
Given a socket addressing information element, returns 0 if address is not IPV6 and not 0 value otherwise.
addr | A socket addressing information element |
void SOPC_Socket_AddrInfoDelete | ( | SOPC_Socket_AddressInfo ** | addrs | ) |
Deallocate a linked list of socket addressing information.
addrs | (In/Out) A linked list of socket addressing information to deallocate. Pointer set to NULL after operation. |
SOPC_Socket_Address * SOPC_Socket_GetPeerAddress | ( | SOPC_Socket | sock | ) |
Given a socket get the address information associated to the peer connected to the socket.
sock | The socket connected to a peer |
SOPC_Socket_Address * SOPC_Socket_CopyAddress | ( | SOPC_Socket_AddressInfo * | addr | ) |
Copy the socket address from a socket address information.
addr | The socket address information to copy into socket address structure |
addr
or NULL in case of failures. Caller is responsible to free the result using SOPC_SocketAddress_Delete. SOPC_ReturnStatus SOPC_SocketAddress_GetNameInfo | ( | const SOPC_Socket_Address * | addr, |
char ** | host, | ||
char ** | service ) |
Get address information as C strings from the given socket address.
addr | The socket address to use to get information as C string | |
[out] | host | (optional) The host information of the address as C string (i.e. IP). Must be deallocated by caller (if non-NULL) |
[out] | service | (optional) The service information of the address as C string (i.e. port). Must be deallocated by caller (if non-NULL) |
void SOPC_SocketAddress_Delete | ( | SOPC_Socket_Address ** | addr | ) |
Deallocate a socket address obtained with SOPC_Socket_GetPeerAddress or SOPC_Socket_CopyAddress.
addr | (In/Out) An address information to deallocate. Pointer set to NULL after operation. |
void SOPC_Socket_Clear | ( | SOPC_Socket * | sock | ) |
Clear socket state to an invalid socket.
[out] | sock | Value pointed is set to invalid socket value |
SOPC_ReturnStatus SOPC_Socket_CreateNew | ( | SOPC_Socket_AddressInfo * | addr, |
bool | setReuseAddr, | ||
bool | setNonBlocking, | ||
SOPC_Socket * | sock ) |
Create a new socket using the addressing information provided.
addr | The addressing information used to instantiate a TCP/IP socket | |
setReuseAddr | If value is not false (0) the socket is configured to be reused | |
setNonBlocking | If value is not false (0) the socket is configured to be non blocking | |
[out] | sock | Value pointed is set with the newly created socket |
SOPC_ReturnStatus SOPC_Socket_Listen | ( | SOPC_Socket | sock, |
SOPC_Socket_AddressInfo * | addr ) |
Configure the socket to listen connections using the given addressing information Connection on a listening socket is detected when receiving a read event on the socket.
sock | The socket used for binding and listening |
addr | The addressing information used to bind the socket for listening (IP and port) |
SOPC_ReturnStatus SOPC_Socket_Accept | ( | SOPC_Socket | listeningSock, |
bool | setNonBlocking, | ||
SOPC_Socket * | acceptedSock ) |
Operation to accept a connection on a listening socket Connection on a listening socket is detected when receiving a read event on the socket.
listeningSock | The listening socket on which a read event has been received. | |
setNonBlocking | If value is not false (0) the connection socket is configured to be non blocking | |
[out] | acceptedSock | Value pointed is set with the newly created socket for accepted connection |
SOPC_ReturnStatus SOPC_Socket_Connect | ( | SOPC_Socket | sock, |
SOPC_Socket_AddressInfo * | addr ) |
Operation to establish a connection using the given socket and addressing information Connection establishment result must be detected when receiving a read event on the socket and then by calling the SOPC_Socket_CheckAckConnect operation.
addr | The addressing information used to establish connection (IP and port) |
sock | The socket used for establishing the connection |
SOPC_ReturnStatus SOPC_Socket_ConnectToLocal | ( | SOPC_Socket | from, |
SOPC_Socket | to ) |
Operation to establish a connection using the given socket to the given local socket. Both sockets shall have been created with same addressing information protocol. The address to connected to is extracted from the target socket.
from | The socket used for establishing the connection |
to | The socket to connect to |
SOPC_ReturnStatus SOPC_Socket_CheckAckConnect | ( | SOPC_Socket | sock | ) |
Operation to check connection establishment result on a connecting socket After using SOPC_Socket_Connect on a socket and receiving a write event on the socket this operation returns the failure or success of the connection.
sock | The socket on which the first read event has been received after calling SOPC_Socket_Connect operation. |
SOPC_SocketSet * SOPC_SocketSet_Create | ( | void | ) |
Create a socket set.
void SOPC_SocketSet_Delete | ( | SOPC_SocketSet ** | set | ) |
Delete the pointed socket set and set the pointer to NULL.
void SOPC_SocketSet_Add | ( | SOPC_Socket | sock, |
SOPC_SocketSet * | sockSet ) |
Add a socket to the given socket set.
sock | The socket to add to the set (not NULL) |
sockSet | The socket set to use for the operation (not NULL) |
bool SOPC_SocketSet_IsPresent | ( | SOPC_Socket | sock, |
SOPC_SocketSet * | sockSet ) |
Returns if a socket is present in the given socket set.
sock | The socket to search in the set (not NULL) |
sockSet | The socket set to use for the operation (not NULL) |
void SOPC_SocketSet_Clear | ( | SOPC_SocketSet * | sockSet | ) |
Clear a socket set.
sockSet | The socket set to use for the operation (not NULL) |
int32_t SOPC_Socket_WaitSocketEvents | ( | SOPC_SocketSet * | readSet, |
SOPC_SocketSet * | writeSet, | ||
SOPC_SocketSet * | exceptSet, | ||
uint32_t | waitMs ) |
Wait for events (read, write and exception) on the sockets in the given sets for a given duration. If events are received on sockets or waiting reached timeout it returns and the socket sets contain only the sockets on which events occurred.
readSet | (In/Out) The set of sockets on which read events are awaited and as a result the set of sockets on which event occurred |
writeSet | (In/Out) The set of sockets on which write events are awaited and as a result the set of sockets on which event occurred |
exceptSet | (In/Out) The set of sockets on which exception events are awaited and as a result the set of sockets on which event occurred |
waitMs | The maximum duration in milliseconds waiting for events (0 means infinite) |
SOPC_ReturnStatus SOPC_Socket_Write | ( | SOPC_Socket | sock, |
const uint8_t * | data, | ||
uint32_t | count, | ||
uint32_t * | sentBytes ) |
Write data through the socket.
sock | The socket on which data must be written |
data | The data bytes to write on socket |
count | The number of bytes to write |
sentBytes | Pointer to the number of bytes sent on socket after call (only significant when SOPC_STATUS_OK returned) |
SOPC_ReturnStatus SOPC_Socket_Read | ( | SOPC_Socket | sock, |
uint8_t * | data, | ||
uint32_t | dataSize, | ||
uint32_t * | readCount ) |
Read data through the socket.
sock | The socket on which data must be read |
data | The data bytes to be set with read bytes |
dataSize | The number of bytes that can be set (or expected to be read) |
readCount | Pointer to the number of bytes actually written on the socket (only significant when SOPC_STATUS_OK returned) |
SOPC_ReturnStatus SOPC_Socket_BytesToRead | ( | SOPC_Socket | sock, |
uint32_t * | bytesToRead ) |
Retrieve number of bytes available to read on the socket.
sock | The socket on which data might be available to read | |
[out] | bytesToRead | Pointer to the number of bytes available to read on the socket. To be considered only if returned status is SOPC_STATUS_OK |
void SOPC_Socket_Close | ( | SOPC_Socket * | sock | ) |
Close the socket connection and/or clear the socket.
sock | The socket to disconnect and/or clear |