码迷,mamicode.com
首页 > 其他好文 > 详细

[libevent.manual] libevent基础知识

时间:2015-08-31 19:18:54      阅读:147      评论:0      收藏:0      [点我收藏+]

标签:

在线手册


• 官方网站:http://libevent.org/

• 官方手册:http://www.wangafu.net/~nickm/libevent-book/

• 官方下载:http://sourceforge.net/projects/levent/files/libevent/

• 在线手册:http://www.monkey.org/~provos/libevent/doxygen-2.0.1/index.html

• 百度百科:http://baike.baidu.com/link?url=cAxwbS2-agM4LSIYDQS1tAFxYrkLjju-6gcARq2iG6keI6MP6_WZpPCvZWKgAJbFnHNL40u5yYz6qhb71RQg4K

• 维基百科:https://en.wikipedia.org/wiki/Libevent

编译和安装(Linux : CentOS 7.0)


? 下载并解压libevent压缩包

? chmod 777 ./configure

? ./configure -prefix=/usr

? make

? make install

? 检测libevent是否安装成功:ls -al /usr/lib | grep libevent

 测试示例


1. 获取版本信息

// test.cpp
#include
<stdio.h> #include <event.h> int main(int argc, char ** argv) { const char *cszVersion = event_get_version(); printf("Version : %s\n", cszVersion); return 0; }

g++ -o test.o -c test.cpp

g++ -levent -o test test.o

2. 简单触发器

// test.cpp
#include
<stdio.h> #include <event.h> #include <iostream> void OnTime(evutil_socket_t fd, short event, void *arg) { std::cout << "OnTime Triggers!" << std::endl; struct timeval tv; tv.tv_sec = 1; tv.tv_usec = 0; event_add((struct event*)arg, &tv); } int main(int argc, char ** argv) { struct timeval tv; struct event evTime; tv.tv_sec = 1; tv.tv_usec = 0; event_init(); evtimer_set(&evTime, OnTime, &evTime); event_add(&evTime, &tv); event_dispatch(); return 0; }

g++ -o test.o -c test.cpp

g++ -levent -o test test.o

[libevent.manual] libevent基础知识

标签:

原文地址:http://www.cnblogs.com/heartchord/p/4766791.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!