linux 下第一个Libevent代码学习
1 #include <event.h> 2 struct event ev; 3 struct timeval tv; 4 5 void time_cb(int fd, short event, void* argc) 6 { 7 printf("timer wakeup\n"); 8 event_add(&ev, &tv); 9 } 10 11 int main() 12 { 13 struct event_base*base = event_init(); 14 tv.tv_sec = 10; 15 tv.tv_usec = 0; 16 evtimer_set(&ev, time_cb, NULL); 17 event_add(&ev, &tv); 18 event_base_dispatch(base); 19 return 0; 20 }
注意编译的时候gcc -o * *.c -levent
需要加上-levent链接库