tags:

views:

78

answers:

2

I have read through the documentation for Winsock2 on MSDN, but I still need clarification on a few things, if anyone can help.

I planned to make something like the the setup you get when you use WSAAsyncSelect(), but using a separate thread. Can I use WSAEventSelect() to link more than one socket to a single event object?

If I used a completion port instead, which events do I get through the completion port? The MSDN has a list in terms of file operations, but I had trouble relating them to which events (FD_READ, FD_WRITE, ect..) would be sent through the completion port. Is there a way to tell which event is completing? or do I have to take note of this and store it in a struct each time I send or recv something?

thanks for any *help anyone can give me on this =D

edit: better yet, would I better off just switching to C# to do this? It seems to be very popular and better suited to this specific task.

+1  A: 

[Disclaimer: I've extremely limited experience with socket programming.]

I planned to make something like the the setup you get when you use WSAAsyncSelect(), but using a separate thread. Can I use WSAEventSelect() to link more than one socket to a single event object?

That wouldn't make sense. An event can just be signaled once. So if you'd have multiple sockets connected to the same event, then when it gets signaled you'd never knew which socket signaled the event!

What you could do is create an event for every socket (possibly multiple events per socket: for every FD_* event you're interested in) and use WSAWaitForMultipleEvents ( http://msdn.microsoft.com/en-us/library/ms742219%28v=VS.85%29.aspx)

Martin
this is where I am confused. If what you are saying is true, then what would happen if one socket got two read events in a row? wouldn't the API wait for WSAEnumNetworkEvents() to be called to reset the event before signaling it again?
Nick
I do not know. I do not expect the API to be so smart though. That is, yes, I fully expect the event to only be set once.
Martin
A: 

No, you cannot link multiple sockets to a single WSAEVENT. You have to call WSACreateEvent() and WSAEventSelect() for each individual socket that you want to receive notifications for. You can use WSAWaitForMultipleEvents() to have a single thread wait for events from multiple sockets, though.

As for using completion ports, I suggest you read MSDN's articles on the matter, such as:

Windows Sockets 2.0: Write Scalable Winsock Apps Using Completion Ports.

Remy Lebeau - TeamB
at the time I didn't fully understand completion ports..but I have done quite a bit of reading on the topic, and now, my current configuration does not need any event objects at all. I didn't know that AcceptEx() would trigger the completion port..so that pretty much fixed my problem. Thanks
Nick