首先它是通过指向struct event_list的指针的指针来实现的
在struct event_base结构中体现如下:
/* active event management */
struct event_list **activequeues;
int nactivequeues;
其中nactivequeues为活动事件队列链表数,对应的优先级有0到nactivequeues-1级
默认是1
相应的初始化部分在如下代码:
int
event_base_priority_init(struct event_base *base, int npriorities)
{
int i;
if (base->event_count_active)
return (-1);
if (base->nactivequeues && npriorities != base->nactivequeues) {
for (i = 0; i < base->nactivequeues; ++i) {
free(base->activequeues[i]);
}
free(base->activequeues);
}
/* Allocate our priority queues */
base->nactivequeues = npriorities;
base->activequeues = (struct event_list **)calloc(base->nactivequeues,
npriorities * sizeof(struct event_list *));
if (base->activequeues == NULL)
event_err(1, "%s: calloc", __func__);
for (i = 0; i < base->nactivequeues; ++i) {
base->activequeues[i] = malloc(sizeof(struct event_list));
if (base->activequeues[i] == NULL)
event_err(1, "%s: malloc", __func__);
TAILQ_INIT(base->activequeues[i]);
}
return (0);
}
具体体现在活动事件处理函数中如下:
static void
event_process_active(struct event_base *base)
{
struct event *ev;
struct event_list *activeq = NULL;
int i;
short ncalls;
for (i = 0; i < base->nactivequeues; ++i) {
if (TAILQ_FIRST(base->activequeues[i]) != NULL) {
activeq = base->activequeues[i];
break;
}
}
assert(activeq != NULL);
for (ev = TAILQ_FIRST(activeq); ev; ev = TAILQ_FIRST(activeq)) {
if (ev->ev_events & EV_PERSIST)
event_queue_remove(base, ev, EVLIST_ACTIVE);
else
event_del(ev);
/* Allows deletes to work */
ncalls = ev->ev_ncalls;
ev->ev_pncalls = &ncalls;
while (ncalls) {
ncalls--;
ev->ev_ncalls = ncalls;
(*ev->ev_callback)((int)ev->ev_fd, ev->ev_res, ev->ev_arg);
if (event_gotsig || base->event_break)
return;
}
}
}
优先级值越小越早处理
分享到:
相关推荐
1.libevent库编译工具为vs2019 2.环境为qt5.15.2 3.设置本地的目录,开启线程即可实现http服务器文件下载。
这是一个使用libevent实现的web服务器,客户端采用CInternetSession来实现的,是一个完整的可用的例子,项目采用cmake来管理。提供给大家参考,有问题可以邮件给buptxu@qq.com,多谢。
全部C代码,linux下的线程池和libevent配合实现的高并发tcp服务器,tcp通讯采用分帧的方式发包,帧包含帧头和数据部分,使用libevent的bufferevent方式来实现的帧提取,可直接使用GCC来编译。还配套有一个C#写的...
libevent2.1.7在Linux安装过程
Libevent 服务端 客户端 代码实现 实现大并发 -------
Libevent 基于事件的
LibEvent定时器事件开发实例
速度:libevent 尝试使用每个平台上最高速的非阻塞 IO 实现,并且不引入太多的额外开 销。 可扩展性:libevent 被设计为程序即使需要上万个活动套接字的时候也可以良好工作。 方便:无论何时,最自然的使用 ...
windows平台下对于服务器高并发的网络模型选型中,使用libevent是个不错的选择。 本文的背景基于:国内博客对于libevent大多介绍Linux实现,大多是C语言的实现,Windows平台下C++相对较少或者较旧。 本文针对...
Libevent 编程中文帮助文档 版本:V1.0 日期:2016-11-15 作者:周勇 本文 档是 2009-2012 年由 Nick-Mathewson 基于 Attribution-Noncommercial-Share Alike 许可协议 3.0 创建,未来版本将会使用约束性更低的...
【最新】C++ 使用libEvent实现http的post, get功能,【最新】C++ 使用libEvent实现http的post, get功能
在linux下C语言通过libevent操作串口,通过libevent来实现回调读取串口数据。全部C代码,可直接编译和测试。
libevent参考手册(中文版),包含libevent的设计说明、原理描述,模块介绍和接口说明。
libevent在MFC上的实现, 花了1周的时间研究各种TCP模型, 包括LINUX和WINDOWS平台等, 包括C&C++, C#, JAVA, GOLANG, ERLANG等居于IOCP, SELECT, POLL, EPOLL, KQUEUE, BIO, NIO, AIO, 并发语言等实现的同步或异步...
Libevent 是一个用C语言编写的、轻量级的开源高性能事件通知库,主要有以下几个亮点:事件驱动( ...注册事件优先级。 Libevent 已经被广泛的应用,作为底层的网络库;比如 memcached、 Vomit、 Nylon、 Netchat等等。
C语言实现的开源网络库 LibEvent2.0.22的帮助文档中文翻译版本 日期 作者 备注 2016-11-15 周勇 Libevent编程中文帮助文档V1.0
Libevent 中文手册
1.基于libevent实现relay服务器。2.基于libevent实现relay客户端