The Select and Poll API provide a means to perform multiplexed I/O on sockets from an application. In Linux, all opened sockets are file descriptors.
If a particular application wishes to read from or write into multiple file descriptors, the program has to wait on the different file descriptors to know when data can be written or read to a specific opened socket file descriptor. This is problematic as a particular application will either have to spawn threads or processes to wait on multiple descriptors or frequently poll (NOTE: this is not the same as the poll API) the descriptors to check if I/O is possible on the opened socket descriptors.
To circumvent the above problem, select and poll API provide an application to offload the checking of the file descriptor to the linux kernel and not block on a particular file descriptor.
The select and Poll API are used specifically to achieve the below (A Linux Programming Interface – Michael Kerrisk):
- Check whether I/O is possible on a file descriptor without blocking if it is not possible.
- Monitor multiple file descriptors to see if I/O is possible on any of them.
Select and Poll API allow a Linux application to perform I/O multiplexing on sockets and other types of open file descriptors. Select and Poll APIs do not by themselves perform the I/O. They merely indicate when a particular file descriptor is ready to be written into or read from.
Select and Poll API is not specific to sockets and will be also handled in the “system Programming section” later for other types of file descriptors. However, the following set of articles describe the usage of select and Poll API in sockets.
Pingback: IPv6 Socket Code Example | Hitch Hiker's Guide to Learning