Help: shutdown(..., SHUT_WR) on TCP sockets
Sergey Organov
sorganov@gmail.com
Fri May 17 13:15:00 GMT 2019
Florian Weimer <fweimer@redhat.com> writes:
[...]
>> Given the above, could please somebody clarify what is the actual
>> intended behavior of shutdown(..., SHUT_WR) on GLIBC/Linux nowadays?
>
> Thanks for raising the issue. I posted a patch to libc-alpha.
>
> What you saw is the expected behavior for the mainline Linux kernel.
> Since this is what distributions ship, I think it makes sense to
> document it.
Thanks! While we are at this part of the manual, I've found that:
"When you have finished using a socket, you can simply close its file
descriptor with close; see Opening and Closing Files. 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."
has its own problem.
It looks like SO_LINGER is disabled by default in Linux, so "_normally_"
in "normally lose tries to complete this transmission" is probably
wrong.
As for the actual behavior, is close()/shutdown() on sockets is more
Linux kernel question than GLIBC one? I.e., is GLIBC only a thin wrapper
over calls to kernel and does nothing special by itself? If so, do you
have some reference where I could get information on behavior details
and/or check relevant discussions? Just ask in generic Linux kernel
mailing list?
I mean, what you wrote in the patch to GLIBC documentation is close to
my observations, yet Linux manual page on SO_LINGER seems to document
entirely different behavior, see below. That means you've likely got
your information elsewhere, from more recent/reliable source.
SOCKET(7) Linux Programmer's Manual SOCKET(7)
[...]
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 immediately and the closing is done in the background.
When the socket is closed as part of exit(2), it always
lingers in the background.
-- Sergey
More information about the Libc-help
mailing list