ConnectEx with IOCP problem
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 Get开发者_JS百科QueuedCompletionStatus 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?
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.
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.
精彩评论