SO_LINGER not working?

Holger Kiehl (hkiehl@dwd.d400.de)
Mon, 23 Jun 1997 12:15:36 +0200


I have a small TCP/IP server that does the following just after accept():

l.l_onoff = 1; l.l_linger = 0;
setsockopt(sockfd, SOL_SOCKET, SO_LINGER, (char *)&l, sizeof(struct linger));

i.e. it sets the linger time to 0 second. On Irix 5.3 and Ftx 3.0.1 this
code works as expected, calling netstat just after a client has disconnected
from my server, there are no connections left in TIME_WAIT state. However,
using the same code on Linux 2.0.25 or 2.0.30, it does not seem to care
about the SO_LINGER option. There are always connections left in TIME_WAIT
state. Is this a bug or am I doing something wrong?

The server is used to handle lots of connections that disconnect very
quickly. On Linux I will then have lots of connections in the TIME_WAIT
state. Is there another solution, other then the SO_LINGER option, to avoid
connections hanging around in the TIME_WAIT state?

Thanks,
Holger