关于select/poll/epoll的特点和区别
select 每次都是轮询,而且每次都要重新加入到fd_set中,即会清空fd_set
int select(int nfds, fd_set* readfds, fd_set* writefds, fd_set* errorfds, struct timeval* timeout);
poll 每次都是轮询,但不需要再加入到fd_set中,即不会清空fd_set
int poll(struct pollfd fds[], nfds_t nfds, int timeout);
epoll 不是轮询,分为电平触发和边缘触发
电平触发(缺省):当通知过某个fd,就算不做了任何操作,下次还会继续通知,传统的select/poll都是这种模型的代表
边缘触发(高速工作方式):当通知过某个fd时,下次不会通知了,直到做了某些操作导致那个文件描述符不再为就绪状态了
int epoll_create(int size);
int epoll_ctl(int epfd,int op,int fd,struct epoll_event *event);
int epoll_wait(int epfd,struct epoll_event *events,int maxevents,int timeout);
参考: