libev是个高性能跨平台的事件驱动框架,支持io事件,超时事件,子进程状态改变通知,信号通知,文件状态改变通知,还能用来实现wait/notify机制。libev对每种监听事件都用一个ev_type类型的数据结构表示,如ev_io, ev_timer, ev_child, ev_async分别用来表示文件监听器, timeout监听器, 子进程状态监听器, 同步事件监听器.
ev_timer简单例子:
#include <ev++.h>
#include <unistd.h>
void SecondTimeout(EV_P_ ev_timer *w, int revents)
{
;//秒回调函数
}
void MinuteTimeout(EV_P_ ev_timer *w, int revents)
{
;//分钟回调函数
}
int main(int argc,const char *argv[])
{
ev::default_loop loop;
ev_timer second_watcher;
ev_timer_init(&second_watcher, SecondTimeout, 0., 1);
ev_timer_start(loop, &second_watcher);
ev_timer minute_watcher;
ev_timer_init(&minute_watcher, MinuteTimeout, 0., 60);
ev_timer_start(loop, &minute_watcher);
loop.run(0);
return 0;
}