Non-blocking socket errors

Heiko Wundram heikowu at ceosg.de
Fri May 7 11:30:28 EDT 2004


Hi all!

Does anybody know whether there is some form of concise reference to what 
behaviour sockets (AF_INET,SOCK_STREAM) exhibit when the remote end closes 
the writing/reading channel? I've looked at the sources of different 
implementations of event-loops (asyncore, medusa, twisted), and each of them 
seems to handle a different set of errors as representative for premature 
closing of one direction of the socket.

Let me give a little example of what I have found out (and this seems to be 
similarily handled in asyncore, medusa and twisted):

Client -> shutdown(1)
Server -> socket is readable and recv() returns ""
	-> signal server code that shutdown on read has happened.

But what happens if the following occurs:

Client -> shutdown(0)
Server -> ?? Nothing special happens, further writes succeed, until the OS 
send-buffer is full, and never raise an error.

Of course, you can create a myriad of combinations with this.

What's especially interesting for me is the case that the client calls 
shutdown(0), but the server still has data to be transmitted, and should thus 
signal to itself that the data has not been transferred completely.

Anyway, is there some form of reference to the behaviour of sockets? man 2 
recv/send aren't especially helpful in this respect, and what else I've found 
on the web for socket-programming isn't either... I know that each OS shows 
different behaviour, but I'm actually just interested in the Linux 2.x 
IP-stack with glibc.

Heiko.




More information about the Python-list mailing list