[Python-Dev] Socket timeout and completion based sockets
shibturn at gmail.com
Mon Nov 26 17:05:04 CET 2012
On 26/11/2012 11:49am, Kristján Valur Jónsson wrote:
> However, other implementations of python sockets, e.g. ones that rely on
> IO completion, may not have the luxury of using select. For example, on
> Windows, there is no way to abort an IOCP socket call, so a timeout must
> be implemented by aborting the wait. Dealing with the resulting race
> can be an interesting challenge.
I am not quite sure what you mean by "aborting the wait". But you can
abort an overlapped operation using CancelIo()/CancelIoEx().
I have just done some experimenting.
Using CancelIo()/CancelIoEx() to abort an operation started with
WSARecv() does not seem to cause a problem -- you just call
GetOverlappedResult() afterwards to check whether the operation
completed before it could be aborted.
But aborting an operation started with WSASend() sometimes seems to
"break" the connection: a subsequent WSARecv()/WSASend() will fail with
WSAECONNABORTED or WSAECONNRESET depending on which end of the
connection you are on.
So, as you say, if you abort a send then you cannot expect to
successfully resend the data later.
More information about the Python-Dev