轻量级网络库libevent概况
Libevent is a library for writing fast portable nonblocking IO.
libevent是一个为编写快速可移植的非阻塞IO程序而设计的。
libevent组件
libevent包括了以下组件:
1. evutil
Generic functionality to abstract out the differences between different platforms' networking implementations.
用于抽象不同平台网络实现差异的通用功能。
2. event & event_base
This is the heart of Libevent. It provides an abstract API to the various platform-specific, event-based nonblocking IO backends. It can let you know when sockets are ready to read or write, do basic timeout functionality, and detect OS signals.
libevent的核心,为各种平台特定的、基于事件的非阻塞IO后端(backend,即epoll、select等)提供抽象API。它们能够通知应用套接字是否已经准备好读或者写,并具备处理超时的基本功能,且能够检测操作系统信号。
3. bufferevent
These functions provide a more convenient wrapper around Libevent’s event-based core. They let your application request buffered reads and writes, and rather than informing you when sockets are ready to do, they let you know when IO has actually occurred.
(The bufferevent interface also has multiple backends, so that it can take advantage of systems that provide faster ways to do nonblocking IO, such as the Windows IOCP API.)
bufferevent中的函数为libevent基于事件的核心提供了使用更方便的封装。它们使得我们的应用可以请求已经缓冲的读写操作。另外,它们让我们知道IO读写已经真正发生,而不是当套接字准备好读或写就通知我们。
(bufferevent接口有多个后端,它可以采用系统提供的更快的非阻塞IO后端,例如Windows中的IOCP API。)
4. evbuffer
This module implements the buffers underlying bufferevents, and provides functions for efficient and/or convenient access.
在bufferevent层之下实现了缓冲功能,并且提供了方便有效的访问函数。
5. evhttp
A simple HTTP client/server implementation.
一个简单的HTTP客户端/服务器实现。
6. evdns
A simple DNS client/server implementation.
一个简单的DNS客户端/服务器实现。
7. evrpc
A simple RPC implementation.
一个简单的RPC实现。
libevent头文件
All current public Libevent headers are installed under the event2 directory. Headers fall into three broad classes:
libevent公用头文件都安装在event2目录中。头文件可以大概分为三类:
1. API headers
An API header is one that defines current public interfaces to Libevent. These headers have no special suffix.
定义libevent公用接口。这类头文件没有特定后缀。
2. Compatibility headers
A compatibility header includes definitions for deprecated functions. You shouldn’t include it unless you’re porting a program from an older version of Libevent.
为已废弃的函数提供兼容。不应该使用这类头文件,除飞要移植使用较老版本libevent的程序。
3. Structure headers
These headers define structures with relatively volatile layouts. Some of these are exposed in case you need fast access to structure component; some are exposed for historical reasons. Relying on any of the structures in headers directly can break your program’s binary compatibility with other versions of Libevent, sometimes in hard-to-debug ways. These headers have the suffix "_struct.h"
这类头文件以相对不稳定的布局定义各种结构体。这些结构体中的一些是为了提供快速访问而暴露;一些是因为历史原因而暴露。直接依赖这类头文件中的任何结构体都会破坏程序对其他版本libevent的二进制兼容性。这些问题有时候是以非常难以调试的方式出现。这类头文件具有后缀“_struct.h”。
源代码组织结构
libevent的源代码虽然都在一层文件夹下面,但是其代码分类还是相当清晰的,主要可分为头文件、内部使用的头文件、辅助功能函数、日志、libevent框架、对系统I/O多路复用机制的封装、信号管理、定时事件管理、缓冲区管理、基本数据结构和基于libevent的两个实用库等几个部分,有些部分可能就是一个源文件。
源代码中的test部分就不在我们关注的范畴了。
1)头文件
主要就是event.h:事件宏定义、接口函数声明,主要结构体event的声明;
2)内部头文件
xxx-internal.h:内部数据结构和函数,对外不可见,以达到信息隐藏的目的;
3)libevent框架
event.c:event整体框架的代码实现;
4)对系统I/O多路复用机制的封装
epoll.c:对epoll的封装;
select.c:对select的封装;
devpoll.c:对dev/poll的封装;
kqueue.c:对kqueue的封装;
5)定时事件管理
min-heap.h:其实就是一个以时间作为key的小根堆结构;
6)信号管理
signal.c:对信号事件的处理;
7)辅助功能函数
evutil.h 和evutil.c:一些辅助功能函数,包括创建socket pair和一些时间操作函数:加、减和比较等。
8)日志
log.h和log.c:log日志函数
9)缓冲区管理
evbuffer.c和buffer.c:libevent对缓冲区的封装;
10)基本数据结构
compat/sys下的两个源文件:queue.h是libevent基本数据结构的实现,包括链表,双向链表,队列等;_libevent_time.h:一些用于时间操作的结构体定义、函数和宏定义;
11)实用网络库
http和evdns:是基于libevent实现的http服务器和异步dns查询库;
libevent编译后的库
1. event_core
All core event and buffer functionality. This library contains all the event_base, evbuffer, bufferevent, and utility functions.
该库包含了所有核心的事件和缓冲功能,包含了所有的event_base、evbuffer、bufferevent和辅助(utility)函数。
2. event_extra
This library defines protocol-specific functionality that you may or may not want for your application, including HTTP, DNS, and RPC.
该库定义了程序可能需要,也可能不需要的协议特定功能,包括HTTP、DNS和RPC。
3. event
This library exists for historical reasons; it contains the contents of both libevent_core and libevent_extra. You shouldn’t use it; it may go away in a future version of Libevent.
这个库因为历史原因而存在,它包含了libevent_core和libevent_extra的内容。我们不应该使用这个库。未来版本的libevent可能去掉这个库。
某些平台上可能安装下列库:
4. event_pthreads
This library adds threading and locking implementations based on the pthreads portable threading library. It is separated from libevent_core so that you don’t need to link against pthreads to use Libevent unless you are actually using Libevent in a multithreaded way.
该库添加了基于pthread可移植线程库的线程和锁实现。它独立于libevent_core,这样程序使用libevent时就不需要链接到pthread,除非是以多线程方式使用libevent。
5. event_openssl
This library provides support for encrypted communications using bufferevents and the OpenSSL library. It is separated from libevent_core so that you don’t need to link against OpenSSL to use Libevent unless you are actually using encrypted connections.
该库为使用bufferevent和OpenSSL的加密通信提供支持。它独立于libevent_core,这样程序使用libevent时就不需要链接到OpenSSL,除非是进行加密通信。
新老版本比较
libevent 2.0以更合理的、不易出错的方式修正了API。如果可能,编写新程序时应该使用libevent 2.0。但是有时候可能需要使用较老的API,例如在升级已存的应用时,或者支持因为某些原因不能安装2.0或者更新版本libevent的环境时。较老版本的libevent头文件较少,也不安装在event2目录中。

在2.0以及以后版本的libevent中,老的头文件仍然会作为新头文件的封装而存在。
其他关于使用较老版本的提示:
- V1.4版之前只有一个库libevent,它包含现在分散到libevent_core和libevent_extra中的所有功能。
- V2.0版之前不支持锁:只有确定不同时在多个线程中使用同一个结构体时,libevent才是线程安全的。
参考资料
The Libevent Reference Manual: Preliminaries
轻量级网络库libevent概况的更多相关文章
- 轻量级网络库libevent初探
本文是关于libevent库第一篇博文,主要由例子来说明如何利用该库.后续博文再深入研究该库原理. libevent库简介 就如libevent官网上所写的“libevent - an event n ...
- [原]网络库libevent在Visual Studio中的使用方法
libevent是一个事件触发的网络库,适用于windows.linux.bsd等多种平台,内部使用select.epoll.kqueue等系统调用管理事件机制.著名分布式缓存软件memcached也 ...
- 网络库libevent、libev、libuv对比
Libevent.libev.libuv三个网络库,都是c语言实现的异步事件库Asynchronousevent library). 异步事件库本质上是提供异步事件通知(Asynchronous Ev ...
- [开源] gnet: 一个轻量级且高性能的 Golang 网络库
Github 主页 https://github.com/panjf2000/gnet 欢迎大家围观~~,目前还在持续更新,感兴趣的话可以 star 一下暗中观察哦. 简介 gnet 是一个基于 Ev ...
- Mudo C++网络库第十一章学习笔记
反思C++面向对象与虚函数 C++语言学习可以看<C++ Primer>这本书; 在C++中进行面向对象编程会遇到其他语言中不存在的问题, 其本质原因是C++ class是值语义, 而非对 ...
- libevent网络库
1.概述 libevent是一个C语言编写的.轻量级开源高性能事件通知库.作为底层网络库,已经被广泛应用(如:memcached.Vomit.Nylon.Netchat等).主要有以下几个亮点: 事件 ...
- 开源网络库ACE、Boost的ASIO、libevent、libev、ZeroMQ
开源C/C++网络库:ACE C++语言 跨平台Boost的ASIO C++语言 跨平台libevent C语言 主要支持linux,新版增加了对windows的IOC ...
- Windows下libevent C++封装类实现(为什么要使用封装好的网络库?)
题记 windows平台下对于服务器高并发的网络模型选型中,使用libevent是个不错的选择. 本文的背景基于:国内博客对于libevent大多介绍linux实现,大多是c语言的实现,Windows ...
- 以libevent网络库为引:网络通信和多线程
1. windows下编译及使用libevent http://www.cnblogs.com/luxiaoxun/p/3603399.html 2. <<libevent学习资料&g ...
随机推荐
- iOS 应用提交到iTunes Connect,显示"正在处理"后消失不见
打包上传iTunes Connect 成功后,进入iTunes Connect 会看到如下的构建信息: 可是,过一会再刷新该页面,构建的版本就消失了. 出现如上所述的情况,主要目前已知的有两种原因: ...
- Xcode8之后,苹果列出了最新App被拒十大原因
开发者在开发应用程序之前,熟悉苹果审核应用的技术.内容以及设计准则是非常重要的,可以大大降低应用审核被拒的可能性. 最近,苹果通过一个专门的页面给出了截止2016年10月10日应用提交审核被拒的十大原 ...
- leetcode 37. Sudoku Solver 36. Valid Sudoku 数独问题
三星机试也考了类似的题目,只不过是要针对给出的数独修改其中三个错误数字,总过10个测试用例只过了3个与世界500强无缘了 36. Valid Sudoku Determine if a Sudoku ...
- Android 自定义View-android学习之旅(十四)
自定义View的步骤 当andoid提供的系统组件不满足要求时候,完全可以集成View来派生自定义组件. 首定定义一个继承View的子类,然后重写他一个或几个方法. 重写的方法介绍 构造器:这是定制V ...
- 安装解压版本的MySQL,安装过程中的常见命令,检查windows系统错误日志的方式来检查MySQL启动错误,关于Fatal error: Can't open and lock privilege
以端口 port = 3306 # 设置mysql的安装目录 basedir=D://Installed//mysql-5.6.26-winx64//mysql-5.6.26-winx64 # ...
- XCode5添加新建类模板(Cocos2dx Template Class for Scene or Layer)
猴子原创,欢迎转载.转载请注明: 转载自Cocos2D开发网–Cocos2Dev.com,谢谢! 原文地址: http://www.cocos2dev.com/?p=505 因为常用cocos2dx开 ...
- MySQL设计软件登录模块
学了一段时间的Java了,思量着做一点简单的小模块的东西吧,于是就有了下面的这个简单的小案例. 大致实现的功能就是注册于登录还有就是用到了一点,分层思想.仅此而已,所以非常的适合新手围观. 建立好数据 ...
- Ubuntu 15.10下Qt5的安装实战
写照篇博客的目的就是因为最近要使用Qt,但是由于本人的系统是Ubuntu的,而网上大部分的讲解全是基于Windows的,所以就花费一些时间总结了一下我的安装过程,当然也是也为了能帮助到更多的博友. 第 ...
- 学生信息管理小系统(以XML为存储方式)
为了更好地应用XML,就写了这个小项目. 下面是我的项目的目录结构 项目思路 dao是Date Access Object 数据访问层,主要是负责操作数据 domain是实体层,类似于bean层,放置 ...
- 并发编程(三): 使用C++11实现无锁stack(lock-free stack)
前几篇文章,我们讨论了如何使用mutex保护数据及使用使用condition variable在多线程中进行同步.然而,使用mutex将会导致一下问题: 等待互斥锁会消耗宝贵的时间 - 有时候是很多时 ...