Linux epoll的使用
Linux epoll的使用
在Linux上,执行man epoll之后,可以得到这些结果
- NAME
- epoll - I/O event notification facility
- SYNOPSIS
- #include <sys/epoll.h>
- DESCRIPTION
- epoll is a variant of poll(2) that can be used either as Edge or Level Trig-
- gered interface and scales well to large numbers of watched fds. Three system
- calls are provided to set up and control an epoll set: epoll_create(2),
- epoll_ctl(2), epoll_wait(2).
- An epoll set is connected to a file descriptor created by epoll_create(2).
- Interest for certain file descriptors is then registered via epoll_ctl(2).
- 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上是否产生以及产生了什么事务。
|
评论暂时关闭