|
-
October 24th, 2011, 04:07 AM
#1
Event is not signaled on non-blocking socket
Hi All
I have a non-blocking socket and I'm working with event objects. I'm on the client side. I'm implementing a hand-shake protocol. It's fairly straightforward, I connect to the server, I send query1, I receive resp1, I send query2, I receive resp2, and so on, it's a 4-5 way ping-pong like messaging. I'm not happy with it either but I have to live with it.
My problem is, after 4 rounds of send-recv, WSAWaitForMultipleEvents() wouldn't return.
Following is a representation of what I do in my code
Code:
event = CreateEvent(...)
sock = WSASocket(...., WSA_FLAG_OVERLAPPED)
WSAEventSelect(sock, event, FD_CONNECT)
WSAWaitForMultipleEvents(1, event, ...) // this one is ok
WSAEnumNetworkEvents(sock, event, &networkEvents)
and my client has connected to the server. Now I send something, select read and close events, and then sit in a loop
Code:
send(...)
WSAEventSelect(sock, event, FD_CLOSE | FD_READ)
loop()
{
WSAWaitForMultipleEvents(...INFINITE) // this one stucks after three iterations
...
WSAEnumNetworkEvents(sock, event, &networkEvents)
...
}
Ok, it's a bit more complicated than that. I take care of WSAEWOULDBLOCK cases. And there is another event to signal thread termination so WSAWaitForMultipleEvents would return to exit loop.
After each send() completes I call WSAEventSelect(sock, event, FD_CLOSE | FD_READ), and after each recv() completes I call WSAEventSelect(sock, event, FD_CLOSE | FD_WRITE), and I expect to be notified when there is something to be read on the socket, or the socket is ready for writing.
My problem : connect - send - recv - send - recv - stuck.
I tell the socket provider that I want to be niotified when it's ready for writing but it notifies me once for the second send, and the next recv works too, but then it's stuck and I'm not notified for write readiness.
Has anyone any ideas, apart from the design of the call flow?
Thanks
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|