当前位置:网站首页>高性能IO框架库libevent(三):libevent框架函数概述
高性能IO框架库libevent(三):libevent框架函数概述
2022-07-17 11:36:00 【贪睡的蜗牛】
一、基础流程
1. 创建 event_base (乐高底座)
struct event_base *event_base_new(void);
struct event_base *base = event_base_new();
2. 创建 事件evnet
常规事件 event --> event_new();
bufferevent --> bufferevent_socket_new();
3、将事件 添加到 base上
int event_add(struct event *ev, const struct timeval *tv)
4. 循环监听事件满足
int event_base_dispatch(struct event_base *base);
event_base_dispatch(base);
5.释放 event_base
event_base_free(base);
二、函数
前面要创建一个底座
1、创建事件event:
这里指定了是哪个底座,也就是指定了在哪个底座上创建,更像一棵树创建了一个节点,但连接这个节点的线是虚的,在下面的函数哪里,才把线连上。
struct event *ev;
struct event *event_new(struct event_base *base,evutil_socket_t fd,short what,event_callback_fn cb; void *arg);
base: event_base_new()返回值。一个底座
fd: 绑定到 event 上的 文件描述符
what:对应的事件(r、w、e)
EV_READ 一次 读事件
EV_WRTIE 一次 写事件
EV_PERSIST 持续触发。 结合 event_base_dispatch 函数使用,生效。
cb:一旦事件满足监听条件,回调的函数。
typedef void (*event_callback_fn)(evutil_socket_t fd, short, void *)
arg: 回调的函数的参数。
返回值:成功创建的 event
2、添加事件到 event_base
这里并没有指明是哪个底座,由于这个事件本身已经指定了在哪里创建,因此也不需要指明是哪个。
int event_add(struct event *ev, const struct timeval *tv);
ev: event_new() 的返回值。
tv:NULL,这个是时间
3、从event_base上摘下事件【了解】
int event_del(struct event *ev);
ev: event_new() 的返回值。
4、销毁事件
int event_free(struct event *ev);
ev: event_new() 的返回值。
未决和非未决
非未决: 没有资格被处理
未决: 有资格被处理(但是事件还没有到达),但尚未被处理
激活态:事件到达,还没有处理
边栏推荐
- NPM usage
- 壳聚糖包裹PCN224纳米粒子|金属-有机骨架Fe-MIL-88NH2|镍基MOF材料(Ni-MOF/NF)
- Chapter 4 - consistency of first-order multi-agent systems - > consistency of continuous time systems with time delays
- Chapter 4 - first order multi-agent system consistency - > switching topology system consistency [program code]
- npm使用
- FAW Toyota Asia lion's first product refresh
- Chapter 4 - first order multi-agent system consistency - > pilot follow system consistency [program code]
- ES Restful操作
- Conversion between two-dimensional array and sparse array
- Learning summary of MySQL advanced Chapter 11: locate SQL methods with slow execution and analyze the use of query statement explain
猜你喜欢

壳聚糖包裹PCN224纳米粒子|金属-有机骨架Fe-MIL-88NH2|镍基MOF材料(Ni-MOF/NF)

565. Array nesting / Sword finger offer II 001 Integer division

Rhcsa day 1 7.11

Chapter 4 - first order multi-agent system consistency - > pilot follower system consistency

Packet knowledge

状态码的故事

Network Security Learning (Qianfeng network security notes) 1-- building virtual machines
![[C language] a brief introduction to the first C language program and data type](/img/59/9a90d94c4735d80402cda72ac6f2e6.png)
[C language] a brief introduction to the first C language program and data type

Run yolov3 on Huawei modelarts_ coco_ detection_ dynamic_ AIPP sample

【OpenCV 例程200篇】233. 区域特征之矩不变量
随机推荐
Online education knowledge payment website source code system + live broadcast + applet, installation tutorial
VIM details
fastadmin with 和 filed 合用导致field失效
FAW Toyota Asia lion's first product refresh
【C语言】浅涉第一个C语言程序及数据类型
PTA 1037 change at Hogwarts
Chapter 4 - first order multi-agent system consistency - > switching topology system consistency
Flink入门到实战-阶段四(时间和窗口图解)
Es restful operation
状态码的故事
Duilib implements tooltip custom mouse prompt window
半监督学习在恶意软件流量检测中的应用
SSH连接华为ModelArts notebook
CLWY权限管理(一)--- 项目搭建
Talking about the informatization planning of industrial enterprises
Among China's top ten national snacks, it is actually the first
二维数组与稀疏数组之间的转换
测试vector、list、set调用empty和size的耗时是否为常数
mof定制材料|NH(2)-UiO66/rGO氧化石墨烯纳米复合材料|负载亚甲基蓝的ZIF-90纳米粒子
【摸鱼神器】UI库秒变低代码工具——表单篇(二)子控件