tags:

views:

61

answers:

2

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?

A: 

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.

Len Holgate
A: 

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.

charfeddine.ahmed
Interesting code... IMHO you're creating that IOCP incorrectly, as the dummy socket that you're creating to create the IOCP isn't created for overlapped use as you're using socket() and not `WSASocket()` with `WSA_FLAG_OVERLAPPED` see docs for http://msdn.microsoft.com/en-us/library/aa363862(VS.85).aspx regarding the "opened for overlapped I/O completion" requirement for the socket. Secondly if all you're using that first socket for is to create the IOCP then you can simply pass `NULL`. Thirdly I've never found that any 'unlocking' is required when using IOCPs as the docs suggest you should.
Len Holgate