在线手册
• 官方网站: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
• 维基百科: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
时间: 2024-10-19 11:40:09