Does anyone know the history of the SO_LINGER socket option? Was this a
purposeful decision or an oversight? Am I missing something?
Thanks,
Phillip Soltan
SO_LINGER in 2.2 specifies how long close() will block waiting for the connection
shutdown. It does not force an abort.
This blocking makes a difference in the error reporting; when the socket is asynchronously
closed and an RST or ICMP is received after close returned the BSD sockets API offers no way
to pass this error to the application. A linger block time prevents that.
In practice there is a long standing bug in the linux 2.2+ stack that this error will not
be returned by close() anyways, so it is kind of pointless currently in Linux.
In 2.4 SO_LINGER with a zero linger time and linger == 1 will force an connection abort.
In 2.2 that is not implemented.
-Andi
That is incorrect, according to Richard Stevens. In "UNIX Network
Programming" (second edition) on page 187 he says:
If "l_onoff" is nonzero and l_linger is nonzero, then the kernel
will linger when the socket is closed. That is, if there is any data
still remaining in the socket send buffer, the process is put to sleep
until either (a) all the data is sent and acknowledged by the peer
TCP, or (b) the linger time expires. If the socket has been set
nonblocking, it will not wait for the "close" to complete, even if the
linger time is nonzero. When using this feature of the SO_LINGER
option it is important for the application to check the return value
from "close", because if the linger time expires before the remaining
data is sent and acknowledged, "close" returns EWOULDBLOCK and any
remaining data in the send buffer is discarded.
>
> This blocking makes a difference in the error reporting; when the socket is asynchronously
> closed and an RST or ICMP is received after close returned the BSD sockets API offers no way
> to pass this error to the application. A linger block time prevents that.
>
> In practice there is a long standing bug in the linux 2.2+ stack that this error will not
> be returned by close() anyways, so it is kind of pointless currently in Linux.
>
> In 2.4 SO_LINGER with a zero linger time and linger == 1 will force an connection abort.
> In 2.2 that is not implemented.
>
> -Andi
Phillip Soltan
> Andi Kleen <fre...@alancoxonachip.com> wrote in message news:<oup4rsi...@pigdrop.muc.suse.de>...
> > "Phillip Soltan" <pso...@vcnet.com> writes:
> >
> > > I have generally found Linux networking to be a superset of BSD networking.
> > > The one exception I've come across is the SO_LINGER socket option. If
> > > "linger" is turned on, it is supposed to abort the TCP connection if there
> > > is still data left to send after the linger time has completed. This is my
> > > understanding based on Richard Steven's book "Unix Network Programming".
> > > Linux (RH6.2/2.2.14 kernel), on the other hand, returns from "close" and
> > > continues to transmit what is left in the send queue.
> > >
> > > Does anyone know the history of the SO_LINGER socket option? Was this a
> > > purposeful decision or an oversight? Am I missing something?
> >
> > SO_LINGER in 2.2 specifies how long close() will block waiting for the connection
> > shutdown. It does not force an abort.
>
> That is incorrect, according to Richard Stevens. In "UNIX Network
> Programming" (second edition) on page 187 he says:
It's correct on Linux. Stevens generally describes what he learned on BSD,
but that may not necessarily apply to the Linux sockets implementation.
-Andi