book
Article ID: KB0084860
calendar_today
Updated On:
Description
Resolution:
SO_LINGER controls the actions taken when a close is executed on a socket that has unsent data. This option can be cleared by toggling. The default is off.
The linger timeout interval is set with a parameter in the setsockopt call. The only useful values are zero and nonzero. If l_onoff is zero, close returns immediately, but any unsent data is transmitted (after close returns). If l_onoff is nonzero and l_linger is zero, close returns immediately,and any unsent data is discarded.
If l_onoff is nonzero and l_linger is nonzero, close does not return until all unsent data is transmitted (or the connection is closed by the remote system). In the default case, (SO_LINGER is off), close is not blocked. The socket itself, however, goes through graceful disconnect, and no data is lost.
An example is:
int result;
struct linger linger;
linger.l_onoff = 1; /*0 = off (l_linger ignored), nonzero = on */
linger.l_linger =1; /*0 = discard data, nonzero = wait for data sent */
result = setsockopt(s, SOL_SOCKET, SO_LINGER, &linger, sizeof(linger));
setopt _socket_linger will control l_onoff for the linger and setopt _socket_linger_time the time to linger. Note that if socket_linger is set to false , the time becomes "dont care".
Using the setopts below cause close to return immediately, but any unsent data is transmitted after close returns.
setopt _socket_linger FALSE
setopt _socket_linger_time 0 (HP/UX specific)