SFML community forums
Help => Network => Topic started by: Shimajda on December 14, 2010, 12:53:18 pm
-
Does anyone knows how selector works?
Lets say that our selector can handle 64 sockets, and we have 640 connections to handle. So we have 10 selectors, 64 sockets for each and we check each selector for ready sockets.
Is that faster than iterating through simple socket array (or container)?
In http://www.sfml-dev.org/forum/viewtopic.php?t=1977&highlight=selector
Actually, the number of sockets that a selector can hold is OS-dependent. And it may perfectly be as low as 64.
How do i know how much sockets selector can handle in system that program is running?
-
Lets say that our selector can handle 64 sockets, and we have 640 connections to handle. So we have 10 selectors, 64 sockets for each and we check each selector for ready sockets.
Is that faster than iterating through simple socket array (or container)?
This doesn't produce the same results.
If you use more than one selector, you will have to wait until the first one receives data (or timeout) to proceed with the second one, etc.
If you use multiple sockets it's exactly the same, replace "selector" with "socket". Unless the sockets are in non-blocking mode, which would be the only good solution in this context. But this is a totally different approach.
How do i know how much sockets selector can handle in system that program is running?
I don't know if there's a standard constant/macro that defines it. It could be a good idea to check that :)
-
Sorry forgot about some details:
For each selector we have timeout: 0.01
In second case all sockets are in non-blocking code (blocking mode would be suicide :) )
I forgot becouse I have no idea how can i handle multiple clients in case where they send data only if they need and server have other things to do than just waiting for clients. Another thing is that I can't use threads.
-
There's no need to use selectors, especially if you would need several of them, if you can use non-blocking sockets.
I forgot becouse I have no idea how can i handle multiple clients in case where they send data only if they need and server have other things to do than just waiting for clients. Another thing is that I can't use threads.
Non-blocking mode is definitely the only solution in this context. Everything else would block the thread.
-
For my second question answer is here:
http://stackoverflow.com/questions/411295/alternatives-to-winsock2-with-example-server-source-in-c
Brian R. Bondy describes why select() is limited to 64 in some os, and how to check it.
There was mentioned about "Input/output completion port (IOCP)" but its Windows NT solution.
-
Thanks :)