An evbuffer is an opaque data type for efficiently buffering data to be sent or received on the network.
Type definition for a callback that is invoked whenever data is added or removed from an evbuffer.
Describes a single extent of memory inside an evbuffer. Used for direct-access functions.
A cleanup function for a piece of memory added to an evbuffer by reference.
Used to tell evbuffer_readln what kind of line-ending to look for.
Defines how to adjust an evbuffer_ptr by evbuffer_ptr_set()
Append data to the end of an evbuffer.
Move all data from one evbuffer into another evbuffer.
Add a new callback to an evbuffer.
Copy data from a file into the evbuffer for writing to a socket.
Append a formatted string to the end of an evbuffer.
Reference memory into an evbuffer without copying.
Append a va_list formatted string to the end of an evbuffer.
Change the flags that are set for a callback on a buffer by removing some
Change the flags that are set for a callback on a buffer by adding more.
Postpone calling a given callback until unsuspend is called later.
Stop postponing a callback that we postponed with evbuffer_cb_suspend.
Change the flags that are set for an evbuffer by removing some.
Commits previously reserved space.
Read data from an evbuffer, and leave the buffer unchanged.
Force all the callbacks on an evbuffer to be run, not immediately after the evbuffer is altered, but instead from inside the event loop.
Remove a specified number of bytes data from the beginning of an evbuffer.
Enable locking on an evbuffer so that it can safely be used by multiple threads at the same time.
Expands the available space in an evbuffer.
Deallocate storage for an evbuffer.
Prevent calls that modify an evbuffer from succeeding. A buffer may frozen at the front, at the back, or at both the front and the back.
Returns the number of contiguous available bytes in the first buffer chain.
Returns the total number of bytes stored in the evbuffer
Acquire the lock on an evbuffer. Has no effect if locking was not enabled with evbuffer_enable_locking.
Allocate storage for a new evbuffer.
Function to peek at data inside an evbuffer without removing it or copying it out.
Prepends data to the beginning of the evbuffer
Prepends all data from the src evbuffer to the beginning of the dst evbuffer.
Sets the search pointer in the buffer to position.
Makes the data at the begging of an evbuffer contiguous.
Read from a file descriptor and store the result in an evbuffer.
Read a single line from an evbuffer.
Read data from an evbuffer and drain the bytes read.
Read data from an evbuffer into another evbuffer, draining the bytes from the source buffer. This function avoids copy operations to the extent possible.
Remove a callback from an evbuffer, given the function and argument used to add it.
Remove a callback from an evbuffer, given a handle returned from evbuffer_add_cb.
Reserves space in the last chain or chains of an evbuffer.
Search for a string within an evbuffer.
Search for an end-of-line string within an evbuffer.
Search for a string within part of an evbuffer.
Change the flags that are set for an evbuffer by adding more.
Re-enable calls that modify an evbuffer.
Release the lock on an evbuffer. Has no effect if locking was not enabled with evbuffer_enable_locking.
Write the contents of an evbuffer to a file descriptor.
Write some of the contents of an evbuffer to a file descriptor.
If this flag is not set, then a callback is temporarily disabled, and should not be invoked.
If this flag is set, then we will not use evbuffer_peek(), evbuffer_remove(), evbuffer_remove_buffer(), and so on to read bytes from this buffer: we'll only take bytes out of this buffer by writing them to the network (as with evbuffer_write_atmost), by removing them without observing them (as with evbuffer_drain_), or by copying them all out at once (as with evbuffer_add_buffer).
Structure passed to an evbuffer_cb_func evbuffer callback
Pointer to a position within an evbuffer.
@file event2/buffer.h
Functions for buffering data for network sending or receiving.
An evbuffer can be used for preparing data before sending it to the network or conversely for reading data from the network. Evbuffers try to avoid memory copies as much as possible. As a result, evbuffers can be used to pass data around without actually incurring the overhead of copying the data.
A new evbuffer can be allocated with evbuffer_new(), and can be freed with evbuffer_free(). Most users will be using evbuffers via the bufferevent interface. To access a bufferevent's evbuffers, use bufferevent_get_input() and bufferevent_get_output().
There are several guidelines for using evbuffers.
- if you already know how much data you are going to add as a result of calling evbuffer_add() multiple times, it makes sense to use evbuffer_expand() first to make sure that enough memory is allocated before hand.
- evbuffer_add_buffer() adds the contents of one buffer to the other without incurring any unnecessary memory copies.
- evbuffer_add() and evbuffer_add_buffer() do not mix very well: if you use them, you will wind up with fragmented memory in your buffer.
- For high-performance code, you may want to avoid copying data into and out of buffers. You can skip the copy step by using evbuffer_reserve_space()/evbuffer_commit_space() when writing into a buffer, and evbuffer_peek() when reading.
In Libevent 2.0 and later, evbuffers are represented using a linked list of memory chunks, with pointers to the first and last chunk in the chain.
As the contents of an evbuffer can be stored in multiple different memory blocks, it cannot be accessed directly. Instead, evbuffer_pullup() can be used to force a specified number of bytes to be contiguous. This will cause memory reallocation and memory copies if the data is split across multiple blocks. It is more efficient, however, to use evbuffer_peek() if you don't require that the memory to be contiguous.