Question

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?

Was it helpful?

Solution

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.

OTHER TIPS

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top