libevent::事件::定时器2
2024-09-01 09:12:47
#define evtimer_new(b, cb, arg) event_new((b), -1, 0, (cb), (arg))
#include <cstdio>
#include <errno.h>
#include <sys/types.h>
#include <event.h>
#include <event2/event.h>
#include <event2/event_struct.h>
#include <event2/event-config.h>
#include <event2/util.h> void do_timeout(evutil_socket_t fd, short event, void *arg)
{
printf("do timeout (time: %ld)!\n", time(NULL));
} void create_timeout_event(struct event_base *base)
{
struct event *ev;
struct timeval timeout;
//将事件和event_base绑定
ev = event_new(base, -1, EV_PERSIST, do_timeout, NULL);
if (ev) {
timeout.tv_sec = 5;
timeout.tv_usec = 0;
event_add(ev, &timeout);
}
} int
main(int argc, char **argv)
{
struct event_base *base; base = event_base_new(); if (!base) {
printf("Error: Create an event base error!\n");
return -1;
} create_timeout_event(base);
event_base_dispatch(base); return (0);
}
最新文章
- SignalR入门之Hub
- Authcode()
- Sublime Text 3 个人开发习惯
- 利用Aspose.Pdf将扫描的电子书修改为适合在kindle上查看
- 数据结构算法C语言实现(八)--- 3.2栈的应用举例:迷宫求解与表达式求值
- mysql 关于日期时间的字段类型
- VS在Release模式下,难道还可以Debug?
- C/C++常用算法【C语言顺序查找(随机数)】【1】
- android 休眠唤醒机制分析(一) — wake_lock
- Vim 命令 【转】
- 201521123024《Java程序设计》第7周学习总结
- 后台模拟请求 HttpHelper 序列化 MD5 时间戳
- Java学习笔记(四)——好记性不如烂键盘(答答租车)
- [转帖]关于网络编程中MTU、TCP、UDP优化配置的一些总结
- oftype 指的是集合的类型
- Atitit &#160;技术经理职责与流程表总结
- LoadRunner录制脚本-基础
- js判断checkbox是否选中
- Java-JUC(六):创建线程的4种方式
- 五毛党可能要失业了,因为AI水军来了
热门文章
- ActiveMQ JMX使用
- jvm对象内存分配
- 三段式有限状态机Verilog代码
- Spring 梳理-Spring配置文件 -<;context:annotation-config/>;和<;context:component-scan base-package=";";/>;和<;mvc:annotation-driven />; 的区别
- Android测试环境配置
- thymeleaf 语法
- iSCSI 网关管理 - Storage6
- Python爬虫(二):Requests库
- 夯实Java基础系列17:一文搞懂Java多线程使用方式、实现原理以及常见面试题
- 文本数据IO操作--字符流