libevent timer定时器
来源:互联网 发布:什么是淘宝店铺首页 编辑:程序博客网 时间:2024/06/05 04:47
每隔一秒循环执行回调函数#include <iostream>#include <event2/event.h>struct cb_arg{ struct event *ev; struct timeval tv;};void timeout_cb(int fd, short event, void *params){ puts("111"); struct cb_arg *arg = (struct cb_arg*)params; struct event *ev = arg->ev; struct timeval tv = arg->tv; evtimer_add(ev, &tv);}int main(){ struct event_base *base = event_base_new(); struct event *timeout = NULL; struct timeval tv = {1, 0}; struct cb_arg arg; timeout = evtimer_new(base, timeout_cb, &arg); arg.ev = timeout; arg.tv = tv; evtimer_add(timeout, &tv); event_base_dispatch(base); evtimer_del(timeout); return 0;}
或者:
让事件变为持久的,这样在执行完回调后事件处于未决状态。
事件的几个状态:
1.new -> 已初始化状态
2.add -> 未决状态
3.有信号 -> 激活状态,这时候会触发回调
4.回调执行之后 -> 非未决状态,如果new的时候有EV_PERSIST标记此时是未决状态。
#include <iostream>#include <event2/event.h>void timeout_cb(int fd, short event, void *params){ puts("111");}int main(){ struct event_base *base = event_base_new(); struct event *timeout = NULL; struct timeval tv = {1, 0}; timeout = event_new(base, -1, EV_PERSIST, timeout_cb, NULL); evtimer_add(timeout, &tv); event_base_dispatch(base); evtimer_del(timeout); return 0;}
- libevent timer定时器
- Libevent 编程- 定时器事件(timer event)
- libevent源码学习(四)定时器Timer
- libevent timer
- libevent 定时器
- libevent - 定时器
- Timer 定时器
- TIMER 定时器
- timer 定时器
- timer 定时器
- timer定时器
- 定时器 Timer
- 定时器Timer
- timer定时器
- Timer 定时器
- Timer定时器
- 定时器TIMER
- 定时器Timer
- Python中的html.parser
- cocos2d-x 显示遇到白框
- 线程函数的优先级
- 顺序栈的建立
- Java操作XML文件大合集(增删改查)
- libevent timer定时器
- snmptrap、snmpinform和snmptrapd的详细介绍及其用法
- 再看ADO.NET
- 一口一口吃掉Struts(九)——国际化问题(2)
- linux下作业控制
- opencv-Mat补充
- Hdu 1039 - Easier Done Than Said?
- JDBC连接MySQL数据库
- 低电平中断和下降沿中断的区别