epoll的事件的状态

转自:http://www.cppblog.com/yangsf5/archive/2009/03/12/76353.html

1.状态

1、listen fd,有新连接请求,触发EPOLLIN。
2、对端发送普通数据,触发EPOLLIN。
3、带外数据,只触发EPOLLPRI。

2.状态详解

EPOLLIN
              The associated file is available for read(2) operations. 文件描述符可读
EPOLLOUT
              The associated file is available for write(2) operations. 文件描述符可写

EPOLLRDHUP
              Stream  socket peer closed connection, or shut down writing half
              of connection.  (This flag is especially useful for writing sim-
              ple code to detect peer shutdown when using Edge Triggered moni-
              toring.) 对端已经关闭了连接。当使用Edge Triggered监视时,这个标志对于编写简单的代码来检测对端关闭特别有用。

EPOLLPRI
              There is urgent data available for read(2) operations.带外数据,需要优先处理

EPOLLERR
              Error condition happened  on  the  associated  file  descriptor.
              epoll_wait(2)  will always wait for this event; it is not neces-
              sary to set it in events. 文件描述符发生错误时,epoll_wait会一直关注这个事件,所以不必特意注册。

EPOLLHUP
              Hang  up   happened   on   the   associated   file   descriptor.
              epoll_wait(2)  will always wait for this event; it is not neces-
              sary to set it in events.

EPOLLET
              Sets  the  Edge  Triggered  behavior  for  the  associated  file
              descriptor.   The default behavior for epoll is Level Triggered.
              See epoll(7) for more detailed information about Edge and  Level
              Triggered event distribution architectures. 相应文件描述符边缘触发

EPOLLONESHOT (since Linux 2.6.2)
              Sets  the  one-shot behavior for the associated file descriptor.
              This means that after an event is pulled out with  epoll_wait(2)
              the  associated  file  descriptor  is internally disabled and no
              other events will be reported by the epoll interface.  The  user
              must  call  epoll_ctl() with EPOLL_CTL_MOD to re-enable the file
              descriptor with a new event mask.

原文地址:https://www.cnblogs.com/BlueBlueSea/p/14870424.html