deimos.event2.buffer

@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.

Public Imports

deimos.event2.util
public import deimos.event2.util;
deimos.event2.event_struct
public import deimos.event2.event_struct;

Members

Aliases

evbuffer
alias evbuffer = void

An evbuffer is an opaque data type for efficiently buffering data to be sent or received on the network.

evbuffer_cb_entry
alias evbuffer_cb_entry = void
Undocumented in source but is binding to C. You might be able to learn more by searching the web for its name.
evbuffer_cb_func
alias evbuffer_cb_func = ExternC!(void function(evbuffer* buffer, const(evbuffer_cb_info)* info, void* arg))

Type definition for a callback that is invoked whenever data is added or removed from an evbuffer.

evbuffer_iovec
alias evbuffer_iovec = iovec

Describes a single extent of memory inside an evbuffer. Used for direct-access functions.

evbuffer_ref_cleanup_cb
alias evbuffer_ref_cleanup_cb = ExternC!(void function(const(void)* data, size_t datalen, void* extra))

A cleanup function for a piece of memory added to an evbuffer by reference.

Enums

evbuffer_eol_style
enum evbuffer_eol_style

Used to tell evbuffer_readln what kind of line-ending to look for.

evbuffer_ptr_how
enum evbuffer_ptr_how

Defines how to adjust an evbuffer_ptr by evbuffer_ptr_set()

Functions

evbuffer_add
int evbuffer_add(evbuffer* buf, const(void)* data, size_t datlen)

Append data to the end of an evbuffer.

evbuffer_add_buffer
int evbuffer_add_buffer(evbuffer* outbuf, evbuffer* inbuf)

Move all data from one evbuffer into another evbuffer.

evbuffer_add_cb
evbuffer_cb_entry* evbuffer_add_cb(evbuffer* buffer, evbuffer_cb_func cb, void* cbarg)

Add a new callback to an evbuffer.

evbuffer_add_file
int evbuffer_add_file(evbuffer* outbuf, int fd, ev_off_t offset, ev_off_t length)

Copy data from a file into the evbuffer for writing to a socket.

evbuffer_add_printf
int evbuffer_add_printf(evbuffer* buf, const(char)* fmt, ...)

Append a formatted string to the end of an evbuffer.

evbuffer_add_reference
int evbuffer_add_reference(evbuffer* outbuf, const(void)* data, size_t datlen, evbuffer_ref_cleanup_cb cleanupfn, void* cleanupfn_arg)

Reference memory into an evbuffer without copying.

evbuffer_add_vprintf
int evbuffer_add_vprintf(evbuffer* buf, const(char)* fmt, va_list ap)

Append a va_list formatted string to the end of an evbuffer.

evbuffer_cb_clear_flags
int evbuffer_cb_clear_flags(evbuffer* buffer, evbuffer_cb_entry* cb, ev_uint32_t flags)

Change the flags that are set for a callback on a buffer by removing some

evbuffer_cb_set_flags
int evbuffer_cb_set_flags(evbuffer* buffer, evbuffer_cb_entry* cb, ev_uint32_t flags)

Change the flags that are set for a callback on a buffer by adding more.

evbuffer_cb_suspend
void evbuffer_cb_suspend(evbuffer* buffer, evbuffer_cb_entry* cb)

Postpone calling a given callback until unsuspend is called later.

evbuffer_cb_unsuspend
void evbuffer_cb_unsuspend(evbuffer* buffer, evbuffer_cb_entry* cb)

Stop postponing a callback that we postponed with evbuffer_cb_suspend.

evbuffer_clear_flags
int evbuffer_clear_flags(evbuffer* buf, ev_uint64_t flags)

Change the flags that are set for an evbuffer by removing some.

evbuffer_commit_space
int evbuffer_commit_space(evbuffer* buf, evbuffer_iovec* vec, int n_vecs)

Commits previously reserved space.

evbuffer_copyout
ev_ssize_t evbuffer_copyout(evbuffer* buf, void* data_out, size_t datlen)

Read data from an evbuffer, and leave the buffer unchanged.

evbuffer_defer_callbacks
int evbuffer_defer_callbacks(evbuffer* buffer, event_base* base)

Force all the callbacks on an evbuffer to be run, not immediately after the evbuffer is altered, but instead from inside the event loop.

evbuffer_drain
int evbuffer_drain(evbuffer* buf, size_t len)

Remove a specified number of bytes data from the beginning of an evbuffer.

evbuffer_enable_locking
int evbuffer_enable_locking(evbuffer* buf, void* lock)

Enable locking on an evbuffer so that it can safely be used by multiple threads at the same time.

evbuffer_expand
int evbuffer_expand(evbuffer* buf, size_t datlen)

Expands the available space in an evbuffer.

evbuffer_free
void evbuffer_free(evbuffer* buf)

Deallocate storage for an evbuffer.

evbuffer_freeze
int evbuffer_freeze(evbuffer* buf, int at_front)

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.

evbuffer_get_contiguous_space
size_t evbuffer_get_contiguous_space(const(evbuffer)* buf)

Returns the number of contiguous available bytes in the first buffer chain.

evbuffer_get_length
size_t evbuffer_get_length(const(evbuffer)* buf)

Returns the total number of bytes stored in the evbuffer

evbuffer_lock
void evbuffer_lock(evbuffer* buf)

Acquire the lock on an evbuffer. Has no effect if locking was not enabled with evbuffer_enable_locking.

evbuffer_new
evbuffer* evbuffer_new()

Allocate storage for a new evbuffer.

evbuffer_peek
int evbuffer_peek(evbuffer* buffer, ev_ssize_t len, evbuffer_ptr* start_at, evbuffer_iovec* vec_out, int n_vec)

Function to peek at data inside an evbuffer without removing it or copying it out.

evbuffer_prepend
int evbuffer_prepend(evbuffer* buf, const(void)* data, size_t size)

Prepends data to the beginning of the evbuffer

evbuffer_prepend_buffer
int evbuffer_prepend_buffer(evbuffer* dst, evbuffer* src)

Prepends all data from the src evbuffer to the beginning of the dst evbuffer.

evbuffer_ptr_set
int evbuffer_ptr_set(evbuffer* buffer, evbuffer_ptr* ptr, size_t position, evbuffer_ptr_how how)

Sets the search pointer in the buffer to position.

evbuffer_pullup
ubyte* evbuffer_pullup(evbuffer* buf, ev_ssize_t size)

Makes the data at the begging of an evbuffer contiguous.

evbuffer_read
int evbuffer_read(evbuffer* buffer, evutil_socket_t fd, int howmuch)

Read from a file descriptor and store the result in an evbuffer.

evbuffer_readln
char* evbuffer_readln(evbuffer* buffer, size_t* n_read_out, evbuffer_eol_style eol_style)

Read a single line from an evbuffer.

evbuffer_remove
int evbuffer_remove(evbuffer* buf, void* data, size_t datlen)

Read data from an evbuffer and drain the bytes read.

evbuffer_remove_buffer
int evbuffer_remove_buffer(evbuffer* src, evbuffer* dst, size_t datlen)

Read data from an evbuffer into another evbuffer, draining the bytes from the source buffer. This function avoids copy operations to the extent possible.

evbuffer_remove_cb
int evbuffer_remove_cb(evbuffer* buffer, evbuffer_cb_func cb, void* cbarg)

Remove a callback from an evbuffer, given the function and argument used to add it.

evbuffer_remove_cb_entry
int evbuffer_remove_cb_entry(evbuffer* buffer, evbuffer_cb_entry* ent)

Remove a callback from an evbuffer, given a handle returned from evbuffer_add_cb.

evbuffer_reserve_space
int evbuffer_reserve_space(evbuffer* buf, ev_ssize_t size, evbuffer_iovec* vec, int n_vec)

Reserves space in the last chain or chains of an evbuffer.

evbuffer_search
evbuffer_ptr evbuffer_search(evbuffer* buffer, const(char)* what, size_t len, const(evbuffer_ptr)* start)

Search for a string within an evbuffer.

evbuffer_search_eol
evbuffer_ptr evbuffer_search_eol(evbuffer* buffer, evbuffer_ptr* start, size_t* eol_len_out, evbuffer_eol_style eol_style)

Search for an end-of-line string within an evbuffer.

evbuffer_search_range
evbuffer_ptr evbuffer_search_range(evbuffer* buffer, const(char)* what, size_t len, const(evbuffer_ptr)* start, const(evbuffer_ptr)* end)

Search for a string within part of an evbuffer.

evbuffer_set_flags
int evbuffer_set_flags(evbuffer* buf, ev_uint64_t flags)

Change the flags that are set for an evbuffer by adding more.

evbuffer_unfreeze
int evbuffer_unfreeze(evbuffer* buf, int at_front)

Re-enable calls that modify an evbuffer.

evbuffer_unlock
void evbuffer_unlock(evbuffer* buf)

Release the lock on an evbuffer. Has no effect if locking was not enabled with evbuffer_enable_locking.

evbuffer_write
int evbuffer_write(evbuffer* buffer, evutil_socket_t fd)

Write the contents of an evbuffer to a file descriptor.

evbuffer_write_atmost
int evbuffer_write_atmost(evbuffer* buffer, evutil_socket_t fd, ev_ssize_t howmuch)

Write some of the contents of an evbuffer to a file descriptor.

Manifest constants

EVBUFFER_CB_ENABLED
enum EVBUFFER_CB_ENABLED;

If this flag is not set, then a callback is temporarily disabled, and should not be invoked.

EVBUFFER_FLAG_DRAINS_TO_FD
enum EVBUFFER_FLAG_DRAINS_TO_FD;

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).

Structs

evbuffer_cb_info
struct evbuffer_cb_info

Structure passed to an evbuffer_cb_func evbuffer callback

evbuffer_iovec
struct evbuffer_iovec
Undocumented in source but is binding to C. You might be able to learn more by searching the web for its name.
evbuffer_ptr
struct evbuffer_ptr

Pointer to a position within an evbuffer.

Meta