shutdown() and SHUT_RD on TCP sockets - anomalous behaviour?

From: Michael Kerrisk (m.kerrisk@gmx.net)
Date: Thu Oct 24 2002 - 07:21:49 EST


Hello,

I did an archive search and found a post that indicated that what I describe
below is known behaviour. The question is: why does this occur on Linux?

According to SUSv3, if we perform a shutdown(fd, SHUT_RD) on a socket, then
further reads on that socket should be disabled. In the AF_UNIX domain, all
is fine - things operate as expected. However, for stream sockets, things
are different (tested on 2.2.14, and 2.4.19):

1. If we perform a read() on the socket and there is no data, then 0 (EOF)
is (immediately) returned. (This is expected.)

2. However, the peer can still write() to the socket, and afterwards we can
read() that data from the socket, even though the reading half of the socket
should be shutdown. Instead of this behaviour, I expected the data to be
discarded, and the read() to return 0 as in point 1.

I've read the relevant source code to confirm the anomalous behaviour in
point 2. The question is: why do things happen in this way on Linux?

Thansk

Michael

-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/



This archive was generated by hypermail 2b29 : Thu Oct 31 2002 - 22:00:23 EST