The joys and jilts of non-blocking sockets

Robert Amesz rcameszREMOVETHIS at dds.removethistoo.nl
Wed May 30 19:01:37 EDT 2001


I wrote:

> [Non-blocking connect under Win98, Python 2.1]
>
> But don't despair: if a connection is refused trying to connect
> again to the same host using the same socket will yield the
> following surprising exception:
> 
>    (10022, 'Invalid argument')
>    10022 =                 WSAEINVAL
> 
> Well, it accepted the parameter(s) before, so what's that all
> about? Furthermore, it doesn't make any difference if you change
> the port number, you'll get the same result. Using a different
> hostname which points to the same IP-address doesn't change
> anything either, but using a different hostname *does*, strangely
> enough. 


More weirdness. It seems you only get this error if the first and 
second connect() are roughly less than 0.9 seconds apart. If it's more 
than 0.95 seconds, you always get:

   (10035, 'The socket operation could not complete without blocking')
   10035 = EWOULDBLOCK     WSAEWOULDBLOCK

As select() will do the obvious, and just report the refused connection 
as non-writeable forever, that means you're never going to see a 
WSAEINVAL error if you only use connect() a second time when the socket 
is actually writeable.


Robert Amesz



More information about the Python-list mailing list