libevent源码分析bufferevent_setcb,bufferevent ,bufferevent_data_cb,bufferevent_event_cb,bufferevent_enable,bufferevent_get_output


/**
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);

  


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM