I/O多路复用之poll

来源:互联网 发布:阿里云学生机认证 编辑:程序博客网 时间:2024/05/01 18:14

I/O多路复用之poll
函数原型:
int poll(struct pollfd *fderray, unsigned long nfds, int timeout);

参数一:是指向一个结构数组
struct pollfd {
 int fd; /* descriptor to check*/
 short evevts; /*events of interest on fd*/
 short revents; /* events that occurred on fd*/
}

events作为输入的常量:POLLIN(套接字可读)  POLLOUT(套接字可写)等
revents用于检查fd是否满足我们events监听条件同select中的FD_ISSET();

参数二:nfds决定了我们参数的数组元素个数

参数三:poll函数返回前等待多长时间,三种情况:
0:立即返回,不阻塞
>0:等待指定数目的毫秒数
INFTIM:永远等待(INFTIM定义为一个负值)


poll用法类似于selct参考select

原创粉丝点击