IOT Sockets#
This section provides a reference to IoT Socket API functions.
The IOT socket implementation aims to emulate the standards library to the extent possible for embedded offerings from Silabs. There are substantial limitation/exceptions however, and those are mentioned in the subsequent documentation of IOT sockets.
Modules#
Functions#
Create a communication socket.
Assign a local address to a socket.
Listen for socket connections.
Accept a new connection on a socket.
Connect a socket to a remote host.
Receives data from the socket.
Receives data from the socket.
Send data or check if data can be sent on a connected socket.
Send data or check if data can be sent on a socket.
Retrieve local IP address and port of a socket.
Retrieve remote IP address and port of a socket.
Get socket option.
Set socket option.
Close and release a socket.
Retrieve host IP address from host name.
Function Documentation#
iotSocketCreate#
int32_t iotSocketCreate (int32_t af, int32_t type, int32_t protocol)
Create a communication socket.
[in] | af | Address family. One of the values from Address Family. |
[in] | type | Socket type. One of the values from Socket Type. |
[in] | protocol | Socket protocol. One of the values from Socket Protocol. |
Returns
int32_t. Status information:
Socket identification number (>=0).
IOT_SOCKET_EINVAL = Invalid argument.
IOT_SOCKET_ENOTSUP = Operation not supported.
IOT_SOCKET_ENOMEM = Not enough memory.
IOT_SOCKET_ERROR = Unspecified error.
134
of file third_party/iot_socket/include/iot_socket.h
iotSocketBind#
int32_t iotSocketBind (int32_t socket, const uint8_t * ip, uint32_t ip_len, uint16_t port)
Assign a local address to a socket.
[in] | socket | Socket identification number. |
[in] | ip | Pointer to local IP address. |
[in] | ip_len | Length of 'ip' address in bytes. |
[in] | port | Local port number. |
Returns
int32_t. Status information:
0 = Operation successful.
IOT_SOCKET_ESOCK = Invalid socket.
IOT_SOCKET_EINVAL = Invalid argument (address or socket already bound).
IOT_SOCKET_EADDRINUSE = Address already in use.
IOT_SOCKET_ERROR = Unspecified error.
150
of file third_party/iot_socket/include/iot_socket.h
iotSocketListen#
int32_t iotSocketListen (int32_t socket, int32_t backlog)
Listen for socket connections.
[in] | socket | Socket identification number. |
[in] | backlog | Maximum number of the clients supported. |
Returns
int32_t. Status information:
0 = Operation successful.
IOT_SOCKET_ESOCK = Invalid socket.
IOT_SOCKET_EINVAL = Invalid argument (socket not bound).
IOT_SOCKET_ENOTSUP = Operation not supported.
IOT_SOCKET_EISCONN = Socket is already connected.
IOT_SOCKET_ERROR = Unspecified error.
165
of file third_party/iot_socket/include/iot_socket.h
iotSocketAccept#
int32_t iotSocketAccept (int32_t socket, uint8_t * ip, uint32_t * ip_len, uint16_t * port)
Accept a new connection on a socket.
[in] | socket | Socket identification number. |
[out] | ip | Pointer to buffer where address of connecting socket shall be returned (NULL for none). |
[inout] | ip_len | pointer to length of 'ip' (or NULL if 'ip' is NULL):
|
[out] | port | Pointer to buffer where port of connecting socket shall be returned (NULL for none). |
Returns
int32_t. Status information:
socket identification number of accepted socket (>=0).
IOT_SOCKET_ESOCK = Invalid socket.
IOT_SOCKET_EINVAL = Invalid argument (socket not in listen mode).
IOT_SOCKET_ENOTSUP = Operation not supported (socket type does not support accepting connections).
IOT_SOCKET_ECONNRESET = Connection reset by the peer.
IOT_SOCKET_ECONNABORTED = Connection aborted locally.
IOT_SOCKET_EAGAIN = Operation would block or timed out (may be called again).
IOT_SOCKET_ERROR = Unspecified error.
186
of file third_party/iot_socket/include/iot_socket.h
iotSocketConnect#
int32_t iotSocketConnect (int32_t socket, const uint8_t * ip, uint32_t ip_len, uint16_t port)
Connect a socket to a remote host.
[in] | socket | Socket identification number. |
[in] | ip | Pointer to remote IP address. |
[in] | ip_len | Length of 'ip' address in bytes. |
[in] | port | Remote port number. |
Returns
int32_t. Status information:
0 = Operation successful.
IOT_SOCKET_ESOCK = Invalid socket.
IOT_SOCKET_EINVAL = Invalid argument.
IOT_SOCKET_EALREADY = Connection already in progress.
IOT_SOCKET_EINPROGRESS = Operation in progress.
IOT_SOCKET_EISCONN = Socket is connected.
IOT_SOCKET_ECONNREFUSED = Connection rejected by the peer.
IOT_SOCKET_ECONNABORTED = Connection aborted locally.
IOT_SOCKET_EADDRINUSE = Address already in use.
IOT_SOCKET_ETIMEDOUT = Operation timed out.
IOT_SOCKET_ERROR = Unspecified error.
208
of file third_party/iot_socket/include/iot_socket.h
iotSocketRecv#
int32_t iotSocketRecv (int32_t socket, void * buf, uint32_t len)
Receives data from the socket.
[in] | socket | Socket identification number. |
[out] | buf | Pointer to buffer where data should be stored. |
[in] | len | Length of buffer (in bytes). |
Returns
int32_t. Status information:
Number of bytes received (>=0), if len != 0.
0 = Data is available (len = 0).
IOT_SOCKET_ESOCK = Invalid socket.
IOT_SOCKET_EINVAL = Invalid argument (pointer to buffer or length).
IOT_SOCKET_ENOTCONN = Socket is not connected.
IOT_SOCKET_ECONNRESET = Connection reset by the peer.
IOT_SOCKET_ECONNABORTED = Connection aborted locally.
IOT_SOCKET_EAGAIN = Operation would block or timed out (may be called again).
IOT_SOCKET_ERROR = Unspecified error.
227
of file third_party/iot_socket/include/iot_socket.h
iotSocketRecvFrom#
int32_t iotSocketRecvFrom (int32_t socket, void * buf, uint32_t len, uint8_t * ip, uint32_t * ip_len, uint16_t * port)
Receives data from the socket.
[in] | socket | Socket identification number. |
[out] | buf | Pointer to buffer where data should be stored. |
[in] | len | Length of buffer (in bytes). |
[out] | ip | Pointer to buffer where remote source address shall be returned (NULL for none). |
[inout] | ip_len | Pointer to length of 'ip' (or NULL if 'ip' is NULL):
|
[out] | port | Pointer to buffer where remote source port shall be returned (NULL for none). |
Returns
int32_t. Status information:
Number of bytes received (>=0), if len != 0.
0 = Data is available (len = 0).
IOT_SOCKET_ESOCK = Invalid socket.
IOT_SOCKET_EINVAL = Invalid argument (pointer to buffer or length).
IOT_SOCKET_ENOTCONN = Socket is not connected.
IOT_SOCKET_ECONNRESET = Connection reset by the peer.
IOT_SOCKET_ECONNABORTED = Connection aborted locally.
IOT_SOCKET_EAGAIN = Operation would block or timed out (may be called again).
IOT_SOCKET_ERROR = Unspecified error.
251
of file third_party/iot_socket/include/iot_socket.h
iotSocketSend#
int32_t iotSocketSend (int32_t socket, const void * buf, uint32_t len)
Send data or check if data can be sent on a connected socket.
[in] | socket | Socket identification number. |
[in] | buf | Pointer to buffer containing data to send. |
[in] | len | Length of data (in bytes). |
Returns
int32_t. Status information:
Number of bytes sent (>=0), if len != 0.
0 = Data can be sent (len = 0).
IOT_SOCKET_ESOCK = Invalid socket.
IOT_SOCKET_EINVAL = Invalid argument (pointer to buffer or length).
IOT_SOCKET_ENOTCONN = Socket is not connected.
IOT_SOCKET_ECONNRESET = Connection reset by the peer.
IOT_SOCKET_ECONNABORTED = Connection aborted locally.
IOT_SOCKET_EAGAIN = Operation would block or timed out (may be called again).
IOT_SOCKET_ERROR = Unspecified error.
Note
The function doesn't guarantees the packets are transmitted to remote note, which are enqueued in the queue.
The function can only send max of 1460 bytes in case of plain TCP and UDP. For TLS, the max buffer length is 1370.
272
of file third_party/iot_socket/include/iot_socket.h
iotSocketSendTo#
int32_t iotSocketSendTo (int32_t socket, const void * buf, uint32_t len, const uint8_t * ip, uint32_t ip_len, uint16_t port)
Send data or check if data can be sent on a socket.
[in] | socket | Socket identification number. |
[in] | buf | Pointer to buffer containing data to send. |
[in] | len | Length of data (in bytes). |
[in] | ip | Pointer to remote destination IP address. |
[in] | ip_len | Length of 'ip' address in bytes. |
[in] | port | Remote destination port number. |
Returns
int32_t. Status information:
Number of bytes sent (>=0), if len != 0.
0 = Data can be sent (len = 0).
IOT_SOCKET_ESOCK = Invalid socket.
IOT_SOCKET_EINVAL = Invalid argument (pointer to buffer or length).
IOT_SOCKET_ENOTCONN = Socket is not connected.
IOT_SOCKET_ECONNRESET = Connection reset by the peer.
IOT_SOCKET_ECONNABORTED = Connection aborted locally.
IOT_SOCKET_EAGAIN = Operation would block or timed out (may be called again).
IOT_SOCKET_ERROR = Unspecified error.
Note
If number of bytes to be send exceeds the MSS size specified by remote node, the API will return IOT_SOCKET_ERROR. To know the MSS size for the socket, use sl_si91x_get_socket_mss() utility, In the case of TCP, this should be called after iotSocketConnect().
The function doesn't guarantees the packets are transmitted to remote note, which are enqueued in the queue.
The function can only send max of 1460 bytes in case of plain TCP or UDP. For TLS, the max buffer length is 1370.
298
of file third_party/iot_socket/include/iot_socket.h
iotSocketGetSockName#
int32_t iotSocketGetSockName (int32_t socket, uint8_t * ip, uint32_t * ip_len, uint16_t * port)
Retrieve local IP address and port of a socket.
[in] | socket | Socket identification number. |
[out] | ip | Pointer to buffer where local address shall be returned (NULL for none). |
[inout] | ip_len | Pointer to length of 'ip' (or NULL if 'ip' is NULL):
|
[out] | port | Pointer to buffer where local port shall be returned (NULL for none). |
Returns
int32_t. Status information:
0 = Operation successful.
IOT_SOCKET_ESOCK = Invalid socket.
IOT_SOCKET_EINVAL = Invalid argument (pointer to buffer or length).
IOT_SOCKET_ERROR = Unspecified error.
315
of file third_party/iot_socket/include/iot_socket.h
iotSocketGetPeerName#
int32_t iotSocketGetPeerName (int32_t socket, uint8_t * ip, uint32_t * ip_len, uint16_t * port)
Retrieve remote IP address and port of a socket.
[in] | socket | Socket identification number. |
[out] | ip | Pointer to buffer where remote address shall be returned (NULL for none). |
[inout] | ip_len | Pointer to length of 'ip' (or NULL if 'ip' is NULL):
|
[out] | port | Pointer to buffer where remote port shall be returned (NULL for none). |
Returns
int32_t. Status information:
0 = Operation successful.
IOT_SOCKET_ESOCK = Invalid socket.
IOT_SOCKET_EINVAL = Invalid argument (pointer to buffer or length).
IOT_SOCKET_ENOTCONN = Socket is not connected.
IOT_SOCKET_ERROR = Unspecified error.
333
of file third_party/iot_socket/include/iot_socket.h
iotSocketGetOpt#
int32_t iotSocketGetOpt (int32_t socket, int32_t opt_id, void * opt_val, uint32_t * opt_len)
Get socket option.
[in] | socket | Socket identification number. |
[in] | opt_id | Option identifier. One of the values from Socket Option Id |
[out] | opt_val | Pointer to the buffer that will receive the option value. |
[inout] | opt_len | Pointer to length of the option value:
|
Returns
int32_t. Satus information:
0 = Operation successful.
IOT_SOCKET_ESOCK = Invalid socket.
IOT_SOCKET_EINVAL = Invalid argument.
IOT_SOCKET_ENOTSUP = Operation not supported.
IOT_SOCKET_ERROR = Unspecified error.
Note
The following are the options, which are supported currently.
358
of file third_party/iot_socket/include/iot_socket.h
iotSocketSetOpt#
int32_t iotSocketSetOpt (int32_t socket, int32_t opt_id, const void * opt_val, uint32_t opt_len)
Set socket option.
[in] | socket | Socket identification number. |
[in] | opt_id | Option identifier. One of the values from Socket Option Id. |
[in] | opt_val | Pointer to the option value. |
[in] | opt_len | Length of the option value in bytes. |
Returns
int32_t. Status information:
0 = Operation successful.
IOT_SOCKET_ESOCK = Invalid socket.
IOT_SOCKET_EINVAL = Invalid argument.
IOT_SOCKET_ENOTSUP = Operation not supported.
IOT_SOCKET_ERROR = Unspecified error.
Note
The following are the options, which are supported currently.
381
of file third_party/iot_socket/include/iot_socket.h
iotSocketClose#
int32_t iotSocketClose (int32_t socket)
Close and release a socket.
[in] | socket | Socket identification number. |
Returns
int32_t. Status information:
0 = Operation successful.
IOT_SOCKET_ESOCK = Invalid socket.
IOT_SOCKET_EAGAIN = Operation would block (may be called again).
IOT_SOCKET_ERROR = Unspecified error.
Note
Calling close on server or first client socket would end up closing other socket as well.
395
of file third_party/iot_socket/include/iot_socket.h
iotSocketGetHostByName#
int32_t iotSocketGetHostByName (const char * name, int32_t af, uint8_t * ip, uint32_t * ip_len)
Retrieve host IP address from host name.
[in] | name | Host name. |
[in] | af | Address family. One of value from IOT_SOCKET_ADDRESS_FAMILY |
[out] | ip | Pointer to buffer where resolved IP address shall be returned. |
[inout] | ip_len | Pointer to length of 'ip':
|
Returns
int32_t. Status information:
0 = Operation successful.
IOT_SOCKET_EINVAL = Invalid argument.
IOT_SOCKET_ENOTSUP = Operation not supported.
IOT_SOCKET_ETIMEDOUT = Operation timed out.
IOT_SOCKET_EHOSTNOTFOUND = Host not found.
IOT_SOCKET_ERROR = Unspecified error.
414
of file third_party/iot_socket/include/iot_socket.h