I need fast method for check socket has available data for read. I use select(), but it is not fast. Is faster method exists?
+3
A:
select() tends to degrade for large sets of sockets due to the need to rebuild the fd_set, and the way it gives results.
The epoll() API on Linux is perhaps my favourite method of dealing with multiple sockets. You might take a quick look into it, but it is not available on Windows.
I believe the only way around select()'s limitations on Windows with that many sockets is to use IO-completion ports.
Thanatos
2009-11-26 22:26:44
Rebuild the fd_set? You mean that the select() itself generates another fd_set with the ready to read sockets?
Spidey
2009-11-26 22:38:37
select() will modify any fd_set passed to it. Thus, on your next call, you must re-create a fd_set to pass to select() - either by going through your sockets, or by copying another fd_set, both of which are O(n) operations. APIs like epoll(), however, do not need to be passed a set of FDs - they remember them, and you notify the API of changes in your FD set.
Thanatos
2009-11-26 22:42:49
A:
You need to use completion ports on Windows. There are many online articles on how to use them.
Zan Lynx
2009-11-27 00:22:24