> On Nov 3, 2022, at 11:37, Michael Wojcik via openssl-users <openssl-users@xxxxxxxxxxx> wrote: > >> It’s a rare >> issue, but when it does it’s a head-scratcher. To avoid that, it’s necessary >> to shutdown(SHUT_RD) then drain the read buffer before close(). > > Well, it's not *necessary* to do a half-close. Applications often know when they've received all the data the peer intends to send, thanks to record-delimiting mechanisms in the application protocol. > > And your description looks wrong anyway: shutdown(SHUT_RD) has implementation-defined behavior for TCP sockets (because TCP does not announce the read side of half-close to the peer), and on Linux causes blocked receives and subsequent receives to return 0 (according to references -- I have't tested it), which means after shutdown(SHUT_RD) you *can't* drain the receive buffer. shutdown(SHUT_WR) would work, since it sends a FIN, telling the peer you won't be sending any more data, and still allows you to receive. perl -MSocket -MIO::Socket::INET -e'my $s = IO::Socket::INET->new( Server => 1, Listen => 1 ) or die; my $port = $s->sockport(); my $c = IO::Socket::INET->new("localhost:$port") or die; syswrite $c, "hello"; my $sc = $s->accept(); shutdown($sc, SHUT_RD); sysread $sc, my $buf, 512 or die $!; print $buf' ^^ The above, I believe, demonstrates to the contrary: the read buffer is populated prior to shutdown and drained afterward. >> I would guess that many don’t and just don’t see the >> RST thing frequently enough to worry about it. Regardless, the documentation >> is already pretty voluminous, so if this doesn’t bite many folks, then hey. > > Yes, but wiki articles are always appreciated. I’ll see if I can whip something up. -FG