ConnectEx 存在 IOCP 问题
我使用 IOCP 制作了一个简单的虚拟服务器/虚拟客户端程序,用于某些测试/分析目的。 (而且我还想指出,我是异步网络编程的新手)
看起来服务器与原始客户端配合得很好,但是当虚拟客户端尝试使用 ConnectEx 函数连接到服务器时,IOCP 工作线程仍然被阻塞GetQueuedCompletionStatus 函数在服务器成功接受连接时永远不会返回结果。
问题是什么和/或原因是什么,我应该如何解决这个问题?
I've made a simple dummy server/dummy client program using IOCP for some testing/profiling purpose. (And I also wanted to note that I'm new to asynchronous network programming)
It looks like the server works well with original client, but when the dummy client tries to connect to the server with ConnectEx function, IOCP Worker thread still gets blocked by GetQueuedCompletionStatus function and never returns result while the server succeeds in accepting the connection.
What is the problem and/or the reason, and how should I do to solve this problem?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我认为你用你的评论回答了你自己的问题。
你的事件顺序不正确,你说你Bind、ConnectEx、Associate to IOCP。
您应该绑定,将套接字与 IOCP 关联,然后调用 ConnectEx。
I think you answer your own question with your comment.
Your sequence of events is incorrect, you say that you Bind, ConnectEx, Associate to IOCP.
You should Bind, associate the socket with the IOCP and THEN call ConnectEx.
即使您将接受的套接字关联到 IOCP 后,您的工作线程仍将在 GetQueuedCompletionStatus 上保持阻塞状态,直到您发布“解锁”完成事件。
除非您“解锁”新套接字,否则系统不会发送接收/写入操作的完成事件。
详情查看Push Framework源码 http://www.pushframework.com 它是一个C++网络应用使用 IOCP 的框架。
“解锁”技巧存在于“IOCPQueue”类中。
Even after you associate your accepted socket to IOCP, your worker thread will remain blocked on GetQueuedCompletionStatus untill you post an "unlocking" completion event.
Completion events for receive/write operation wo'nt be sent by the system unless you "unlock" your new socket.
For details ckeck the source code of Push Framework http://www.pushframework.com It is a C++ network application framework using IOCP.
The "unlocking" trick exists in the "IOCPQueue" class.