Embedded TCP/IP stack
4.7.0
|
fnet_return_t fnet_socket_close | ( | fnet_socket_t | s | ) |
Closes an existing socket.
s | Descriptor, identifying a socket to close. |
This function releases the socket descriptor s
, so that further references to s
fail with the error FNET_ERR_BAD_DESC.
An application should always have a matching call to the fnet_socket_close() for each successful call to the fnet_socket() to return any socket resources to the system.
For the SOCK_STREAM sockets, the SO_LINGER option controls the action of the closing, when unsent data is present on the socket and the fnet_socket_close() function is performed. This option has effect on TCP sockets only. To enable or disable the SO_LINGER option, the application should use the fnet_linger structure. This structure includes the l_onoff
and the l_linger
fields. If the l_onoff
has a non-zero value, then the SO_LINGER is enabled. Otherwise, the SO_LINGER option is disabled. The l_linger
field includes the timeout in seconds. If the SO_LINGER option is not used , the remaining data of the output buffer can be sent after the execution of the fnet_socket_close() in the background.
If a timeout expires and unsent data is present, the hard reset occurs and unsent data will be deleted.
If the SO_LINGER option is used with a zero timeout interval, the hard reset occurs immediately and unsent data will be deleted.