//Create socket and connect then...
hEvent = WSACreateEvent(); //Create event
WSAEventSelect(socket, hEvent, FD_READ | FD_CLOSE); //Select items of
interest
//send data...
WSAWaitForMultipleEvents(1, hEvent, FALSE, WSA_INFINITE, FALSE);
//wait for read or close
WSAEnumNetworkEvents(socket, hEvent, &events); //See what
happened
if(events.lNetworkEvents & FD_READ)
{
//Handle reading...
}
else if(events.lNetworkEvents & FD_CLOSE)
{
//Handle shutdown...
}
else
{
//Error!
}
Seems cool, right? Problem is, sometimes after the call to
WSAEnumNetworkEvents events.lNetworkEvents will be zero which means my error
handling stuff gets called, even though there really is no error. I
interpret this to mean that nothing really happened, even though my event
got signaled. So, I changed the code to this:
WSAWaitForMultipleEvents(1, hEvent, FALSE, WSA_INFINITE, FALSE);
//wait for read or close
WSAEnumNetworkEvents(socket, hEvent, &events); //See what
happened
while(events.lNetworkEvents == 0)
{
Sleep(1000);
WSAEnumNetworkEvents(socket, hEvent, &events); //See what
happened
}
This worked, because eventually events.lNetworkEvents would be set to
something useful (READ or CLOSE). Of course, this code sucks, so I changed
it to this:
WSAWaitForMultipleEvents(1, hEvent, FALSE, WSA_INFINITE, FALSE);
//wait for read or close
WSAEnumNetworkEvents(socket, hEvent, &events); //See what
happened
while(events.lNetworkEvents == 0)
{
WSAResetEvent(hEvent);
WSAWaitForMultipleEvents(1, hEvent, FALSE, WSA_INFINITE, FALSE);
//wait for read or close
WSAEnumNetworkEvents(socket, hEvent, &events); //See what
happened
}
which does NOT work. By a little playing around I came up with the version
that does work, which is just to remove the call to WSAResetEvent. Now it
works. Still sucks, but I am still trying to understand what's going on.
My understanding is that a Win32 event is a binary thing. Its either
signaled or not. In the code above, my event gets signaled because I return
from WSAWaitForMultipleEvents, yet it seems to get signalled again inside
the while loop. resetting the event causes it to not get set again though.
Really weird.
So, my problem is twofold:
a) Why would events.lNetworkEvents EVER be 0 after a return from
WSAWaitForMultipleEvents, and
b) How can an event get signalled twice, yet when you reset the event it
never gets signalled?
Any thoughts would be greatly appreciated.
Thanks,
Taylor Boon
Sr. Software Engineer
BioNetrix Corp.
> Seems cool, right? Problem is, sometimes after the call to
> WSAEnumNetworkEvents events.lNetworkEvents will be zero [...]
Question: What are the return values from the various functions that you
call?
--
Cheers,
Felix.
If you post a reply, kindly refrain from emailing it, too.
Note to spammers: fel...@mvps.org is my real email address.
No anti-spam address here. Just one comment: IN YOUR FACE!
Also, I am running NT 4 SP 3.
Thanks,
Taylor Boon
Email: tay...@bscusa.com
Felix Kasza [MVP] wrote in message <3661596b....@207.68.144.14>...
> WSAWaitForMultipleEvents returns WSA_WAIT_EVENT_0
How can that be? In your earlier post, I just stumbled across this:
> hEvent = WSACreateEvent(); //Create event
//...
> WSAWaitForMultipleEvents(1, hEvent, FALSE, WSA_INFINITE, FALSE);
I am rusty with WSA stuff, but shouldn't that be "&hEvent"?
Anyway, if you have a (preferably small) sample that compiles, I'd be
interested in having a closer look.
Thanks,
Taylor
Felix Kasza [MVP] wrote in message <365c5d91....@207.68.144.14>...