Linux下编译libevent的指导可以参考《4、《Libevent中文帮助文档》学习笔记4:Linux下编译libevent》,完成编译、安装,生成so库后,其他程序即可依赖libevent的so库,使用libevent的功能。
由于没有通过prefix指定安装路径,因此库文件默认安装在/usr/local/lib下,头文件在/usr/local/include下,如下所示:
如图可以看出,libevent的so库存在软链接现象。
集成libevent的源码如下:
/*For sockaddr_in*/
#include <netinet/in.h>
/*For socket functions*/
#include <sys/socket.h>
/*For fcntl*/
#include <fcntl.h>
#include <event2/event.h>
#include <assert.h>
#include <unistd.h>
#include <string.h>
#include <stdlib.h>
#include <stdio.h>
#include <errno.h>
#define MAX_LINE 16384
void do_read(evutil_socket_t fd, short events, void*arg);
void do_write(evutil_socket_t fd, short events, void*arg);
char rot13_char(char c)
{
/* We don’t want to use isalpha here; setting the locale change which characters are considered alphabetical.*/
if ((c >= 'a' && c <= 'm') || (c >= 'A' && c <= 'M'))
{
return c + 13;
}
else if ((c >= 'n' && c <= 'z') || (c >= 'N' && c <= 'Z'))
{
return c - 13;
}
else
{
return c;
}
}
struct fd_state
{
char buffer[MAX_LINE];
size_t buffer_used;
size_t n_written;
size_t write_upto;