用libevent的定时器

时间:2022-02-15 00:27:18
 1 #include <iostream>
2 using namespace std;
3
4 #include <event.h>
5
6 static char data[10] = "abc";
7 struct event ev;
8 struct timeval tv;
9 void Fun(int fd, short n, void * a)
10 {
11 evtimer_del(&ev);
12 evtimer_add(&ev, &tv);
13 cout << (char *)a << endl;
14 }
15
16 int main()
17 {
18 event_init();
19 evtimer_set(&ev, Fun, data);
20 tv.tv_sec = 1;
21 tv.tv_usec = 0;
22 evtimer_add(&ev, &tv);
23 event_dispatch();
24 return 0;
25 }