Search⌘ K

An Important API: select() or poll()

Explore how select() and poll() system calls allow programs to check multiple I/O streams for readiness, supporting event-based concurrency and non-blocking event loops. Understand how these APIs manage input and output descriptors, enhance network application efficiency, and enable asynchronous I/O operations, essential for building responsive concurrent systems.

We'll cover the following...

With that basic event loop in mind, we next must address the question of how to receive events. In most systems, a basic API is available, via either the select() or poll() system calls.

What these interfaces enable a program to do is simple: check whether there is any incoming I/O that should be attended to. For example, imagine that a network application (such as a web server) wishes to check whether any network packets have arrived, in order to service them. These system calls let you do exactly that.

select()

Take select() for example. The manual page (on a Mac) describes the API in this manner:

C
int select(int nfds,
fd_set *restrict readfds,
fd_set *restrict writefds,
fd_set *restrict errorfds,
struct timeval *restrict timeout);

The actual description from the man ...