The behaviour of close() and closesocket() cobmined with SO_LINGER is quite clear for me. I'm still confused about shutdown(): does SO_LINGER apply to shutdown in the same way?
MSDN "The shutdown function does not block regardless of the SO_LINGER setting on the socket".
GNU documentation says: "Stop trying to transmit data from this socket. Discard any data waiting to be sent. Stop looking for acknowledgement of data already sent; don't retransmit it if it is lost."
It seems to me, that calling shutdown() just discards any data to be sent through the socket -- I just want to be sure. If I'm right I can call shutdown() followed by close[socket](), to break connection without blocking -- is it true?
Main Topics
Browse All Topics





by: jkrPosted on 2002-08-28 at 07:15:57ID: 7246559
>>seems to me that glibc shutdown is "hard" (doesn't wait
>>transmission of already send data), while behaviour of
>>Windows shutdown depends on SO_LINGER setting
The GNU document also states:
"If there is still data waiting to be transmitted over the connection, normally close tries to complete this transmission. You can control this behavior using the SO_LINGER socket option to specify a timeout period; see Socket Options."
So, that's basically the same behaviour as described in the MS document. Additionally, on the socket options:
SO_LINGER
Sets or gets the SO_LINGER option. The argument is
a linger structure.
struct linger {
int l_onoff; /* linger active */
int l_linger; /* how many seconds to linger for */
};
When enabled, a close(2) or shutdown(2) will not
return until all queued messages for the socket
have been successfully sent or the linger timeout
has been reached. Otherwise, the call returns imme
diately and the closing is done in the background.
When the socket is closed as part of exit(2), it
always lingers in the background.
(gnu manpages)
SO_LINGER
The SO_LINGER option controls the action taken when unsent data is queued on a socket and a closesocket is performed. See closesocket for a description of the way in which the SO_LINGER settings affect the semantics of closesocket. The application sets the desired behavior by creating a LINGER structure (pointed to by the optval parameter) with these members l_onoff and l_linger set appropriately.
(MSDN)