libevent 定时器

来源:互联网 发布:数据库收银员表怎么建 编辑:程序博客网 时间:2024/05/16 15:10
<span style="font-size:18px;">#include<iostream>#include<stdio.h>#include<string.h>#include<stdlib.h>#include<sys/socket.h>#include<sys/types.h>#include<netinet/in.h>#include<event.h>struct event ev;struct timeval tv;void time_cb(int fd,short event,void *argc){        printf("timer wakeup\n");        event_add(&ev,&tv);}int  main(){        struct event_base *base =(struct event_base*)event_init();        tv.tv_sec = 10;        tv.tv_usec = 0;        evtimer_set(&ev,time_cb,NULL);        event_add(&ev,&tv);        event_base_dispatch(base);        return 0;}</span>


编译:g++ -g test.cpp -o test -levent


如果出现错误如下:

./test: error while loading shared libraries: libevent-1.2.so.1: cannot open shared object file: No such file or directory


解决方案:

先执行命令:ldconfig

然后执行:./test


参考:http://blog.csdn.net/sahusoft/article/details/7388617



0 0
原创粉丝点击