Is it possible to initiate a TCP connection request with overlapped I/O, and cancel it before the connection has been completed in Windows? I need to support at least Windows XP SP2.
TCP connections with overlapped I/O
2.4k views Asked by Jörgen Sigvardsson At
2
There are 2 answers
0
On
From here:
overlap
This directory contains a sample server program that uses overlapped I/O. The sample program uses the AcceptEx function and overlapped I/O to handle multiple asynchronous connection requests from clients effectively. The server uses the AcceptEx function to multiplex different client connections in a single-threaded Win32 application. Using overlapped I/O allows for greater scalability.
ConnectEx
allows an overlapped connection attempt.To cancel this one would need to use
CancelIo
passing theSOCKET
as if it were aHANDLE
(it is really). But this must be done from the same thread that calledConnectEx
. Managing things so you can achieve that thread specificity is unlikely to be easy.After XP/2003 (ie. Vista/2008/8/2008R2) you can use
CancelIoEx
from a different thread (theOVERLAPPED
instance is used to fully identify the IO operation).