Archived

This topic is now archived and is closed to further replies.

Overlapped I/O in Winsock2

This topic is 5007 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I''m just starting out with multithreaded overlapped I/O in Winsock2, and I''m running into a few difficulties. Basically, what I have so far is a network thread in a constant WSAWaitForMultipleEvents state. First off, is this the best way to approach the problem? A single thread for all network processing? I''m looking for my "network engine" to eventually support clients numbering in the hundreds. Secondly, I assume the way to do this is to have an array of events, one for each socket, and use that in the Wait call. But does this mean I have to rebuild the array every time a client connects\disconnects? I can''t see this being a major performance issue, but I want to make sure I''m doing things the "right way" before I carry on. Finally, if I''m using preemptive IOCPs for receives, do I still need to register interest in the FD_READ event? Same with FD_WRITE. Can I safely ignore these events? That''s about it, any help would be greatly appreciated

Share this post


Link to post
Share on other sites
If you have a linear array of active items, a good trick when removing an item is to swap the last item and the item being removed, then shorten the array by 1. This gives you order(1) removal, rather than order(n) (per item).

Share this post


Link to post
Share on other sites
Hi,

Problem with the Event method is that you can only have somethign like 64 handles open in each thread :/ so max ever possible is to handle 60 odd connections in a single thread.. so u can have multiple threads all waiting on 60ish connections. Note though that fewer threads the better (optimal is 1 or 2 thread per CPU)

The ultimate solution is to just use IOCPs. that way you dont have to create an event for your connections and can handle Every connection on 1 waiting thread :D but it can be quite complex to make it all work smoothly.. I did it for my final year project for degree and it was still buggy when i finished the degree (its perfect now though)

good luck !

Share this post


Link to post
Share on other sites