Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Weirdness with WSAEnumNetworkEvents

268 views
Skip to first unread message

Taylor Boon

unread,
Nov 23, 1998, 3:00:00 AM11/23/98
to
I'm having a kind of weird problem using events and Winsock. Here's the
deal - I have a client that connects to a server, sends some data and waits
for the server to reply. Since this could potentially happen inside an NT
service, I use event notifications to notify my networking code when things
happen. Here's a snippet of the code:

//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.

Felix Kasza [MVP]

unread,
Nov 24, 1998, 3:00:00 AM11/24/98
to
Taylor,

> 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!

Taylor Boon

unread,
Nov 24, 1998, 3:00:00 AM11/24/98
to
Felix -
All calls succeed. WSAEnumNetEvents and WSAEventSelect return zero.
WSACreateEvent returns a valid event (not NULL), and
WSAWaitForMultipleEvents returns WSA_WAIT_EVENT_0
even n the case where the subsequent call to WSAEnumNetworkEvents returns a
events.lNetworkEvents that is zero.

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>...

Felix Kasza [MVP]

unread,
Nov 25, 1998, 3:00:00 AM11/25/98
to
Taylor,

> 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.

Taylor Boon

unread,
Nov 30, 1998, 3:00:00 AM11/30/98
to
Felix -
Yeah, you're right - &hEvent it is; my mistake when copying from the source.
I will try to get a small sample together in the next couple of days.

Thanks,
Taylor

Felix Kasza [MVP] wrote in message <365c5d91....@207.68.144.14>...

0 new messages