TCP connections with overlapped I/O
-
08-02-2021 - |
سؤال
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.
المحلول
ConnectEx
allows an overlapped connection attempt.
To cancel this one would need to use CancelIo
passing the SOCKET
as if it were a HANDLE
(it is really). But this must be done from the same thread that called ConnectEx
. 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 (the OVERLAPPED
instance is used to fully identify the IO operation).
نصائح أخرى
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.