/** Changes the callbacks for a bufferevent.
通過回調函數來改變bufferevent @param bufev the bufferevent object for which to change callbacks
回調函數將要改變的bufferevent對象
@param readcb callback to invoke when there is data to be read, or NULL if no callback is desired
當有數據要被讀取是,會調用回調函數,如果沒有回調函數,可以為空 @param writecb callback to invoke when the file descriptor is ready for writing, or NULL if no callback is desired
當文件描敘符准備好了寫,會調用回調函數,如果沒有回調函數,可以為空 @param eventcb callback to invoke when there is an event on the file descriptor
當文件描敘符有事件,會調用回調函數 @param cbarg an argument that will be supplied to each of the callbacks (readcb, writecb, and errorcb)
提供給回調函數的參數(讀回調,寫回調,錯誤回調) @see bufferevent_new() */
void bufferevent_setcb(struct bufferevent *bufev, bufferevent_data_cb readcb, bufferevent_data_cb writecb, bufferevent_event_cb eventcb, void *cbarg);
/** Shared implementation of a bufferevent. bufferevent 共享實現 This type is exposed only because it was exposed in previous versions, and some people's code may rely on manipulating it. Otherwise, you should really not rely on the layout, size, or contents of this structure: it is fairly volatile, and WILL change in future versions of the code. **/
struct bufferevent { /** Event base for which this bufferevent was created. */
base,bufferevent為其創建 struct event_base *ev_base; /** Pointer to a table of function pointers to set up how this bufferevent behaves. */
指向一個函數指針表,用於設置bufferevent行為 const struct bufferevent_ops *be_ops; /** A read event that triggers when a timeout has happened or a socket is ready to read data. Only used by some subtypes of bufferevent. */
讀事件,當超時或者套接字准備好讀取數據時觸發。僅被bufferevent的一些子類型所使用 struct event ev_read; /** A write event that triggers when a timeout has happened or a socket is ready to write data. Only used by some subtypes of bufferevent. */
寫事件。 struct event ev_write; /** An input buffer. Only the bufferevent is allowed to add data to this buffer, though the user is allowed to drain it. */ struct evbuffer *input; /** An output buffer. Only the bufferevent is allowed to drain data from this buffer, though the user is allowed to add it. */ struct evbuffer *output; struct event_watermark wm_read; struct event_watermark wm_write; bufferevent_data_cb readcb; bufferevent_data_cb writecb; /* This should be called 'eventcb', but renaming it would break * backward compatibility */ bufferevent_event_cb errorcb; void *cbarg; struct timeval timeout_read; struct timeval timeout_write; /** Events that are currently enabled: currently EV_READ and EV_WRITE are supported. */ short enabled; };
/** A read or write callback for a bufferevent. 對於一個bufferevent的讀或者寫的回調 The read callback is triggered when new data arrives in the input buffer and the amount of readable data exceed the low watermark which is 0 by default. 當新數據到達輸入緩存區且可讀數據的大小超過低水平線(默認大小是0),會觸發讀回調 The write callback is triggered if the write buffer has been exhausted or fell below its low watermark. @param bev the bufferevent that triggered the callback
觸發回調的bufferevent @param ctx the user-specified context for this bufferevent
用戶為bufferevent指定的上下文 */ typedef void (*bufferevent_data_cb)(struct bufferevent *bev, void *ctx);
/** An event/error callback for a bufferevent. bufferevent的事件/錯誤回調 The event callback is triggered if either an EOF condition or another unrecoverable error was encountered. For bufferevents with deferred callbacks, this is a bitwise OR of all errors that have happened on the bufferevent since the last callback invocation. @param bev the bufferevent for which the error condition was reached @param what a conjunction of flags: BEV_EVENT_READING or BEV_EVENT_WRITING to indicate if the error was encountered on the read or write path, and one of the following flags: BEV_EVENT_EOF, BEV_EVENT_ERROR, BEV_EVENT_TIMEOUT, BEV_EVENT_CONNECTED. @param ctx the user-specified context for this bufferevent */ typedef void (*bufferevent_event_cb)(struct bufferevent *bev, short what, void *ctx);
/** Enable a bufferevent. @param bufev the bufferevent to be enabled 將要進行選擇的bufferevent @param event any combination of EV_READ | EV_WRITE. @return 0 if successful, or -1 if an error occurred @see bufferevent_disable() */ int bufferevent_enable(struct bufferevent *bufev, short event);
/** Returns the output buffer. 返回輸出緩存區 The user MUST NOT set the callback on this buffer. When filters are being used, the filters need to be manually triggered if the output buffer was manipulated. @param bufev the bufferevent from which to get the evbuffer 目標,從目標那獲取evbuffer @return the evbuffer object for the output buffer 給輸出緩存區的evbuffer */ struct evbuffer *bufferevent_get_output(struct bufferevent *bufev);