Subject: SO_LINGER lingeronof=1,l_linger=0, makes the socket close to wait for default time
To: None <tech-net@NetBSD.org>
From: TP <hongal@gmail.com>
List: tech-net
Date: 04/13/2007 17:18:47
New to the mailing list,please excuse if I did not follow
some mandatory procedures...on the list.
Here is my question(Did search NetBSD/Solaris/NT/FreeBSD/Linux forum
before for the answers.):
I am using SO_LINGER socket option with linger_onoff=1 and l_linger=0,
And I expect that my TCP connection get closed instantly and data discarded
after the close.,
What I am seeing is my socket is going in TIME_WAIT state after the close
for about 2 min, After digging the code a bit , I see that for
lingeronof=1 and l_linger=0 value
so_linger is forced to copy the default linger_time.
Could some one let me know:
1. The code is correct and its doing the right thing of waiting for 2min,
2. Or its ok to comment out this code , so that l_linger=0 is retained and
connection get closed with RST. Note that I am fine with
client getting RST and leading with data corruption etc related issue.
3. Or/And the definition of SO_LINGER should be different for
lingeronof=1 and l_linger=0.
Link to the code:
http://cvsweb.netbsd.org/bsdweb.cgi/src/sys/netinet/tcp_usrreq.c?annotate=1.13
In tcp_userreq.c
Link to the code snipped that I am referring in the question:
120 /*
121: * TCP attaches to socket via
PRU_ATTACH, reserving space,
122: * and an internet control block.
123: */
124: case PRU_ATTACH:
125: if (inp) {
126: error = EISCONN;
127: break;
128: }
129: error = tcp_attach(so);
130: if (error)
131: break;
132: if ((so->so_options &
SO_LINGER) && so->so_linger == 0)
1.13 ! glass 133: so->so_linger =
TCP_LINGERTIME * hz;
1.1 cgd 134: tp = sototcpcb(so);
135: break;
thanks
hongal