Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

How does TCP linger work?

1,939 views
Skip to first unread message

Doug Toppin

unread,
Jun 29, 1992, 10:09:40 AM6/29/92
to
The environment we work in is:
- approx. 50 computers from various vendors (SGI, Sun, Motorola)
- most running Unix
- some running a real-time system called PSOS
- all communicate via TCP/IP
My question is:
We cannot allow a crashed or hung-up destination application
to hang a sending application.
Therefore, we have had to experiment with using SO_LINGER and no linger.
In the book Unix Network Programming it is mentioned that the
timeout value specified with SO_LINGER is ignored but which systems
ignore it and which support it is not specified.
In our experience, the Motorola Unix did support the linger
timeout value.
On the SGI and the Sun, any value under 30 seconds resulted in a 30 second
linger, any value higher than 30 seconds caused a delay of
an unpredictable amount greater than 30 seconds or an indefinite delay.
We saw an apparent data loss when the linger timeout was set to 0
the socket was opened, data written, and then immediately closed.
We saw no data loss when the default linger setting (we assume
that linger is the default) was unchanged or we set it to not linger and
the socket was opened, data written, and then immediately closed.
What we are interested in is exactly what happens when the linger
timeout expires?
When the linger timeout is reached are resources allocated to the
socket immediately released?
What happens when the linger timeout is set to 0?
What happens when no linger is specified?

Please mail responses and I will post useful replies.
any information that you can provide is appreciated
thanks
Doug Toppin
uunet!melpar!toppin
703-560-5000, x4731

Eric Knox

unread,
Jul 1, 1992, 9:35:45 AM7/1/92
to
Included below is part of a document that was passed down to me when I began
my sockets introduction to TCP/IP. According to this, the linger options is
ignored (I don't currently know if that is true for all systems) and as
such, I never tried to set a timeout, but kept it at 0 (or immediate).

I believe the explanation below fully describes SO_LINGER, but if you have
any further questions, I might be able to answer them.

Eric G. Knox
kn...@aplexus.jhuapl.edu


--- BEGIN INCLUDED DOCUMENT ---

1.7.2 Closing a Connection: SO_LINGER

Specify the SO_LINGER option to determine whether TCP should perform a "grace-
ful" close:

setsockopt (sock, SOL_SOCKET, SO_LINGER, &linger, sizeof (linger));

A graceful close occurs when a connection is shutdown, TCP will try to make
sure that all the unacknowledged data in transmission channel are acknowledged
and the peer is shutdown properly by going through an elaborate set of state
transitions. The variable linger is contains values indicating the amount of
time to SO_LINGER as specified in the data structure linger in the file
vw/h/socket.h. The structure linger contains two parameters: l_onoff and
l_linger. The parameter l_onoff can be set to 1 to turn on the SO_LINGER
option and set to 0 to turn off the SO_LINGER option. The parameter l_linger
determines the amount of time for the shutdown. If the parameter l_onoff is set
to 1 and l_linger is set to 0, the default value of TCP_LINGERTIME (specified
in tcp_timer.h) is used for incoming connections accepted on the socket.

When SO_LINGER is turned on and l_linger is set to 0, TCP simply drops the
connec tion by sending out a RST if a connection is already established. This
frees up the space allocated to the TCP protocol control block and wakes up all
the sleepers on the socket.

Currently, the exact value of l_linger is actually ignored (other than 0) so
that TCP performs the state transitions if l_linger is not 0 but doesn't
explicitly use its value. For the client side socket, the value of l_linger is
not changed if it is set to 0. Issue another setsockopt( ) after the accept( )
call to ensure that the value of l_linger is set to 0 on a newly accepted
socket connection.

--- END INCLUDED DOCUMENT ---

0 new messages