views:

684

answers:

2

I am referring to POSIX standard of select and poll system C API calls?

+13  A: 

I think that this link answers your question.

akappa
+1 for linking to Rich Stevens
qrdl
+1 for Richard Stevens
Scott
When was Stevens answer written? Does the comment about poll() not being available on BSD still apply? MacOS X (which is partly based on BSD) has poll(), and the POSIX standard (POSIX 2008) requires it.
Jonathan Leffler
Rich Stevens passed away in September 1999, so the answer has to be older than that. He mentions seeing a new change in BSD/OS 2.1, which was released in January 1996, so probably around then.
alanc
+2  A: 

The select() call has you use a bitmask to mark which sockets and file descriptors you want to watch, and then the operating system marks which ones in fact have had some kind of activity; poll() has you create a list of descriptor IDs, and the operating system marks each of them with the kind of event that occurred.

Thus with poll() you do not have to approach each socket that showed activity, and try reading and writing and prodding it to find out what kind of thing has happened to it. Instead, the poll() data structure tells you ahead of time whether the socket has new data to read, or has more room now to write, or what.

In fact, poll() has inspired yet another mechanism in modern Linux kernels: epoll() which improves even more upon the mechanism to allow yet another leap in scalability, as today's servers often want to handle tens of thousands of connections at once. This is a good introduction to the effort:

http://scotdoyle.com/python-epoll-howto.html

While this link has some nice graphs showing the benefits of epoll() (you will note that select() is by this point considered so inefficient and old-fashioned that it does not even get a line on these graphs!):

http://lse.sourceforge.net/epoll/index.html


Update: Here is another Stack Overflow question, whose answer gives even more detail about the differences:

http://stackoverflow.com/questions/2032598/caveats-of-select-poll-vs-epoll-reactors-in-twisted

Brandon Craig Rhodes
+1 for actually explaining the answer and not just linking to it.
Mark E