libevent备忘

英文部分引用:http://www.wangafu.net/~nickm/libevent-book/Ref7_evbuffer.html

Moving data from one evbuffer to anotherFor efficiency, Libevent has optimized functions for moving data from one evbuffer to another.

Interface
int evbuffer_add_buffer(struct evbuffer *dst, struct evbuffer *src);
int evbuffer_remove_buffer(struct evbuffer *src, struct evbuffer *dst,
    size_t datlen);

The evbuffer_add_buffer() function moves all data from src to the end of dst. It returns 0 on success, -1 on failure.
The evbuffer_remove_buffer() function moves exactly datlen bytes from src to the end of dst, copying as little as possible. If there are fewer than datlen bytes to move, it moves all the bytes. It returns the number of bytes moved.

We introduced evbuffer_add_buffer() in Libevent 0.8; evbuffer_remove_buffer() was new in Libevent 2.0.1-alpha.

Adding data to the front of an evbufferInterface
int evbuffer_prepend(struct evbuffer *buf, constvoid *data, size_t size);
int evbuffer_prepend_buffer(struct evbuffer *dst, struct evbuffer* src);
These functions behave as evbuffer_add() and evbuffer_add_buffer() respectively, except that they move data to the front of the destination buffer.

These functions should be used with caution, and never on an evbuffer shared with a bufferevent. They were new in Libevent 2.0.1-alpha.

(使用这组函数需谨慎,并且永远不要在和bufferevent关联的evbuffer上使用)


bufferevent_write
bufferevent_write_buffer 只是对evbuffer的一个包装
如果上述两个函数不能满足需求,那么取bufferevent_get_output, bufferevent_get_input可以取出关联的evbuffer,然后可以evbuffer调用相关的方法

 

你可能感兴趣的:(libevent)