什么是epoll的边缘的目的触发选项? [英] what is the purpose of epoll's edge triggered option?

查看:239
本文介绍了什么是epoll的边缘的目的触发选项?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

从epoll的的手册页:

From epoll's man page:

epoll is a variant of poll(2) that can be used either as an edge-triggered
or a level-triggered interface

一个。当需要使用边沿触发选项?该手册页提供了使用它的例子,但我不明白为什么有必要的示例。

When would one use the edge triggered option? The man page gives an example that uses it, but I don't see why it is necessary in the example.

推荐答案

当一个FD变成读取或写入准备好了,你不一定要读(或写)的所有数据立即生效。

When an FD becomes read or write ready, you might not necessarily want to read (or write) all the data immediately.

作为FD依然准备好了,而边沿触发不会再打扰你你,直到下一次电平触发的epoll将继续唠叨你只要一个 EAGAIN (所以它更复杂,code左右,但可以根据你需要做什么更有效)。

Level-triggered epoll will keep nagging you as long as the FD remains ready, whereas edge-triggered won't bother you again until the next time you get an EAGAIN (so it's more complicated to code around, but can be more efficient depending on what you need to do).

说你从资源到FD写作。如果注册为FD变得写就绪兴趣,电平触发,你会得到不断的通报称,FD,仍然可以进行写操作。如果资源尚不可用,这是一个唤醒的浪费,因为你不能写任何更多的反正。

Say you're writing from a resource to an FD. If you register your interest for that FD becoming write ready as level-triggered, you'll get constant notification that the FD is still ready for writing. If the resource isn't yet available, that's a waste of a wake-up, because you can't write any more anyway.

如果您要添加为边沿触发,而不是,你会得到通知的FD是准备写一次,那么当其他的资源准备好你写的尽你所能。然后,如果写(2)收益 EAGAIN ,你停止写作,等待下一个通告。

If you were to add it as edge-triggered instead, you'd get notification that the FD was write ready once, then when the other resource becomes ready you write as much as you can. Then if write(2) returns EAGAIN, you stop writing and wait for the next notification.

这同样适用于阅读,因为你可能不希望把所有数据到用户空间,你就可以做任何你想用它做前(因而具有缓冲它,等等等等)。随着边沿触发epoll的你得到告诉当它准备读,然后就可以记住,做实际读数到什么时候。

The same applies for reading, because you might not want to pull all the data into user-space before you're ready to do whatever you want to do with it (thus having to buffer it, etc etc). With edge-triggered epoll you get told when it's ready to read, and then can remember that and do the actual reading "as and when".

这篇关于什么是epoll的边缘的目的触发选项?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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