博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
关于libevent的事件持续化EV_READ | EV_PERSIST
阅读量:6934 次
发布时间:2019-06-27

本文共 1287 字,大约阅读时间需要 4 分钟。

关于事件的可持续化

从网上找的内容,可以看下github中的一本book,点击下面的连接就ok了。

引用其中的话

About Event Persistence

By default, whenever a pending event becomes active (because its fd is ready to read or write, or because its timeout expires), it becomes non-pending right before its callback is executed. Thus, if you want to make the event pending again, you can call event_add() on it again from inside the callback function.
If the EV_PERSIST flag is set on an event, however, the event is persistent. This means that event remains pending even when its callback is activated. If you want to make it non-pending from within its callback, you can call event_del() on it.
The timeout on a persistent event resets whenever the event’s callback runs. Thus, if you have an event with flags EV_READ|EV_PERSIST and a timeout of five seconds, the event will become active:

  • Whenever the socket is ready for reading.

  • Whenever five seconds have passed since the event last became active.

翻译

可能有不对的地方,欢迎指正

关于事件的持续化

默认情况下,任何时候一个挂起的事件被激活(因为他的fd准备好了读或者写,或者因为他的超时过期了),它会在回调函数执行之前变为非挂起。如果你想让事件再次挂起,你需要在回调函数内部调用event_add()
如果一个事件被设置了EV_PERSIST,那么这个事件就是持续化的,意思就是这个事件会保持挂起状态,即使回调函数被执行。如果你想让它变为非挂起状态,可以在回调函数中调用event_del()

任何时候事件的回调函数触发都会重置持续化事件中的超时状态。因此,如果的事件有EV_READ/EV_PERSIST并且设置了5秒超时,那么有两种情况会触发这个事件:

  1. 当socket可以进行读取的时候

  2. 当5s超时到期的时候

给个例子:

转载地址:http://hrvjl.baihongyu.com/

你可能感兴趣的文章
七.获取真实的DOM节点
查看>>
SQL viewId 比较好看的 Id
查看>>
use include to read a file
查看>>
虚拟属性
查看>>
利用background-attachment做视差滚动效果
查看>>
许小年:宁可踏空,不可断粮<转>
查看>>
第三篇 第八章泡沫灭火系统(二)
查看>>
MYSQL explain 详解
查看>>
移动web-bootstrap
查看>>
洛谷1108 低价购买
查看>>
LeetCode Next Permutation
查看>>
[转载] 杜拉拉升职记——12 话不投机
查看>>
HTTP中的Session和Cookie浅析
查看>>
Java Note
查看>>
台北出差备忘
查看>>
13. Roman to Integer
查看>>
Treap 实现名次树
查看>>
SSD 单发多框检测
查看>>
Layout 不可思议(二)—— 两侧定宽的三列布局
查看>>
Node.js学习笔记(八) --- Node.js的路由模块封装
查看>>