linux_programming
select() vs poll() vs epoll()
select()
int select(int nfds, fd_set *readfds, fd_set *writefds, fd_set *exceptfds, struct timeval *timeout);
poll()
1
2
3
4
5
6
7
8int poll (struct pollfd *fds, unsigned int nfds, int timeout);
struct pollfd {
int fd;
short events;
short revents;
};epoll()
epoll_create(), epoll_ctl(), epoll_wait()
- select() have three bitmask-based set of fds(fd-set), poll() only have signle array of fds(pollfd structure)
select() will reconstruct the fds, so should build each set before each call; poll() has seperate events and returned events, so it don't need.
select() and poll() manage everything in user mode and send sets each time to wait on, to add another fd we need to add it to the set and call select()/poll() again(); however epoll() use epoll_create to create context in the kernel mode, using epoll_ctl to update the context.