struct evbuffer定义在evbuffer-internal.h文件中。

evbuffer结构内部保存一个以evbuffer-chain结构为节点的链表,evbuffer内部有两个分别指向首尾节点的指针。

 struct evbuffer {
/** The first chain in this buffer's linked list of chains. */
struct evbuffer_chain *first;
/** The last chain in this buffer's linked list of chains. */
struct evbuffer_chain *last; /** Pointer to the next pointer pointing at the 'last_with_data' chain.
*
* To unpack:
*
* The last_with_data chain is the last chain that has any data in it.
* If all chains in the buffer are empty, it is the first chain.
* If the buffer has no chains, it is NULL.
*
* The last_with_datap pointer points at _whatever 'next' pointer_
* points at the last_with_datap chain. If the last_with_data chain
* is the first chain, or it is NULL, then the last_with_datap pointer
* is &buf->first.
*/
struct evbuffer_chain **last_with_datap; /** Total amount of bytes stored in all chains.*/
size_t total_len; /** Number of bytes we have added to the buffer since we last tried to
* invoke callbacks. */
size_t n_add_for_cb;
/** Number of bytes we have removed from the buffer since we last
* tried to invoke callbacks. */
size_t n_del_for_cb; #ifndef EVENT__DISABLE_THREAD_SUPPORT
/** A lock used to mediate access to this buffer. */
void *lock;
#endif
/** True iff we should free the lock field when we free this
* evbuffer. */
unsigned own_lock : ;
/** True iff we should not allow changes to the front of the buffer
* (drains or prepends). */
unsigned freeze_start : ;
/** True iff we should not allow changes to the end of the buffer
* (appends) */
unsigned freeze_end : ;
/** True iff this evbuffer's callbacks are not invoked immediately
* upon a change in the buffer, but instead are deferred to be invoked
* from the event_base's loop. Useful for preventing enormous stack
* overflows when we have mutually recursive callbacks, and for
* serializing callbacks in a single thread. */
unsigned deferred_cbs : ;
#ifdef _WIN32
/** True iff this buffer is set up for overlapped IO. */
unsigned is_overlapped : ;
#endif
/** Zero or more EVBUFFER_FLAG_* bits */
ev_uint32_t flags; /** Used to implement deferred callbacks. */
struct event_base *cb_queue; /** A reference count on this evbuffer. When the reference count
* reaches 0, the buffer is destroyed. Manipulated with
* evbuffer_incref and evbuffer_decref_and_unlock and
* evbuffer_free. */
int refcnt; /** A struct event_callback handle to make all of this buffer's callbacks
* invoked from the event loop. */
struct event_callback deferred; /** A doubly-linked-list of callback functions */
LIST_HEAD(evbuffer_cb_queue, evbuffer_cb_entry) callbacks; /** The parent bufferevent object this evbuffer belongs to.
* NULL if the evbuffer stands alone. */
struct bufferevent *parent;
};

struct evbuffer_chain:

evbuffer-chain结构内部保存一个表示buffer内容长度的变量以及一个char*的指针指向buffer内容所在的位置。

 /** A single item in an evbuffer. */
struct evbuffer_chain {
/** points to next buffer in the chain */
struct evbuffer_chain *next; /** total allocation available in the buffer field. */
size_t buffer_len; /** unused space at the beginning of buffer or an offset into a
* file for sendfile buffers. */
ev_misalign_t misalign; /** Offset into buffer + misalign at which to start writing.
* In other words, the total number of bytes actually stored
* in buffer. */
size_t off; /** Set if special handling is required for this chain */
unsigned flags;
#define EVBUFFER_FILESEGMENT 0x0001 /**< A chain used for a file segment */
#define EVBUFFER_SENDFILE 0x0002 /**< a chain used with sendfile */
#define EVBUFFER_REFERENCE 0x0004 /**< a chain with a mem reference */
#define EVBUFFER_IMMUTABLE 0x0008 /**< read-only chain */
/** a chain that mustn't be reallocated or freed, or have its contents
* memmoved, until the chain is un-pinned. */
#define EVBUFFER_MEM_PINNED_R 0x0010
#define EVBUFFER_MEM_PINNED_W 0x0020
#define EVBUFFER_MEM_PINNED_ANY (EVBUFFER_MEM_PINNED_R|EVBUFFER_MEM_PINNED_W)
/** a chain that should be freed, but can't be freed until it is
* un-pinned. */
#define EVBUFFER_DANGLING 0x0040
/** a chain that is a referenced copy of another chain */
#define EVBUFFER_MULTICAST 0x0080 /** number of references to this chain */
int refcnt; /** Usually points to the read-write memory belonging to this
* buffer allocated as part of the evbuffer_chain allocation.
* For mmap, this can be a read-only buffer and
* EVBUFFER_IMMUTABLE will be set in flags. For sendfile, it
* may point to NULL.
*/
unsigned char *buffer;
}; /** callback for a reference chain; lets us know what to do with it when
* we're done with it. Lives at the end of an evbuffer_chain with the
* EVBUFFER_REFERENCE flag set */
struct evbuffer_chain_reference {
evbuffer_ref_cleanup_cb cleanupfn;
void *extra;
};

lievent源码分析:evbuffer的更多相关文章

  1. 【转】libevent源码分析

    libevent源码分析 转自:http://www.cnblogs.com/hustcat/archive/2010/08/31/1814022.html 这两天没事,看了一下Memcached和l ...

  2. Envoy 源码分析--buffer

    目录 Envoy 源码分析--buffer BufferFragment RawSlice Slice OwnedSlice SliceDeque UnownedSlice OwnedImpl Wat ...

  3. Envoy 源码分析--event

    目录 Envoy 源码分析--event libevent Timer SignalEvent FileEvent RealTimeSystem 任务队列 延迟析构 dispacth_thread E ...

  4. ABP源码分析一:整体项目结构及目录

    ABP是一套非常优秀的web应用程序架构,适合用来搭建集中式架构的web应用程序. 整个Abp的Infrastructure是以Abp这个package为核心模块(core)+15个模块(module ...

  5. HashMap与TreeMap源码分析

    1. 引言     在红黑树--算法导论(15)中学习了红黑树的原理.本来打算自己来试着实现一下,然而在看了JDK(1.8.0)TreeMap的源码后恍然发现原来它就是利用红黑树实现的(很惭愧学了Ja ...

  6. nginx源码分析之网络初始化

    nginx作为一个高性能的HTTP服务器,网络的处理是其核心,了解网络的初始化有助于加深对nginx网络处理的了解,本文主要通过nginx的源代码来分析其网络初始化. 从配置文件中读取初始化信息 与网 ...

  7. zookeeper源码分析之五服务端(集群leader)处理请求流程

    leader的实现类为LeaderZooKeeperServer,它间接继承自标准ZookeeperServer.它规定了请求到达leader时需要经历的路径: PrepRequestProcesso ...

  8. zookeeper源码分析之四服务端(单机)处理请求流程

    上文: zookeeper源码分析之一服务端启动过程 中,我们介绍了zookeeper服务器的启动过程,其中单机是ZookeeperServer启动,集群使用QuorumPeer启动,那么这次我们分析 ...

  9. zookeeper源码分析之三客户端发送请求流程

    znode 可以被监控,包括这个目录节点中存储的数据的修改,子节点目录的变化等,一旦变化可以通知设置监控的客户端,这个功能是zookeeper对于应用最重要的特性,通过这个特性可以实现的功能包括配置的 ...

随机推荐

  1. windows安装django

    Window 下安装 Django 如果你还未安装Python环境需要先下载Python安装包. 1.Python 下载地址:https://www.python.org/downloads/ 2.D ...

  2. Cocos2d-x 开发 v3.2 建立新项目并添加库文件

    一.添加其它类库     3.0以上的设计耦合性强,项目中模块常以库的形式存在,需常添加链接库.在3.0中经常用到CocoStudio 编辑器的资源数据,所以需要添加CocoStudio 库. 1.1 ...

  3. JSONObject简介

    JSONObject简介 本节摘要:之前对JSON做了一次简单的介绍,并把JSON和XML做了一个简单的比较:那么,我就在想,如果是一个json格式的字符串传到后台,需要怎么对其处理?如果前台页面需要 ...

  4. BizTalk动手实验(三)BizTalk开发综合实验

    1 课程简介 通过本课程熟悉BizTalk开发组件Schema/Map/Orchestration/Pipeline的开发与配置 2 准备工作 3 演示 3.1 创建与配置BizTalk应用程序 1. ...

  5. graph | hungary

    匈牙利算法,求二分图最大匹配. 若P是图G中一条连通两个未匹配顶点的路径,并且属于M的边和不属于M的边(即已匹配和待匹配的边)在P上交替出现,则称P为相对于M的一条增广路径.(M为一个匹配) 由增广路 ...

  6. PG, Pool之间的一些数量关系

    先说一下我的环境: Ceph cluster中包含6台OSD节点 (osd.0 - 5), 一共有10个Pool (0 - 9), 这些Pool共享了144个PG (这个数字是所有Pool的PG_SI ...

  7. Java的析构函数System的finalize()

    一个对象是由产生 到使用 到销毁的过程 即C++中 构造函数-> body->析构函数 在Java之中为了回收不需要的空间可以使用System类的finalize() class A{ p ...

  8. Android Studio编译运行project报错:····· finished with non-zero exit value 1

    错误代码: Error:Execution failed for task ':app:transformClassesWithDexForDebug'. > com.android.ide.c ...

  9. 分割excel sheet

    Sub split_sheet() '输入用户想要拆分的工作表 Dim sheet_name sheet_name = Application.InputBox("请输入拆分工作表的名称:& ...

  10. MVC4脚本压缩 BundleTable bundles 404错误

    在发布网站的时候,因为使用了MVC4的新特性BundleTable,造成访问的时候js和css报了404错误, google了以后, 有朋友说是因为要在webservice添加 <modules ...