"Didn't receive any data" is the wrong way of looking at this.  It closes the 
socket if it receives an EOF.  A 0-byte return is an authoritative statement 
that there *will be* no more data, not that there isn't any right now.  "there 
isn't any right now" is EAGAIN.

A couple of brief experiments show me that after receiving an EOF and doing 
shutdown(SHUT_WR), at least the sockets from socketpair() will raise an 
exception if you then do a shutdown(SHUT_RD) since the socket is no longer 
connected.  So, victor, if you believe this is a bug you'd probably need to 
demonstrate some kind of resource being leaked.

-g

On Jun 27, 2014, at 2:50 PM, Guido van Rossum <[email protected]> wrote:

> What effect would calling shutdown(SHUT_RD) at this point have? The kernel 
> already knows that no more data will be read. IIUC SHUT_RD would be useful 
> only if you want to indicate you are not interested in reading more without 
> having received an EOF.
> 
> 
> On Fri, Jun 27, 2014 at 2:26 PM, Victor Stinner <[email protected]> 
> wrote:
> Hi,
> 
> While reviewing an old asyncore issue,
> http://bugs.python.org/issue12498
> 
> I read  the source code of _SelectorSocketTransport. I see that
> write_eof() calls sock.shutdown(socket.SHUT_WR). _read_ready() closes
> the socket if it didn't receive any data. It can keep the socket open
> to write more data if protocol.eof_received() is False, but it doesn't
> call sock.shutdown(socket.SHUT_RD).
> 
> Is there a reason for not calling sock.shutdown(socket.SHUT_RD)? If
> yes, it would be nice to document it in a comment.
> 
> Victor
> 
> 
> 
> -- 
> --Guido van Rossum (python.org/~guido)

Reply via email to