poll系统调用和select的类似,也是利用轮询文件描述符来寻找就绪者。
函数原型:
int poll(struct pollfd *fds,nfds_t nfds,int timeout);
fds参数是一个pollfd结构类型的数组,它指定所有我们感兴趣的文件描述符上发生的可读,可写和异常事件。
struct pollfd {
int fd; /* file descriptor */
short events; /* requested events */
short revents; /* returned events */
};
nfds参数指定被监听事件集合fds的大小。其类型nfds_t的定义如下:
typedef unsigned long int nfds_t;
timeout参数指定poll的超时值,单位是毫秒。当timeout为-1时,poll调用将永远阻塞,直到某个事件发生;当timeout为0时,poll调用将立即返回。
poll的返回值和select相同。
I/O复用之poll模型
I/O复用之poll模型
I/O复用之poll模型
poll模式和select模式都是采用轮询的方法进行通讯。不同的是select借助fd_set结构体以及一些宏定义来完成,poll借助pollfd结构体来完成。
文字摘自linux高性能服务器(游双),这是我对poll的一点理解,还请各位多多指教。

相关文章:

  • 2021-09-03
  • 2022-01-07
  • 2021-11-18
  • 2021-04-17
  • 2021-07-07
  • 2021-06-01
  • 2021-04-10
  • 2021-12-06
猜你喜欢
  • 2021-05-27
  • 2021-12-24
  • 2022-12-23
  • 2021-12-01
  • 2021-11-13
  • 2021-11-09
  • 2022-12-23
相关资源
相似解决方案