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

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

 1 struct evbuffer {
 2     /** The first chain in this buffer's linked list of chains. */
 3     struct evbuffer_chain *first;
 4     /** The last chain in this buffer's linked list of chains. */
 5     struct evbuffer_chain *last;
 6
 7     /** Pointer to the next pointer pointing at the 'last_with_data' chain.
 8      *
 9      * To unpack:
10      *
11      * The last_with_data chain is the last chain that has any data in it.
12      * If all chains in the buffer are empty, it is the first chain.
13      * If the buffer has no chains, it is NULL.
14      *
15      * The last_with_datap pointer points at _whatever 'next' pointer_
16      * points at the last_with_datap chain.  If the last_with_data chain
17      * is the first chain, or it is NULL, then the last_with_datap pointer
18      * is &buf->first.
19      */
20     struct evbuffer_chain **last_with_datap;
21
22     /** Total amount of bytes stored in all chains.*/
23     size_t total_len;
24
25     /** Number of bytes we have added to the buffer since we last tried to
26      * invoke callbacks. */
27     size_t n_add_for_cb;
28     /** Number of bytes we have removed from the buffer since we last
29      * tried to invoke callbacks. */
30     size_t n_del_for_cb;
31
32 #ifndef EVENT__DISABLE_THREAD_SUPPORT
33     /** A lock used to mediate access to this buffer. */
34     void *lock;
35 #endif
36     /** True iff we should free the lock field when we free this
37      * evbuffer. */
38     unsigned own_lock : 1;
39     /** True iff we should not allow changes to the front of the buffer
40      * (drains or prepends). */
41     unsigned freeze_start : 1;
42     /** True iff we should not allow changes to the end of the buffer
43      * (appends) */
44     unsigned freeze_end : 1;
45     /** True iff this evbuffer's callbacks are not invoked immediately
46      * upon a change in the buffer, but instead are deferred to be invoked
47      * from the event_base's loop.    Useful for preventing enormous stack
48      * overflows when we have mutually recursive callbacks, and for
49      * serializing callbacks in a single thread. */
50     unsigned deferred_cbs : 1;
51 #ifdef _WIN32
52     /** True iff this buffer is set up for overlapped IO. */
53     unsigned is_overlapped : 1;
54 #endif
55     /** Zero or more EVBUFFER_FLAG_* bits */
56     ev_uint32_t flags;
57
58     /** Used to implement deferred callbacks. */
59     struct event_base *cb_queue;
60
61     /** A reference count on this evbuffer.     When the reference count
62      * reaches 0, the buffer is destroyed.    Manipulated with
63      * evbuffer_incref and evbuffer_decref_and_unlock and
64      * evbuffer_free. */
65     int refcnt;
66
67     /** A struct event_callback handle to make all of this buffer's callbacks
68      * invoked from the event loop. */
69     struct event_callback deferred;
70
71     /** A doubly-linked-list of callback functions */
72     LIST_HEAD(evbuffer_cb_queue, evbuffer_cb_entry) callbacks;
73
74     /** The parent bufferevent object this evbuffer belongs to.
75      * NULL if the evbuffer stands alone. */
76     struct bufferevent *parent;
77 };

struct evbuffer_chain:

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

 1 /** A single item in an evbuffer. */
 2 struct evbuffer_chain {
 3     /** points to next buffer in the chain */
 4     struct evbuffer_chain *next;
 5
 6     /** total allocation available in the buffer field. */
 7     size_t buffer_len;
 8
 9     /** unused space at the beginning of buffer or an offset into a
10      * file for sendfile buffers. */
11     ev_misalign_t misalign;
12
13     /** Offset into buffer + misalign at which to start writing.
14      * In other words, the total number of bytes actually stored
15      * in buffer. */
16     size_t off;
17
18     /** Set if special handling is required for this chain */
19     unsigned flags;
20 #define EVBUFFER_FILESEGMENT    0x0001  /**< A chain used for a file segment */
21 #define EVBUFFER_SENDFILE    0x0002    /**< a chain used with sendfile */
22 #define EVBUFFER_REFERENCE    0x0004    /**< a chain with a mem reference */
23 #define EVBUFFER_IMMUTABLE    0x0008    /**< read-only chain */
24     /** a chain that mustn't be reallocated or freed, or have its contents
25      * memmoved, until the chain is un-pinned. */
26 #define EVBUFFER_MEM_PINNED_R    0x0010
27 #define EVBUFFER_MEM_PINNED_W    0x0020
28 #define EVBUFFER_MEM_PINNED_ANY (EVBUFFER_MEM_PINNED_R|EVBUFFER_MEM_PINNED_W)
29     /** a chain that should be freed, but can't be freed until it is
30      * un-pinned. */
31 #define EVBUFFER_DANGLING    0x0040
32     /** a chain that is a referenced copy of another chain */
33 #define EVBUFFER_MULTICAST    0x0080
34
35     /** number of references to this chain */
36     int refcnt;
37
38     /** Usually points to the read-write memory belonging to this
39      * buffer allocated as part of the evbuffer_chain allocation.
40      * For mmap, this can be a read-only buffer and
41      * EVBUFFER_IMMUTABLE will be set in flags.  For sendfile, it
42      * may point to NULL.
43      */
44     unsigned char *buffer;
45 };
46
47 /** callback for a reference chain; lets us know what to do with it when
48  * we're done with it. Lives at the end of an evbuffer_chain with the
49  * EVBUFFER_REFERENCE flag set */
50 struct evbuffer_chain_reference {
51     evbuffer_ref_cleanup_cb cleanupfn;
52     void *extra;
53 };

lievent源码分析:evbuffer相关推荐

  1. 【Golang源码分析】Go Web常用程序包gorilla/mux的使用与源码简析

    目录[阅读时间:约10分钟] 一.概述 二.对比: gorilla/mux与net/http DefaultServeMux 三.简单使用 四.源码简析 1.NewRouter函数 2.HandleF ...

  2. SpringBoot-web开发(四): SpringMVC的拓展、接管(源码分析)

    [SpringBoot-web系列]前文: SpringBoot-web开发(一): 静态资源的导入(源码分析) SpringBoot-web开发(二): 页面和图标定制(源码分析) SpringBo ...

  3. SpringBoot-web开发(二): 页面和图标定制(源码分析)

    [SpringBoot-web系列]前文: SpringBoot-web开发(一): 静态资源的导入(源码分析) 目录 一.首页 1. 源码分析 2. 访问首页测试 二.动态页面 1. 动态资源目录t ...

  4. SpringBoot-web开发(一): 静态资源的导入(源码分析)

    目录 方式一:通过WebJars 1. 什么是webjars? 2. webjars的使用 3. webjars结构 4. 解析源码 5. 测试访问 方式二:放入静态资源目录 1. 源码分析 2. 测 ...

  5. Yolov3Yolov4网络结构与源码分析

    Yolov3&Yolov4网络结构与源码分析 从2018年Yolov3年提出的两年后,在原作者声名放弃更新Yolo算法后,俄罗斯的Alexey大神扛起了Yolov4的大旗. 文章目录 论文汇总 ...

  6. ViewGroup的Touch事件分发(源码分析)

    Android中Touch事件的分发又分为View和ViewGroup的事件分发,View的touch事件分发相对比较简单,可参考 View的Touch事件分发(一.初步了解) View的Touch事 ...

  7. View的Touch事件分发(二.源码分析)

    Android中Touch事件的分发又分为View和ViewGroup的事件分发,先来看简单的View的touch事件分发. 主要分析View的dispatchTouchEvent()方法和onTou ...

  8. MyBatis原理分析之四:一次SQL查询的源码分析

    上回我们讲到Mybatis加载相关的配置文件进行初始化,这回我们讲一下一次SQL查询怎么进行的. 准备工作 Mybatis完成一次SQL查询需要使用的代码如下: Java代码   String res ...

  9. [转]slf4j + log4j原理实现及源码分析

    slf4j + log4j原理实现及源码分析 转载于:https://www.cnblogs.com/jasonzeng888/p/6051080.html

最新文章

  1. 手把手带你撸一个cli工具
  2. 从重采样到数据合成:如何处理机器学习中的不平衡分类问题? 转载 2017年08月01日 17:09:03 标签: 机器学习 / 数据 719 转自:http://www.sohu.com/a/12
  3. python使用近似公式计算e_python如何算自然底数e(方法二)
  4. 蓝桥杯 BASIC-19 基础练习 完美的代价 Java版
  5. SQL Server-【知识与实战VII】存储过程(下)
  6. ARM平台AMBA总线uart驱动和console初始化
  7. Oracle下载安装:
  8. 纲要-Java网络爬虫系统性学习与实战(1)
  9. 360无线网卡驱动服务器,360无线网卡驱动
  10. 【gp数据库】建表语句万能模板
  11. 写代码遇到的灵异事件
  12. 中型仓储货架是使用三立柱货架好,还是使用两立柱货架好?
  13. Distributed System
  14. BZOJ 3159: 决战 解题报告
  15. 在 Flutter 中自定义画笔 Painter
  16. Web3能否撕裂国内 VC 的共识?
  17. java推送微信模板消息
  18. 联想计算机电源维修,联想电脑主机FSP145-51N1型电源工作原理
  19. 舔狗日记随机展示网站源码
  20. 绕线机-排线伺服比例随动功能块(梯形图+SCL代码)

热门文章

  1. ajax+time+out,关于ajax的timeout问题
  2. wordpress php 链接,简介WordPress中用于获取首页和站点链接的PHP函数_PHP
  3. github private链接访问_如何判定一段内存地址是不可访问的?
  4. Java线程与Android线程,Android线程篇(三):深入理解Java线程池(一)
  5. redis 设置不过期_面试时 Redis 内存淘汰总被问,但是总答不好,怎么解决?
  6. window.open ()的用法
  7. vue项目 构建 打包 发布 三部曲
  8. 电子商务商品供应链概论
  9. 系统学习NLP(二十三)--浅谈Attention机制的理解
  10. 米线店结账程序 装饰着模式_真实数据:外卖销售9999+ 长沙米线万单店 它究竟是怎么做到的?...