1833750 Members
3379 Online
110063 Solutions
New Discussion

blocking in socket close

 
???_408
Occasional Contributor

blocking in socket close

Hey all,
My applications are run on HP 10.20. They are connected Socket.
when lan cable pull out , the application are hang in close() system call, like this

(gdb) where
#0 0xc013e920 in _close_sys () from /usr/lib/libc.1
#1 0xc0149230 in close () from /usr/lib/libc.1
#2 0x1dcd0 in libSockShutdownSockFd (fd=17) at Sock_socket.c:699
#3 0x1db80 in libSockClose (fdInfoPtr=0x401502b8) at Sock_socket.c:663
#4 0x1b8cc in libESockRecvTimerExpired (timerInfo=0x40150a58) at Sock_extern.c:146
#5 0x1ff00 in libSockChkTimer () at Sock_timer.c:187
#6 0x196e4 in libSockEventHandler (n=0, rdMask=0x7b03acb0, wrMask=0x7b03adb0, exMask=0x7b03aeb0, timeOut=0x7b03afb0)

As I know, close() returns immediately. But the application is blocking.

I set l_onoff=1, l_linger=0 using setsockopt().
1 REPLY 1
rick jones
Honored Contributor

Re: blocking in socket close

Regardless of blocking or not, setting l_onoff=1 and l_linger=0 is badnews - it can lead to an abortive close of the connection rather than a graceful one. Abortive closes are bad.

So, instead of setting SO_LINGER, why not leave it unset - l_onoff = 0 and leave it at that. From the setsockopt manpage:

SO_LINGER controls the actions to be taken when there are
untransmitted data in a SOCK_STREAM send socket buffer when the socket
is closed, either due to an explicit call to close() or because the
application terminates normally or abnormally. The action is
determined by the values of members of the struct linger data
structure pointed to by optval in a call to setsockopt(). The data
type struct linger is defined in . If l_onoff is zero
(the default action), close() returns immediately, but the system
tries to transmit any unsent data and release the protocol connection
gracefully. If l_onoff is non-zero and l_linger is zero, close()
returns immediately, any unsent data is discarded, and the protocol
connection is aborted. If both l_onoff and l_linger are non-zero,
close() does not return until the system has tried to transmit all
unsent data and release the connection gracefully.
there is no rest for the wicked yet the virtuous have no pillows