具有重叠 I/O 的 TCP 连接
是否可以使用重叠 I/O 发起 TCP 连接请求,并在 Windows 中连接完成之前取消它?我需要至少支持 Windows XP SP2。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
ConnectEx
允许重叠的连接尝试。要取消此操作,需要使用
CancelIo< /code>
传递
SOCKET
就好像它是HANDLE
(确实如此)。但这必须从调用ConnectEx
的同一线程完成。管理事物以实现线程特异性不太容易。XP/2003(即 Vista/2008/8/2008R2)之后,您可以使用
CancelIoEx
来自不同的线程(OVERLAPPED
实例用于完全识别IO 操作)。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).来自此处:
From here: