一次性*级别*触发的epoll():EPOLLONESHOT是否意味着EPOLLET? [英] One-shot *level*-triggered epoll(): Does EPOLLONESHOT imply EPOLLET?

查看:346
本文介绍了一次性*级别*触发的epoll():EPOLLONESHOT是否意味着EPOLLET?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以在单次级别 - 触发模式下使用 epoll

我找不到我搜索时的任何信息;似乎每个人都使用边缘触发模式。

Is it possible to use epoll in one-shot level-triggered mode?
I couldn't find any information on it when I searched; it seems everyone uses edge-triggered mode.

推荐答案

EPOLLONESHOT 如果选择了flag并且你已经为一个套接字拉了一个事件,那么套接字就不会像许多人想的那样从epoll中删除,但是它的事件被禁用了。您可以使用 epoll_ctl / EPOLL_CTL_MOD 再次启用它们。

When the EPOLLONESHOT flag is selected and you have pulled an event for a socket, then the socket won't get removed from epoll as many think but its events get disabled. You can enable them again using epoll_ctl / EPOLL_CTL_MOD.

EPOLLONESHOT 行为很方便的示例是当您从套接字读取可用数据到缓冲区时。该缓冲区将被独立清空,但在它不为空之前,您必须禁用套接字事件,即使套接字有其他数据。然后在使用和清空缓冲区后,您可以重新启用套接字。

An example case when the EPOLLONESHOT behavior comes handy is when you've read the available data from a socket into a buffer. That buffer would be emptied independently, but until it isn't empty, you have to disable the socket events, even if the socket has additional data. Then after the buffer got used and emptied, you can re-enable the socket.

边缘触发和水平触发的一次性行为之间的差异仅在你重新启用套接字。例如:

The difference between the edge- and level-triggered "one shot" behaviors come only when you re-enable the socket. An example:


  1. 套接字接收7K数据(现在它存储在内核缓冲区中)

  2. 等待输入事件,然后由于EPOLLONESHOT而禁用套接字事件。

  3. 您将4K读入应用程序级缓冲区。

  4. 稍后使用和清空应用程序缓冲区。使用 epoll_ctl重新启用套接字 / EPOLL_CTL_MOD

  1. The socket receives 7K data (for now it's stored in a kernel buffer)
  2. You wait for an input event, then the socket events get disabled due to the EPOLLONESHOT.
  3. You read 4K into an application level buffer.
  4. Later the application buffer gets used and emptied. You re-enable the socket with epoll_ctl / EPOLL_CTL_MOD.

等级触发的EPOLLONESHOT:


  1. 自内核缓冲区中仍然存在3K数据,事件再次被触发。

边缘触发的EPOLLONESHOT:


  1. 它不会再次触发可用数据的事件。你必须通过阅读来测试它,然后等待 EAGAIN / EWOULDBLOCK

  1. It won't trigger an event again for the available data. You must test it by reading, and waiting for EAGAIN / EWOULDBLOCK.

这篇关于一次性*级别*触发的epoll():EPOLLONESHOT是否意味着EPOLLET?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆