Linux epoll的使用


在Linux上,执行man epoll之后,可以得到这些结果

  1. NAME  
  2.        epoll - I/O event notification facility  
  3.   
  4. SYNOPSIS  
  5.        #include <sys/epoll.h>  
  6.   
  7. DESCRIPTION  
  8.        epoll  is a variant of poll(2) that can be used either as Edge or Level Trig-  
  9.        gered interface and scales well to large numbers of watched fds. Three system  
  10.        calls  are  provided  to  set  up  and control an epoll set: epoll_create(2),  
  11.        epoll_ctl(2), epoll_wait(2).  
  12.   
  13.        An epoll set is connected to a file descriptor  created  by  epoll_create(2).  
  14.        Interest  for  certain  file descriptors is then registered via epoll_ctl(2).  
  15.        Finally, the actual wait is started by epoll_wait(2).  

epoll相关的的系统调用有:epoll_create, epoll_ctl和epoll_wait。

epoll_create用来创建一个epoll文件描述符。

epoll_ctl用来添加、修改、删除需要侦听的文件描述符及其事件。

epoll_wait/epoll_pwait 接收发生在被侦听的描述符上的,用户感兴趣的IO事件。

这个条件符使用完之后,直接用close关闭即可。另外,任何被侦听的文件描述拊只要其被关闭,那么它也会自动的从被侦听的文件描述符集体中删除。

一,epoll_create

函数声明如下: int epoll_create(int maxfds)

参数表示EPOLL所支持的最大句柄数,函数会返回一个新的EPOLL句柄,之后的所有操作将通过这个句柄来进行操作。该 函数生成一个epoll专用的文件描述符,会向内核申请一空间,用来存放你想存眷的socket fd上是否产生以及产生了什么事务。

  • 1
  • 2
  • 下一页

相关内容