Skip to end of metadata
Go to start of metadata

You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 9 Next »

Controlling Socket Blocking Options

Socket blocking options may be configured during compile time by adjusting the net_cfg.h macro NET_SOCK_CFG_BLOCK_SEL to the following values:

NET_SOCK_BLOCK_SEL_DFLT
NET_SOCK_BLOCK_SEL_BLOCK
NET_SOCK_BLOCK_SEL_NO_BLOCK

NET_SOCK_BLOCK_SEL_DFLT selects blocking as the default option, however, allows run-time code to override blocking settings by specifying additional socket.
NET_SOCK_BLOCK_SEL_BLOCK configures all sockets to always block.
NET_SOCK_BLOCK_SEL_NO_BLOCK configures all sockets to non blocking.

See the section C-13-46 and section C-13-48 for more information about sockets and blocking options.

Specific Socket Option API

µC/TCP-IP provides a set of APIs to configure sockets on an individual basis. These APIs are listed below and detailed in Network Socket Functions:

Generic Socket Option API

µC/TCP-IP provides two APIs to read and configure socket option values. These APIs are listed below and detailed in Network Socket Functions:

Their BSD equivalent are listed below. See also BSD Functions.

MSL

Maximum Segment Lifetime (MSL) is the time a TCP segment can exist in the network, and is defined as two minutes. 2MSL is twice this lifetime. It is the maximum lifetime of a TCP segment on the network because it supposes segment transmission and acknowledgment.

Currently, Micrium does not support multiple sockets with identical connection information. This prevents new sockets from binding to the same local addresses as other sockets. Thus, for TCP sockets, each close() incurs the TCP 2MSL timeout and prevents the next bind() from the same client from occurring until after the timeout expires. This is why the 2MSL value is used. This can lead to a long delay before the socket resource is released and reused. µC/TCP-IP configures the TCP connection's default maximum segment lifetime (MSL) timeout value, specified in integer seconds. A starting value of 3 seconds is recommended.

If TCP connections are established and closed rapidly, it is possible that this timeout may further delay new TCP connections from becoming available. Thus, an even lower timeout value may be desirable to free TCP connections and make them available for new connections as rapidly as possible. However, a 0 second timeout prevents µC/TCP-IP from performing the complete TCP connection close sequence and will instead send TCP reset (RST) segments.

For UDP sockets, the sockets close() without delay. Thus, the next bind() is not blocked.

 

TCP Keep-Alives (TODO)

µC/TCP-IP support TCP Keep-Alives. RFC  #1122 stipulate that "Keep-Alive mechanism periodically probes the other end of a connection when connection is otherwise idle, even when there is not data to be sent." 

It is possible to enable the Keep-Alive option for a specific socket by using the function NetSock_OptSet() with the option NET_SOCK_OPT_SOCK_KEEP_ALIVE.

Knowing your TCP connection ID, you can also used the API function NetTCP_ConnCfgTxKeepAliveEn().

Each time the connection Idle timeout occurs, the stack will send a keep-alive message to probe the other end of the connection. The timeout value for a given TCP connection can be set with the NetSock_OptSet() function and the NET_SOCK_OPT_TCP_KEEP_IDLE option. Else, knowing your TCP connection ID, the API function NetTCP_ConnCfgIdleTimeout()can also be use.

  • No labels