epoll with edge triggered event

前端 未结 2 1316
走了就别回头了
走了就别回头了 2020-12-29 18:09

The man page of epoll has a sample code for edge triggered like the following :

for (;;) {
    nfds = epoll_wait(epollfd, events, MAX_EVENTS, -1);
    if          


        
2条回答
  •  半阙折子戏
    2020-12-29 18:16

    As long as you read until you get an EAGAIN error, you will get the event the next time you are calling epoll_wait.

    The event is only triggered when there is a change between empty and non-empty (or full and non-full for EPOLLOUT), but that status then remains until the event is delivered via epoll_wait.

    On a somewhat related note: if you register for EPOLLIN and EPOLLOUT events and assuming you never fill up the send buffer, you still get the EPOLLOUT flag set in the event returned by epoll_wait each time EPOLLIN is triggered - see https://lkml.org/lkml/2011/11/17/234 for a more detailed explanation.

    And finally, the exact behaviour of edge-triggered mode actually depends on the socket type used and isn't really documented anywhere. I did some tests some time ago and documented my findings here: http://cmeerw.org/blog/753.html#753 - in short, for datagram sockets you might get more events than you would expect.

提交回复
热议问题