使用libevent库作为例子 下载 & 编译 & 安装libevent $ git clone https://github.com.cnpmjs.org/libevent/libevent.git $ cd libevent && mkdir build && cd build $ cmake .. $ make libevent实现的定时器 // main.cpp #include "event.h" struct event ev; struct timeval tv; void time_cb(evutil_socket_t fd, short event, void *argc) { printf("timer wakeup\n"); event_add(&ev, &tv); // reschedule timer } int main() { struct event_base *base = event_base_new(); tv.tv_sec = 2;……
阅读全文