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 : ;
  39. /** True iff we should not allow changes to the front of the buffer
  40. * (drains or prepends). */
  41. unsigned freeze_start : ;
  42. /** True iff we should not allow changes to the end of the buffer
  43. * (appends) */
  44. unsigned freeze_end : ;
  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 : ;
  51. #ifdef _WIN32
  52. /** True iff this buffer is set up for overlapped IO. */
  53. unsigned is_overlapped : ;
  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. 【转】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. js再学习笔记

    #js再学习笔记 ##基本 1.js严格区分大小写   2.js末尾的分号可加,也可不加   3.六种数据类型(使用typeof来检验数据的类型) `typeof` - undefined: `var ...

  2. 链接后加"/"与不加"/"的区别

    1.http://www.abc.com/abc2.http://www.abc.com/abc/ 当Web服务器接收到对某个末尾不含斜杠的url请求时,例如“http://www.abc.com/a ...

  3. oracle空间管理

    表空间:组织数据文件的一种途径,  是一个逻辑概念  包含有 表,字段,索引 一个数据库可以对应多个表空间 一个物理文件对应一个表空间 任何一个数据库创建的第一一个表空间是 system Tables ...

  4. 树莓派文档翻译 - 使用 - GPIO: 树莓派A和B

    https://www.raspberrypi.org/documentation/usage/gpio/README.md 2016/6/25 GPIO: 树莓派A和B ##介绍GPIO和在树莓派上 ...

  5. centos7 挂载数据盘

    centos 挂载数据盘1.运行 fdisk -l 命令查看数据盘.注意:在没有分区和格式化数据盘之前,使用 df -h 命令是无法看到数据盘的. 如果执行了 fdisk -l 命令后,没有发现 /d ...

  6. IAR EW8051-8.10.4安装及破解方法

    第一步:获取破解license 1: 点击桌面左下角“开始”按钮,找到cmd.exe,右键创建cmd.exe 快捷方式到桌面: ————如果是windows7 ,请右键点击cmd.exe 快捷图标,点 ...

  7. css3超过指定宽度文字,显示省略号

    text-overflow:ellipsis; overflow:hidden; white-space:nowrap; width:200px;

  8. git http\https\git免密设置记住用户名和密码的方法

    设置记住密码(默认15分钟): git config --global credential.helper cache如果想自己设置时间,可以这样做: git config credential.he ...

  9. NumberPicker设置宽度,设置文字颜色

    修改宽度 wheel = (NumberPicker) findViewById(R.id.info_wheel_province); wheel.setLayoutParams(new Linear ...

  10. git pull all braches

    控制台下执行如下: git branch -r | grep -v '\->' | while read remote; do git branch --track "${remote ...