I am reading a book about network progamming in C. It is from 2004. In the example code, author is using select C function to accept multiple connections from the client. Is that function deprecated today?

I see that there are different ways to accept multiplexed I/O like poll and epoll. What are the advantages?

有帮助吗?

解决方案

It's not deprecated, and lots of programs rely on it.

It's just not the best tool as it has some limitations:

  • The number of file descriptors is limited (OS specific, usually possible to increase it with kernel recompiling).
  • Doesn't scale well (with lots of fds): the whole FD set must be maintained, and re-initialized as select manipulates it.

Feel free to use it if these aren't relevant for you. Otherwise use poll/libevent if you're looking for a cross-platform solution, or in some rare-cases epoll/kqueue for platform specific optimized solutions.

其他提示

It's not deprecated in its behavior, but its design may have performance issues. For example, linux epoll() documentation states:

API can be used either as an edge-triggered or a level-triggered inter‐ face and scales well to large numbers of watched file descriptors.

Since the efficient alternatives are specific to each operating system, an option better than directly using select() is to use a cross platform multiplexing library (which uses the best implementation available), examples being:

If you're developing for a specific operating system, use the recommended implementation for high performance applications.

However, since some people don't like current libraries for I/O multiplexing (due to "being ugly"), select is still a viable alternative.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top