NOTE
select, poll, epoll
Select, poll, and epoll provide I/O multiplexing. These notes compare them starting with select's descriptor copying, scanning, and count limits.
This is a historical learning note and may contain outdated or incomplete understanding.
1. select
- Several major disadvantages of select:
- Every time select is called, the fd set needs to be copied from user space to kernel space. This overhead becomes large when there are many fds.
- At the same time, each select call requires the kernel to traverse all passed-in fds. This overhead also becomes large when there are many fds.
- The number of file descriptors supported by select is too small; the default is 1024.

2. poll
- Solves the third problem of select.

3. epoll
- Solves all three disadvantages of select.

3.1. LT
- Level triggered: as long as the read buffer is not empty, read events continue to be triggered; as long as the write buffer is not full, write events continue to be triggered.
- This is generally used because if an ET event is not handled properly after one trigger, there is no second chance.
3.2. ET
- Edge triggered: triggers once when the read buffer changes from empty to nonempty; triggers once when the write buffer changes from full to non-full.
- For example, a user sends a large file and fills the write buffer. Later, when the buffer becomes writable, a transition from full to non-full occurs once.
4. References
Drag to pan, scroll to zoom, and click a node to expand or collapse it. Large maps start with deeper levels collapsed; click nodes to expand them.
Discussion
Sign in with GitHub to comment. Discussions are stored as GitHub Issues.View on GitHub