Search code examples
cioposix-select

Is C select() function deprecated?


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?


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.