Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

TCP connections with overlapped I/O

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.

like image 853
Jörgen Sigvardsson Avatar asked Sep 01 '25 10:09

Jörgen Sigvardsson


1 Answers

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).

like image 99
Richard Avatar answered Sep 04 '25 08:09

Richard