libevent源码分析:bufferevent
Posted 冷冰若水
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了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 };
以上是关于libevent源码分析:bufferevent的主要内容,如果未能解决你的问题,请参考以下文章