-
November 3rd, 2008, 08:29 AM
#1
How to use WSAEnumNetworkEvents ??
Hi,
I've this piece of code on my Server, which tries to understand if a certian Client has sent data of has closed his socket.
Code:
WSAEVENT hEvent = CreateEvent(NULL, FALSE, FALSE, NULL);
ret = WSAEventSelect(m_client, hEvent, FD_READ | FD_CLOSE);
do
{
DWORD dReturn = WaitForSingleObject(hEvent, INFINITE);
int r = recv(m_client, sData, 64, 0);
printf("Status: %d\n", dReturn);
} while(true);
the value of 'dReturn' always equals ZERO and my question is:
How can I distinguish between: FD_READ to FD_CLOSE ??
Thanks
-
November 3rd, 2008, 08:58 AM
#2
Re: How to use WSAEnumNetworkEvents ??
There is an example of using WSAEnumNetworkEvents here.
After calling WSAEnumNetworkEvents you can use the WSANETWORKEVENTS structure to determine which events that has occured and if they failed or not.
- petter
-
November 3rd, 2008, 08:58 AM
#3
Re: How to use WSAEnumNetworkEvents ??
Use two events and wait for MultipleObject is one alternative....
TheCPUWizard is a registered trademark, all rights reserved. (If this post was helpful, please RATE it!)
2008, 2009,2010
In theory, there is no difference between theory and practice; in practice there is.
* Join the fight, refuse to respond to posts that contain code outside of [code] ... [/code] tags. See here for instructions
* How NOT to post a question here
* Of course you read this carefully before you posted
* Need homework help? Read this first
-
November 3rd, 2008, 11:14 AM
#4
Re: How to use WSAEnumNetworkEvents ??
The sample code given by Microsoft in its WSAEnumNetworkEvents() documentation is not very good.
At the very least, change the timeout in the second call to WSAWaitForMultipleEvents() from 1000 down to zero.
In addition, when checking for network events, remember that more than one network event can be set at one time. So, code like this is wrong:
Code:
// bad, don't use
if (NetworkEvents.lNetworkEvents == FD_ACCEPT)
{
// .. processing for FD_ACCEPT
}
// Process FD_READ notification
if (NetworkEvents.lNetworkEvents == FD_READ)
{
// .. processing for FD_READ
}
// Process FD_WRITE notification, etc...
It's wrong for the reason that multiple different FD's can be set for one single network event. Instead, uise code like this:
Code:
// better
if (NetworkEvents.lNetworkEvents & FD_ACCEPT)
{
// .. processing for FD_ACCEPT
}
// Process FD_READ notification
if (NetworkEvents.lNetworkEvents & FD_READ)
{
// .. processing for FD_READ
}
// Process FD_WRITE notification, etc...
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
|