libevent源码分析:bufferevent

struct bufferevent定义在文件bufferevent_struct.h中。

 1 /**
 2   Shared implementation of a bufferevent.
 3
 4   This type is exposed only because it was exposed in previous versions,
 5   and some people‘s code may rely on manipulating it.  Otherwise, you
 6   should really not rely on the layout, size, or contents of this structure:
 7   it is fairly volatile, and WILL change in future versions of the code.
 8 **/
 9 struct bufferevent {
10     /** Event base for which this bufferevent was created. */
11     struct event_base *ev_base;
12     /** Pointer to a table of function pointers to set up how this
13         bufferevent behaves. */
14     const struct bufferevent_ops *be_ops;
15
16     /** A read event that triggers when a timeout has happened or a socket
17         is ready to read data.  Only used by some subtypes of
18         bufferevent. */
19     struct event ev_read;
20     /** A write event that triggers when a timeout has happened or a socket
21         is ready to write data.  Only used by some subtypes of
22         bufferevent. */
23     struct event ev_write;
24
25     /** An input buffer. Only the bufferevent is allowed to add data to
26         this buffer, though the user is allowed to drain it. */
27     struct evbuffer *input;
28
29     /** An input buffer. Only the bufferevent is allowed to drain data
30         from this buffer, though the user is allowed to add it. */
31     struct evbuffer *output;
32
33     struct event_watermark wm_read;
34     struct event_watermark wm_write;
35
36     bufferevent_data_cb readcb;
37     bufferevent_data_cb writecb;
38     /* This should be called ‘eventcb‘, but renaming it would break
39      * backward compatibility */
40     bufferevent_event_cb errorcb;
41     void *cbarg;
42
43     struct timeval timeout_read;
44     struct timeval timeout_write;
45
46     /** Events that are currently enabled: currently EV_READ and EV_WRITE
47         are supported. */
48     short enabled;
49 };
时间: 2024-11-08 18:33:02

libevent源码分析:bufferevent的相关文章

Libevent源码分析-timer和signal处理

timer处理 Signal处理 timerfd和signalfd timerfd signalfd timer处理 在Libevent源码分析-event处理流程中,使用了定时器,来看一下源码: evtimer_set(&ev, time_cb, NULL);//设置定时器事件 其中evtimer_set是个宏定义 #define evtimer_set(ev, cb, arg) event_set((ev), -1, 0, (cb), (arg)) //event_set原型 void ev

【转】libevent源码分析

libevent源码分析 转自:http://www.cnblogs.com/hustcat/archive/2010/08/31/1814022.html 这两天没事,看了一下Memcached和libevent的源码,做个小总结. 1.入门 1.1.概述Libevent是一个用于开发可扩展性网络服务器的基于事件驱动(event-driven)模型的网络库.Libevent有几个显著的亮点: (1)事件驱动(event-driven),高性能:(2)轻量级,专注于网络,不如 ACE 那么臃肿庞

Libevent源码分析 (1) hello-world

Libevent源码分析 (1) hello-world ⑨月份接触了久闻大名的libevent,当时想读读源码,可是由于事情比较多一直没有时间,现在手头的东西基本告一段落了,我准备读读libevent的源码,凡是我觉得有必要的内容均一一记录,与君共勉. 首先要说说什么是libevent: libevent是一个事件通知库,libevent API提供一种机制使得我们可以在一个文件描述符(file descriptor)发生特定事件时或者timeout发生时执行指定的回调函数.libevent意

libevent源码分析-event

event结构 event相关接口 Libevent对event的管理 event结构 event是Reactor模式中的最重要的组件.它包含了了一个句柄fd,并设置监听这个句柄上的哪些事件(读/写等),设置了对应的函数指针,在事件到来时,回调函数指针来处理事件. 先看一下event的结构.它位于include/event2/event_struct.h中 struct event { TAILQ_ENTRY(event) ev_active_next; TAILQ_ENTRY(event) e

[libevent源码分析] event_init

libevent采用的是经典的reactor网络框架,集成了信号.定时.网络事件于一体 首先对event_init进行源码剖析 event_init 主要创建event_base对象, struct event_base { const struct eventop *evsel; //lievent支持select epoll kequeue..等网络api,包括init.add.del.dispatch的接口,每种网络框架都支持 void *evbase; //支持相应网络api的 结构对象

[libevent源码分析] event_set

libevent使用event来封装网络事件回调,参数.fd...等一些信息,函数很简单 void event_set(struct event *ev, int fd, short events, void (*callback)(int, short, void *), void *arg) { /* Take the current base - caller needs to set the real base later */ ev->ev_base = current_base; /

[libevent源码分析] event_add

event_add 把event往当前event中的ev_base追加,如果需要定时,那么tv不能为空 int event_add(struct event *ev, const struct timeval *tv) { struct event_base *base = ev->ev_base; //event_add 会把event加入到他的ev_base成员里 const struct eventop *evsel = base->evsel; //对应linux的epoll相关函数

[libevent源码分析] event_base_dispatch

分析下事件循环 event_base_dispatch int event_base_dispatch(struct event_base *event_base) { return (event_base_loop(event_base, 0)); } int event_base_loop(struct event_base *base, int flags) { const struct eventop *evsel = base->evsel; void *evbase = base->

Libevent源码分析系列【转】

转自:https://www.cnblogs.com/zxiner/p/6919021.html 1.使用libevent库 源码那么多,该怎么分析从哪分析呢?一个好的方法就是先用起来,会用了,然后去看底层相应的源码,这样比较有条理,自上向下掌握.下面用libevent库写个程序,每隔1秒输出一行信息. test.c 2.event, event_base 经过第1步,下面开始看上面程序中的每一部分的源码.首先是两个核心结构体event和event_base event event_base源码

libevent源码分析一--io事件响应

这篇文章将分析libevent如何组织io事件,如何捕捉事件的发生并进行相应的操作.这里不会详细分析event与event_base的细节,仅描述io事件如何存储与如何响应. 1.  select libevent的实现io事件的backend实际上使用的是io复用接口,如select, poll, epoll等,这里以最简单的select为例进行说明.首先简单介绍一下select接口: int select(int nfds, fd_set *readfds, fd_set *writefds