Reputation: 3451
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?
Upvotes: 4
Views: 1188
Reputation: 10926
It depends on what you mean by "deprecated". The glibc man page for select
says the following right at the top:
WARNING:
select()
can monitor only file descriptors numbers that are less thanFD_SETSIZE
(1024)—an unreasonably low limit for many modern applications—and this limitation will not change. All modern applications should instead usepoll
orepoll
, which do not suffer this limitation.
When your documentation starts with a warning not to use a certain function, I think it's fair to call that function "deprecated". However, sometimes that term implies that a function is going to be removed in the near future, and select
is certainly not going to be removed.
Upvotes: 0
Reputation: 8030
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.
Upvotes: 4
Reputation: 96286
It's not deprecated, and lots of programs rely on it.
It's just not the best tool as it has some limitations:
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.
Upvotes: 8