轻量级网络库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 ...
随机推荐
- Dynamics CRM2011 导入解决方案报根组件插入错误的解决方法
今天在还原一个老版本的解决方案,在导入时报根组件插入问题"Cannot add a Root Component 38974590-9322-e311-b365-00155d810a00 o ...
- 在Ubuntu12.04上安装图形化配置与window共享的samba服务器
1.安装samba图形化配置界面 sudo apt-get install system-config-samba 2.启动图形化配置界面 3.添加用户,最好是要用adduser命令去添加 具体配置可 ...
- Android安全升级的7.0: Nougat
Tamic http://www.jianshu.com/users/3bbb1ddf4fd5/latest_articles 今年夏天以来,Google做了多种增强的安全性在Android的7.0N ...
- Python Tkinter小试
前两天看到一篇关于Python使用Tkinter 的博文,写的很好.就拿来研究了一下,改了改.现分享如下: 参考 代码 # coding:utf8 # python2.73 winxp ''''' 天 ...
- EBS销售订单挑库发放处理程序
来自:http://blog.csdn.net/cunxiyuan108/article/details/6014769 在EBS实施中,经常遇到从外部传进来一个被登记的销售订单,需要通过程序进行销售 ...
- Android App之间通过Intent交互
Android 最重要的功能之一是应用能够基于它要执行的"操作"向另一个应用发送用户. 例如,如果您的应用有您要在地图上显示的公司地址,您无需在显示地图的应用中构建 Activit ...
- python 如何优雅地退出子进程
python 如何优雅地退出子进程 主进程产生子进程,子进程进入永久循环模式.当主进程要求子进程退出时,如何能安全地退出子进程呢? 参考一些代码,我写了这个例子.运行之后,用kill pid试试.pi ...
- Linux目录架构详解
Linux和Windows操作系统的显著区别之一就是目录架构的不同.Linux操作系统的目录架构遵循文件系统层级结构标准.不知你是否使用ls命令浏览过Linux的根目录"/",亲爱 ...
- 指令汇B新闻客户端开发(一) 新手引导页开发
首先做开发的时候应该有一个闪屏页面和新手引导页, 我相信闪屏页面大家应该都会了,那么先看到新手引导页了. 我们可以看到这其实是一个ViewPager,我们也可以看到这是3个引导页,那么首先来看一下布局 ...
- java中的interface接口
接口:java接口是一些方法表征的集合,但是却不会在接口里实现具体的方法. java接口的特点如下: 1.java接口不能被实例化 2.java接口中声明的成员自动被设置为public,所以不存在pr ...