.TH "event2/buffer.h" 3 "Tue Jan 31 2017" "libevent" \" -*- nroff -*-
.ad l
.nh
.SH NAME
event2/buffer.h \- Functions for buffering data for network sending or receiving\&.
.SH SYNOPSIS
.br
.PP
\fC#include <event2/visibility\&.h>\fP
.br
\fC#include <event2/event\-config\&.h>\fP
.br
\fC#include <stdarg\&.h>\fP
.br
\fC#include <event2/util\&.h>\fP
.br
.SS "Data Structures"
.in +1c
.ti -1c
.RI "struct \fBevbuffer\fP"
.br
.RI "\fIAn evbuffer is an opaque data type for efficiently buffering data to be sent or received on the network\&. \fP"
.ti -1c
.RI "struct \fBevbuffer_cb_info\fP"
.br
.RI "\fIStructure passed to an evbuffer_cb_func evbuffer callback\&. \fP"
.ti -1c
.RI "struct \fBevbuffer_iovec\fP"
.br
.RI "\fIDescribes a single extent of memory inside an evbuffer\&. \fP"
.ti -1c
.RI "struct \fBevbuffer_ptr\fP"
.br
.RI "\fIPointer to a position within an evbuffer\&. \fP"
.in -1c
.SS "Macros"
.in +1c
.ti -1c
.RI "#define \fBEVBUF_FS_CLOSE_ON_FREE\fP 0x01"
.br
.RI "\fIFlag for creating evbuffer_file_segment: If this flag is set, then when the evbuffer_file_segment is freed and no longer in use by any evbuffer, the underlying fd is closed\&. \fP"
.ti -1c
.RI "#define \fBEVBUF_FS_DISABLE_LOCKING\fP 0x08"
.br
.RI "\fIFlag for creating evbuffer_file_segment: Do not allocate a lock for this segment\&. \fP"
.ti -1c
.RI "#define \fBEVBUF_FS_DISABLE_MMAP\fP 0x02"
.br
.RI "\fIFlag for creating evbuffer_file_segment: Disable memory-map based implementations\&. \fP"
.ti -1c
.RI "#define \fBEVBUF_FS_DISABLE_SENDFILE\fP 0x04"
.br
.RI "\fIFlag for creating evbuffer_file_segment: Disable direct fd-to-fd implementations (including sendfile and splice)\&. \fP"
.ti -1c
.RI "#define \fBEVBUFFER_CB_ENABLED\fP 1"
.br
.RI "\fIIf this flag is not set, then a callback is temporarily disabled, and should not be invoked\&. \fP"
.ti -1c
.RI "#define \fBEVBUFFER_FLAG_DRAINS_TO_FD\fP 1"
.br
.RI "\fIIf this flag is set, then we will not use \fBevbuffer_peek()\fP, \fBevbuffer_remove()\fP, \fBevbuffer_remove_buffer()\fP, 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)\&. \fP"
.in -1c
.SS "Typedefs"
.in +1c
.ti -1c
.RI "typedef void(* \fBevbuffer_cb_func\fP) (struct \fBevbuffer\fP *buffer, const struct \fBevbuffer_cb_info\fP *info, void *arg)"
.br
.RI "\fIType definition for a callback that is invoked whenever data is added or removed from an evbuffer\&. \fP"
.ti -1c
.RI "typedef void(* \fBevbuffer_file_segment_cleanup_cb\fP) (struct evbuffer_file_segment const *seg, int flags, void *arg)"
.br
.RI "\fIA cleanup function for a evbuffer_file_segment added to an evbuffer for reference\&. \fP"
.ti -1c
.RI "typedef void(* \fBevbuffer_ref_cleanup_cb\fP) (const void *data, size_t datalen, void *extra)"
.br
.RI "\fIA cleanup function for a piece of memory added to an evbuffer by reference\&. \fP"
.in -1c
.SS "Enumerations"
.in +1c
.ti -1c
.RI "enum \fBevbuffer_eol_style\fP { \fBEVBUFFER_EOL_ANY\fP, \fBEVBUFFER_EOL_CRLF\fP, \fBEVBUFFER_EOL_CRLF_STRICT\fP, \fBEVBUFFER_EOL_LF\fP, \fBEVBUFFER_EOL_NUL\fP }
.RI "\fIUsed to tell evbuffer_readln what kind of line-ending to look for\&. \fP""
.br
.ti -1c
.RI "enum \fBevbuffer_ptr_how\fP { \fBEVBUFFER_PTR_SET\fP, \fBEVBUFFER_PTR_ADD\fP }
.RI "\fIDefines how to adjust an \fBevbuffer_ptr\fP by \fBevbuffer_ptr_set()\fP \fP""
.br
.in -1c
.SS "Functions"
.in +1c
.ti -1c
.RI "EVENT2_EXPORT_SYMBOL int \fBevbuffer_add\fP (struct \fBevbuffer\fP *buf, const void *data, size_t datlen)"
.br
.RI "\fIAppend data to the end of an evbuffer\&. \fP"
.ti -1c
.RI "EVENT2_EXPORT_SYMBOL int \fBevbuffer_add_buffer\fP (struct \fBevbuffer\fP *outbuf, struct \fBevbuffer\fP *inbuf)"
.br
.RI "\fIMove all data from one evbuffer into another evbuffer\&. \fP"
.ti -1c
.RI "EVENT2_EXPORT_SYMBOL int \fBevbuffer_add_buffer_reference\fP (struct \fBevbuffer\fP *outbuf, struct \fBevbuffer\fP *inbuf)"
.br
.RI "\fICopy data from one evbuffer into another evbuffer\&. \fP"
.ti -1c
.RI "EVENT2_EXPORT_SYMBOL struct evbuffer_cb_entry * \fBevbuffer_add_cb\fP (struct \fBevbuffer\fP *buffer, \fBevbuffer_cb_func\fP cb, void *cbarg)"
.br
.RI "\fIAdd a new callback to an evbuffer\&. \fP"
.ti -1c
.RI "EVENT2_EXPORT_SYMBOL int \fBevbuffer_add_file\fP (struct \fBevbuffer\fP *outbuf, int fd, ev_off_t offset, ev_off_t length)"
.br
.RI "\fICopy data from a file into the evbuffer for writing to a socket\&. \fP"
.ti -1c
.RI "EVENT2_EXPORT_SYMBOL int \fBevbuffer_add_file_segment\fP (struct \fBevbuffer\fP *buf, struct evbuffer_file_segment *seg, ev_off_t offset, ev_off_t length)"
.br
.RI "\fIInsert some or all of an evbuffer_file_segment at the end of an evbuffer\&. \fP"
.ti -1c
.RI "EVENT2_EXPORT_SYMBOL size_t \fBevbuffer_add_iovec\fP (struct \fBevbuffer\fP *buffer, struct \fBevbuffer_iovec\fP *vec, int n_vec)"
.br
.RI "\fIAppend data from 1 or more iovec's to an evbuffer\&. \fP"
.ti -1c
.RI "EVENT2_EXPORT_SYMBOL int \fBevbuffer_add_printf\fP (struct \fBevbuffer\fP *buf, const char *fmt,\&.\&.\&.)"
.br
.RI "\fIAppend a formatted string to the end of an evbuffer\&. \fP"
.ti -1c
.RI "EVENT2_EXPORT_SYMBOL int \fBevbuffer_add_reference\fP (struct \fBevbuffer\fP *outbuf, const void *data, size_t datlen, \fBevbuffer_ref_cleanup_cb\fP cleanupfn, void *cleanupfn_arg)"
.br
.RI "\fIReference memory into an evbuffer without copying\&. \fP"
.ti -1c
.RI "EVENT2_EXPORT_SYMBOL int \fBevbuffer_add_vprintf\fP (struct \fBevbuffer\fP *buf, const char *fmt, va_list ap)"
.br
.RI "\fIAppend a va_list formatted string to the end of an evbuffer\&. \fP"
.ti -1c
.RI "EVENT2_EXPORT_SYMBOL int \fBevbuffer_cb_clear_flags\fP (struct \fBevbuffer\fP *buffer, struct evbuffer_cb_entry *cb, ev_uint32_t flags)"
.br
.RI "\fIChange the flags that are set for a callback on a buffer by removing some\&. \fP"
.ti -1c
.RI "EVENT2_EXPORT_SYMBOL int \fBevbuffer_cb_set_flags\fP (struct \fBevbuffer\fP *buffer, struct evbuffer_cb_entry *cb, ev_uint32_t flags)"
.br
.RI "\fIChange the flags that are set for a callback on a buffer by adding more\&. \fP"
.ti -1c
.RI "EVENT2_EXPORT_SYMBOL int \fBevbuffer_clear_flags\fP (struct \fBevbuffer\fP *buf, ev_uint64_t flags)"
.br
.RI "\fIChange the flags that are set for an evbuffer by removing some\&. \fP"
.ti -1c
.RI "EVENT2_EXPORT_SYMBOL int \fBevbuffer_commit_space\fP (struct \fBevbuffer\fP *buf, struct \fBevbuffer_iovec\fP *vec, int n_vecs)"
.br
.RI "\fICommits previously reserved space\&. \fP"
.ti -1c
.RI "EVENT2_EXPORT_SYMBOL ev_ssize_t \fBevbuffer_copyout\fP (struct \fBevbuffer\fP *buf, void *data_out, size_t datlen)"
.br
.RI "\fIRead data from an evbuffer, and leave the buffer unchanged\&. \fP"
.ti -1c
.RI "EVENT2_EXPORT_SYMBOL ev_ssize_t \fBevbuffer_copyout_from\fP (struct \fBevbuffer\fP *buf, const struct \fBevbuffer_ptr\fP *pos, void *data_out, size_t datlen)"
.br
.RI "\fIRead data from the middle of an evbuffer, and leave the buffer unchanged\&. \fP"
.ti -1c
.RI "EVENT2_EXPORT_SYMBOL int \fBevbuffer_defer_callbacks\fP (struct \fBevbuffer\fP *buffer, struct \fBevent_base\fP *base)"
.br
.RI "\fIForce all the callbacks on an evbuffer to be run, not immediately after the evbuffer is altered, but instead from inside the event loop\&. \fP"
.ti -1c
.RI "EVENT2_EXPORT_SYMBOL int \fBevbuffer_drain\fP (struct \fBevbuffer\fP *buf, size_t len)"
.br
.RI "\fIRemove a specified number of bytes data from the beginning of an evbuffer\&. \fP"
.ti -1c
.RI "EVENT2_EXPORT_SYMBOL int \fBevbuffer_enable_locking\fP (struct \fBevbuffer\fP *buf, void *lock)"
.br
.RI "\fIEnable locking on an evbuffer so that it can safely be used by multiple threads at the same time\&. \fP"
.ti -1c
.RI "EVENT2_EXPORT_SYMBOL int \fBevbuffer_expand\fP (struct \fBevbuffer\fP *buf, size_t datlen)"
.br
.RI "\fIExpands the available space in an evbuffer\&. \fP"
.ti -1c
.RI "EVENT2_EXPORT_SYMBOL void \fBevbuffer_file_segment_add_cleanup_cb\fP (struct evbuffer_file_segment *seg, \fBevbuffer_file_segment_cleanup_cb\fP cb, void *arg)"
.br
.RI "\fIAdd cleanup callback and argument for the callback to an evbuffer_file_segment\&. \fP"
.ti -1c
.RI "EVENT2_EXPORT_SYMBOL void \fBevbuffer_file_segment_free\fP (struct evbuffer_file_segment *seg)"
.br
.RI "\fIFree an evbuffer_file_segment\&. \fP"
.ti -1c
.RI "EVENT2_EXPORT_SYMBOL struct evbuffer_file_segment * \fBevbuffer_file_segment_new\fP (int fd, ev_off_t offset, ev_off_t length, unsigned flags)"
.br
.RI "\fICreate and return a new evbuffer_file_segment for reading data from a file and sending it out via an evbuffer\&. \fP"
.ti -1c
.RI "EVENT2_EXPORT_SYMBOL void \fBevbuffer_free\fP (struct \fBevbuffer\fP *buf)"
.br
.RI "\fIDeallocate storage for an evbuffer\&. \fP"
.ti -1c
.RI "EVENT2_EXPORT_SYMBOL int \fBevbuffer_freeze\fP (struct \fBevbuffer\fP *buf, int at_front)"
.br
.RI "\fIPrevent calls that modify an evbuffer from succeeding\&. \fP"
.ti -1c
.RI "EVENT2_EXPORT_SYMBOL size_t \fBevbuffer_get_contiguous_space\fP (const struct \fBevbuffer\fP *buf)"
.br
.RI "\fIReturns the number of contiguous available bytes in the first buffer chain\&. \fP"
.ti -1c
.RI "EVENT2_EXPORT_SYMBOL size_t \fBevbuffer_get_length\fP (const struct \fBevbuffer\fP *buf)"
.br
.RI "\fIReturns the total number of bytes stored in the evbuffer\&. \fP"
.ti -1c
.RI "EVENT2_EXPORT_SYMBOL void \fBevbuffer_lock\fP (struct \fBevbuffer\fP *buf)"
.br
.RI "\fIAcquire the lock on an evbuffer\&. \fP"
.ti -1c
.RI "EVENT2_EXPORT_SYMBOL struct \fBevbuffer\fP * \fBevbuffer_new\fP (void)"
.br
.RI "\fIAllocate storage for a new evbuffer\&. \fP"
.ti -1c
.RI "EVENT2_EXPORT_SYMBOL int \fBevbuffer_peek\fP (struct \fBevbuffer\fP *buffer, ev_ssize_t len, struct \fBevbuffer_ptr\fP *start_at, struct \fBevbuffer_iovec\fP *vec_out, int n_vec)"
.br
.RI "\fIFunction to peek at data inside an evbuffer without removing it or copying it out\&. \fP"
.ti -1c
.RI "EVENT2_EXPORT_SYMBOL int \fBevbuffer_prepend\fP (struct \fBevbuffer\fP *buf, const void *data, size_t size)"
.br
.RI "\fIPrepends data to the beginning of the evbuffer\&. \fP"
.ti -1c
.RI "EVENT2_EXPORT_SYMBOL int \fBevbuffer_prepend_buffer\fP (struct \fBevbuffer\fP *dst, struct \fBevbuffer\fP *src)"
.br
.RI "\fIPrepends all data from the src evbuffer to the beginning of the dst evbuffer\&. \fP"
.ti -1c
.RI "EVENT2_EXPORT_SYMBOL int \fBevbuffer_ptr_set\fP (struct \fBevbuffer\fP *buffer, struct \fBevbuffer_ptr\fP *ptr, size_t position, enum \fBevbuffer_ptr_how\fP how)"
.br
.RI "\fISets the search pointer in the buffer to position\&. \fP"
.ti -1c
.RI "EVENT2_EXPORT_SYMBOL unsigned char * \fBevbuffer_pullup\fP (struct \fBevbuffer\fP *buf, ev_ssize_t size)"
.br
.RI "\fIMakes the data at the beginning of an evbuffer contiguous\&. \fP"
.ti -1c
.RI "EVENT2_EXPORT_SYMBOL int \fBevbuffer_read\fP (struct \fBevbuffer\fP *buffer, \fBevutil_socket_t\fP fd, int howmuch)"
.br
.RI "\fIRead from a file descriptor and store the result in an evbuffer\&. \fP"
.ti -1c
.RI "EVENT2_EXPORT_SYMBOL char * \fBevbuffer_readln\fP (struct \fBevbuffer\fP *buffer, size_t *n_read_out, enum \fBevbuffer_eol_style\fP eol_style)"
.br
.RI "\fIRead a single line from an evbuffer\&. \fP"
.ti -1c
.RI "EVENT2_EXPORT_SYMBOL int \fBevbuffer_remove\fP (struct \fBevbuffer\fP *buf, void *data, size_t datlen)"
.br
.RI "\fIRead data from an evbuffer and drain the bytes read\&. \fP"
.ti -1c
.RI "EVENT2_EXPORT_SYMBOL int \fBevbuffer_remove_buffer\fP (struct \fBevbuffer\fP *src, struct \fBevbuffer\fP *dst, size_t datlen)"
.br
.RI "\fIRead data from an evbuffer into another evbuffer, draining the bytes from the source buffer\&. \fP"
.ti -1c
.RI "EVENT2_EXPORT_SYMBOL int \fBevbuffer_remove_cb\fP (struct \fBevbuffer\fP *buffer, \fBevbuffer_cb_func\fP cb, void *cbarg)"
.br
.RI "\fIRemove a callback from an evbuffer, given the function and argument used to add it\&. \fP"
.ti -1c
.RI "EVENT2_EXPORT_SYMBOL int \fBevbuffer_remove_cb_entry\fP (struct \fBevbuffer\fP *buffer, struct evbuffer_cb_entry *ent)"
.br
.RI "\fIRemove a callback from an evbuffer, given a handle returned from evbuffer_add_cb\&. \fP"
.ti -1c
.RI "EVENT2_EXPORT_SYMBOL int \fBevbuffer_reserve_space\fP (struct \fBevbuffer\fP *buf, ev_ssize_t size, struct \fBevbuffer_iovec\fP *vec, int n_vec)"
.br
.RI "\fIReserves space in the last chain or chains of an evbuffer\&. \fP"
.ti -1c
.RI "EVENT2_EXPORT_SYMBOL struct \fBevbuffer_ptr\fP \fBevbuffer_search\fP (struct \fBevbuffer\fP *buffer, const char *what, size_t len, const struct \fBevbuffer_ptr\fP *start)"
.br
.RI "\fISearch for a string within an evbuffer\&. \fP"
.ti -1c
.RI "EVENT2_EXPORT_SYMBOL struct \fBevbuffer_ptr\fP \fBevbuffer_search_eol\fP (struct \fBevbuffer\fP *buffer, struct \fBevbuffer_ptr\fP *start, size_t *eol_len_out, enum \fBevbuffer_eol_style\fP eol_style)"
.br
.RI "\fISearch for an end-of-line string within an evbuffer\&. \fP"
.ti -1c
.RI "EVENT2_EXPORT_SYMBOL struct \fBevbuffer_ptr\fP \fBevbuffer_search_range\fP (struct \fBevbuffer\fP *buffer, const char *what, size_t len, const struct \fBevbuffer_ptr\fP *start, const struct \fBevbuffer_ptr\fP *end)"
.br
.RI "\fISearch for a string within part of an evbuffer\&. \fP"
.ti -1c
.RI "EVENT2_EXPORT_SYMBOL int \fBevbuffer_set_flags\fP (struct \fBevbuffer\fP *buf, ev_uint64_t flags)"
.br
.RI "\fIChange the flags that are set for an evbuffer by adding more\&. \fP"
.ti -1c
.RI "EVENT2_EXPORT_SYMBOL int \fBevbuffer_unfreeze\fP (struct \fBevbuffer\fP *buf, int at_front)"
.br
.RI "\fIRe-enable calls that modify an evbuffer\&. \fP"
.ti -1c
.RI "EVENT2_EXPORT_SYMBOL void \fBevbuffer_unlock\fP (struct \fBevbuffer\fP *buf)"
.br
.RI "\fIRelease the lock on an evbuffer\&. \fP"
.ti -1c
.RI "EVENT2_EXPORT_SYMBOL int \fBevbuffer_write\fP (struct \fBevbuffer\fP *buffer, \fBevutil_socket_t\fP fd)"
.br
.RI "\fIWrite the contents of an evbuffer to a file descriptor\&. \fP"
.ti -1c
.RI "EVENT2_EXPORT_SYMBOL int \fBevbuffer_write_atmost\fP (struct \fBevbuffer\fP *buffer, \fBevutil_socket_t\fP fd, ev_ssize_t howmuch)"
.br
.RI "\fIWrite some of the contents of an evbuffer to a file descriptor\&. \fP"
.in -1c
.SH "Detailed Description"
.PP
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\&.
.PP
A new evbuffer can be allocated with \fBevbuffer_new()\fP, and can be freed with \fBevbuffer_free()\fP\&. Most users will be using evbuffers via the bufferevent interface\&. To access a bufferevent's evbuffers, use \fBbufferevent_get_input()\fP and \fBbufferevent_get_output()\fP\&.
.PP
There are several guidelines for using evbuffers\&.
.PP
.IP "\(bu" 2
if you already know how much data you are going to add as a result of calling \fBevbuffer_add()\fP multiple times, it makes sense to use \fBevbuffer_expand()\fP first to make sure that enough memory is allocated before hand\&.
.IP "\(bu" 2
\fBevbuffer_add_buffer()\fP adds the contents of one buffer to the other without incurring any unnecessary memory copies\&.
.IP "\(bu" 2
\fBevbuffer_add()\fP and \fBevbuffer_add_buffer()\fP do not mix very well: if you use them, you will wind up with fragmented memory in your buffer\&.
.IP "\(bu" 2
For high-performance code, you may want to avoid copying data into and out of buffers\&. You can skip the copy step by using \fBevbuffer_reserve_space()\fP/evbuffer_commit_space() when writing into a buffer, and \fBevbuffer_peek()\fP when reading\&.
.PP
.PP
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\&.
.PP
As the contents of an evbuffer can be stored in multiple different memory blocks, it cannot be accessed directly\&. Instead, \fBevbuffer_pullup()\fP 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 \fBevbuffer_peek()\fP if you don't require that the memory to be contiguous\&.
.SH "Macro Definition Documentation"
.PP
.SS "#define EVBUF_FS_DISABLE_LOCKING 0x08"
.PP
Flag for creating evbuffer_file_segment: Do not allocate a lock for this segment\&. If this option is set, then neither the segment nor any evbuffer it is added to may ever be accessed from more than one thread at a time\&.
.SS "#define EVBUF_FS_DISABLE_SENDFILE 0x04"
.PP
Flag for creating evbuffer_file_segment: Disable direct fd-to-fd implementations (including sendfile and splice)\&. You might want to use this option if data needs to be taken from the evbuffer by any means other than writing it to the network: the sendfile backend is fast, but it only works for sending files directly to the network\&.
.SS "#define EVBUFFER_CB_ENABLED 1"
.PP
If this flag is not set, then a callback is temporarily disabled, and should not be invoked\&.
.PP
\fBSee also:\fP
.RS 4
\fBevbuffer_cb_set_flags()\fP, \fBevbuffer_cb_clear_flags()\fP
.RE
.PP
.SS "#define EVBUFFER_FLAG_DRAINS_TO_FD 1"
.PP
If this flag is set, then we will not use \fBevbuffer_peek()\fP, \fBevbuffer_remove()\fP, \fBevbuffer_remove_buffer()\fP, 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)\&. Using this option allows the implementation to use sendfile-based operations for \fBevbuffer_add_file()\fP; see that function for more information\&.
.PP
This flag is on by default for bufferevents that can take advantage of it; you should never actually need to set it on a bufferevent's output buffer\&.
.SH "Typedef Documentation"
.PP
.SS "typedef void(* evbuffer_cb_func) (struct \fBevbuffer\fP *buffer, const struct \fBevbuffer_cb_info\fP *info, void *arg)"
.PP
Type definition for a callback that is invoked whenever data is added or removed from an evbuffer\&. An evbuffer may have one or more callbacks set at a time\&. The order in which they are executed is undefined\&.
.PP
A callback function may add more callbacks, or remove itself from the list of callbacks, or add or remove data from the buffer\&. It may not remove another callback from the list\&.
.PP
If a callback adds or removes data from the buffer or from another buffer, this can cause a recursive invocation of your callback or other callbacks\&. If you ask for an infinite loop, you might just get one: watch out!
.PP
\fBParameters:\fP
.RS 4
\fIbuffer\fP the buffer whose size has changed
.br
\fIinfo\fP a structure describing how the buffer changed\&.
.br
\fIarg\fP a pointer to user data
.RE
.PP
.SS "typedef void(* evbuffer_ref_cleanup_cb) (const void *data, size_t datalen, void *extra)"
.PP
A cleanup function for a piece of memory added to an evbuffer by reference\&.
.PP
\fBSee also:\fP
.RS 4
\fBevbuffer_add_reference()\fP
.RE
.PP
.SH "Enumeration Type Documentation"
.PP
.SS "enum \fBevbuffer_eol_style\fP"
.PP
Used to tell evbuffer_readln what kind of line-ending to look for\&.
.PP
\fBEnumerator\fP
.in +1c
.TP
\fB\fIEVBUFFER_EOL_ANY \fP\fP
Any sequence of CR and LF characters is acceptable as an EOL\&. Note that this style can produce ambiguous results: the sequence 'CRLF' will be treated as a single EOL if it is all in the buffer at once, but if you first read a CR from the network and later read an LF from the network, it will be treated as two EOLs\&.
.TP
\fB\fIEVBUFFER_EOL_CRLF \fP\fP
An EOL is an LF, optionally preceded by a CR\&. This style is most useful for implementing text-based internet protocols\&.
.TP
\fB\fIEVBUFFER_EOL_CRLF_STRICT \fP\fP
An EOL is a CR followed by an LF\&.
.TP
\fB\fIEVBUFFER_EOL_LF \fP\fP
An EOL is a LF\&.
.TP
\fB\fIEVBUFFER_EOL_NUL \fP\fP
An EOL is a NUL character (that is, a single byte with value 0)
.SS "enum \fBevbuffer_ptr_how\fP"
.PP
Defines how to adjust an \fBevbuffer_ptr\fP by \fBevbuffer_ptr_set()\fP
.PP
\fBSee also:\fP
.RS 4
\fBevbuffer_ptr_set()\fP
.RE
.PP
.PP
\fBEnumerator\fP
.in +1c
.TP
\fB\fIEVBUFFER_PTR_SET \fP\fP
Sets the pointer to the position; can be called on with an uninitialized \fBevbuffer_ptr\fP\&.
.TP
\fB\fIEVBUFFER_PTR_ADD \fP\fP
Advances the pointer by adding to the current position\&.
.SH "Function Documentation"
.PP
.SS "EVENT2_EXPORT_SYMBOL int evbuffer_add (struct \fBevbuffer\fP * buf, const void * data, size_t datlen)"
.PP
Append data to the end of an evbuffer\&.
.PP
\fBParameters:\fP
.RS 4
\fIbuf\fP the evbuffer to be appended to
.br
\fIdata\fP pointer to the beginning of the data buffer
.br
\fIdatlen\fP the number of bytes to be copied from the data buffer
.RE
.PP
\fBReturns:\fP
.RS 4
0 on success, -1 on failure\&.
.RE
.PP
.SS "EVENT2_EXPORT_SYMBOL int evbuffer_add_buffer (struct \fBevbuffer\fP * outbuf, struct \fBevbuffer\fP * inbuf)"
.PP
Move all data from one evbuffer into another evbuffer\&. This is a destructive add\&. The data from one buffer moves into the other buffer\&. However, no unnecessary memory copies occur\&.
.PP
\fBParameters:\fP
.RS 4
\fIoutbuf\fP the output buffer
.br
\fIinbuf\fP the input buffer
.RE
.PP
\fBReturns:\fP
.RS 4
0 if successful, or -1 if an error occurred
.RE
.PP
\fBSee also:\fP
.RS 4
\fBevbuffer_remove_buffer()\fP
.RE
.PP
.SS "EVENT2_EXPORT_SYMBOL int evbuffer_add_buffer_reference (struct \fBevbuffer\fP * outbuf, struct \fBevbuffer\fP * inbuf)"
.PP
Copy data from one evbuffer into another evbuffer\&. This is a non-destructive add\&. The data from one buffer is copied into the other buffer\&. However, no unnecessary memory copies occur\&.
.PP
Note that buffers already containing buffer references can't be added to other buffers\&.
.PP
\fBParameters:\fP
.RS 4
\fIoutbuf\fP the output buffer
.br
\fIinbuf\fP the input buffer
.RE
.PP
\fBReturns:\fP
.RS 4
0 if successful, or -1 if an error occurred
.RE
.PP
.SS "EVENT2_EXPORT_SYMBOL struct evbuffer_cb_entry* evbuffer_add_cb (struct \fBevbuffer\fP * buffer, \fBevbuffer_cb_func\fP cb, void * cbarg)"
.PP
Add a new callback to an evbuffer\&. Subsequent calls to \fBevbuffer_add_cb()\fP add new callbacks\&. To remove this callback, call evbuffer_remove_cb or evbuffer_remove_cb_entry\&.
.PP
\fBParameters:\fP
.RS 4
\fIbuffer\fP the evbuffer to be monitored
.br
\fIcb\fP the callback function to invoke when the evbuffer is modified, or NULL to remove all callbacks\&.
.br
\fIcbarg\fP an argument to be provided to the callback function
.RE
.PP
\fBReturns:\fP
.RS 4
a handle to the callback on success, or NULL on failure\&.
.RE
.PP
.SS "EVENT2_EXPORT_SYMBOL int evbuffer_add_file (struct \fBevbuffer\fP * outbuf, int fd, ev_off_t offset, ev_off_t length)"
.PP
Copy data from a file into the evbuffer for writing to a socket\&. This function avoids unnecessary data copies between userland and kernel\&. If sendfile is available and the EVBUFFER_FLAG_DRAINS_TO_FD flag is set, it uses those functions\&. Otherwise, it tries to use mmap (or CreateFileMapping on Windows)\&.
.PP
The function owns the resulting file descriptor and will close it when finished transferring data\&.
.PP
The results of using \fBevbuffer_remove()\fP or \fBevbuffer_pullup()\fP on evbuffers whose data was added using this function are undefined\&.
.PP
For more fine-grained control, use evbuffer_add_file_segment\&.
.PP
\fBParameters:\fP
.RS 4
\fIoutbuf\fP the output buffer
.br
\fIfd\fP the file descriptor
.br
\fIoffset\fP the offset from which to read data
.br
\fIlength\fP how much data to read, or -1 to read as much as possible\&. (-1 requires that 'fd' support fstat\&.)
.RE
.PP
\fBReturns:\fP
.RS 4
0 if successful, or -1 if an error occurred
.RE
.PP
.SS "EVENT2_EXPORT_SYMBOL int evbuffer_add_file_segment (struct \fBevbuffer\fP * buf, struct evbuffer_file_segment * seg, ev_off_t offset, ev_off_t length)"
.PP
Insert some or all of an evbuffer_file_segment at the end of an evbuffer\&. Note that the offset and length parameters of this function have a different meaning from those provided to evbuffer_file_segment_new: When you create the segment, the offset is the offset \fIwithin the file\fP, and the length is the length \fIof the segment\fP, whereas when you add a segment to an evbuffer, the offset is \fIwithin the segment\fP and the length is the length of the _part of the segment you want to use\&.
.PP
In other words, if you have a 10 KiB file, and you create an evbuffer_file_segment for it with offset 20 and length 1000, it will refer to bytes 20\&.\&.1019 inclusive\&. If you then pass this segment to evbuffer_add_file_segment and specify an offset of 20 and a length of 50, you will be adding bytes 40\&.\&.99 inclusive\&.
.PP
\fBParameters:\fP
.RS 4
\fIbuf\fP the evbuffer to append to
.br
\fIseg\fP the segment to add
.br
\fIoffset\fP the offset within the segment to start from
.br
\fIlength\fP the amount of data to add, or -1 to add it all\&.
.RE
.PP
\fBReturns:\fP
.RS 4
0 on success, -1 on failure\&.
.RE
.PP
.SS "EVENT2_EXPORT_SYMBOL size_t evbuffer_add_iovec (struct \fBevbuffer\fP * buffer, struct \fBevbuffer_iovec\fP * vec, int n_vec)"
.PP
Append data from 1 or more iovec's to an evbuffer\&. Calculates the number of bytes needed for an iovec structure and guarantees all data will fit into a single chain\&. Can be used in lieu of functionality which calls \fBevbuffer_add()\fP constantly before being used to increase performance\&.
.PP
\fBParameters:\fP
.RS 4
\fIbuffer\fP the destination buffer
.br
\fIvec\fP the source iovec
.br
\fIn_vec\fP the number of iovec structures\&.
.RE
.PP
\fBReturns:\fP
.RS 4
the number of bytes successfully written to the output buffer\&.
.RE
.PP
.SS "EVENT2_EXPORT_SYMBOL int evbuffer_add_printf (struct \fBevbuffer\fP * buf, const char * fmt, \&.\&.\&.)"
.PP
Append a formatted string to the end of an evbuffer\&. The string is formated as printf\&.
.PP
\fBParameters:\fP
.RS 4
\fIbuf\fP the evbuffer that will be appended to
.br
\fIfmt\fP a format string
.br
\fI\&.\&.\&.\fP arguments that will be passed to printf(3)
.RE
.PP
\fBReturns:\fP
.RS 4
The number of bytes added if successful, or -1 if an error occurred\&.
.RE
.PP
\fBSee also:\fP
.RS 4
evutil_printf(), \fBevbuffer_add_vprintf()\fP
.RE
.PP
.SS "EVENT2_EXPORT_SYMBOL int evbuffer_add_reference (struct \fBevbuffer\fP * outbuf, const void * data, size_t datlen, \fBevbuffer_ref_cleanup_cb\fP cleanupfn, void * cleanupfn_arg)"
.PP
Reference memory into an evbuffer without copying\&. The memory needs to remain valid until all the added data has been read\&. This function keeps just a reference to the memory without actually incurring the overhead of a copy\&.
.PP
\fBParameters:\fP
.RS 4
\fIoutbuf\fP the output buffer
.br
\fIdata\fP the memory to reference
.br
\fIdatlen\fP how memory to reference
.br
\fIcleanupfn\fP callback to be invoked when the memory is no longer referenced by this evbuffer\&.
.br
\fIcleanupfn_arg\fP optional argument to the cleanup callback
.RE
.PP
\fBReturns:\fP
.RS 4
0 if successful, or -1 if an error occurred
.RE
.PP
.SS "EVENT2_EXPORT_SYMBOL int evbuffer_add_vprintf (struct \fBevbuffer\fP * buf, const char * fmt, va_list ap)"
.PP
Append a va_list formatted string to the end of an evbuffer\&.
.PP
\fBParameters:\fP
.RS 4
\fIbuf\fP the evbuffer that will be appended to
.br
\fIfmt\fP a format string
.br
\fIap\fP a varargs va_list argument array that will be passed to vprintf(3)
.RE
.PP
\fBReturns:\fP
.RS 4
The number of bytes added if successful, or -1 if an error occurred\&.
.RE
.PP
.SS "EVENT2_EXPORT_SYMBOL int evbuffer_cb_clear_flags (struct \fBevbuffer\fP * buffer, struct evbuffer_cb_entry * cb, ev_uint32_t flags)"
.PP
Change the flags that are set for a callback on a buffer by removing some\&.
.PP
\fBParameters:\fP
.RS 4
\fIbuffer\fP the evbuffer that the callback is watching\&.
.br
\fIcb\fP the callback whose status we want to change\&.
.br
\fIflags\fP EVBUFFER_CB_ENABLED to disable the callback\&.
.RE
.PP
\fBReturns:\fP
.RS 4
0 on success, -1 on failure\&.
.RE
.PP
.SS "EVENT2_EXPORT_SYMBOL int evbuffer_cb_set_flags (struct \fBevbuffer\fP * buffer, struct evbuffer_cb_entry * cb, ev_uint32_t flags)"
.PP
Change the flags that are set for a callback on a buffer by adding more\&.
.PP
\fBParameters:\fP
.RS 4
\fIbuffer\fP the evbuffer that the callback is watching\&.
.br
\fIcb\fP the callback whose status we want to change\&.
.br
\fIflags\fP EVBUFFER_CB_ENABLED to re-enable the callback\&.
.RE
.PP
\fBReturns:\fP
.RS 4
0 on success, -1 on failure\&.
.RE
.PP
.SS "EVENT2_EXPORT_SYMBOL int evbuffer_clear_flags (struct \fBevbuffer\fP * buf, ev_uint64_t flags)"
.PP
Change the flags that are set for an evbuffer by removing some\&.
.PP
\fBParameters:\fP
.RS 4
\fIbuffer\fP the evbuffer that the callback is watching\&.
.br
\fIcb\fP the callback whose status we want to change\&.
.br
\fIflags\fP One or more EVBUFFER_FLAG_* options
.RE
.PP
\fBReturns:\fP
.RS 4
0 on success, -1 on failure\&.
.RE
.PP
.SS "EVENT2_EXPORT_SYMBOL int evbuffer_commit_space (struct \fBevbuffer\fP * buf, struct \fBevbuffer_iovec\fP * vec, int n_vecs)"
.PP
Commits previously reserved space\&. Commits some of the space previously reserved with \fBevbuffer_reserve_space()\fP\&. It then becomes available for reading\&.
.PP
This function may return an error if the pointer in the extents do not match those returned from evbuffer_reserve_space, or if data has been added to the buffer since the space was reserved\&.
.PP
If you want to commit less data than you got reserved space for, modify the iov_len pointer of the appropriate extent to a smaller value\&. Note that you may have received more space than you requested if it was available!
.PP
\fBParameters:\fP
.RS 4
\fIbuf\fP the evbuffer in which to reserve space\&.
.br
\fIvec\fP one or two extents returned by evbuffer_reserve_space\&.
.br
\fIn_vecs\fP the number of extents\&.
.RE
.PP
\fBReturns:\fP
.RS 4
0 on success, -1 on error
.RE
.PP
\fBSee also:\fP
.RS 4
\fBevbuffer_reserve_space()\fP
.RE
.PP
.SS "EVENT2_EXPORT_SYMBOL ev_ssize_t evbuffer_copyout (struct \fBevbuffer\fP * buf, void * data_out, size_t datlen)"
.PP
Read data from an evbuffer, and leave the buffer unchanged\&. If more bytes are requested than are available in the evbuffer, we only extract as many bytes as were available\&.
.PP
\fBParameters:\fP
.RS 4
\fIbuf\fP the evbuffer to be read from
.br
\fIdata_out\fP the destination buffer to store the result
.br
\fIdatlen\fP the maximum size of the destination buffer
.RE
.PP
\fBReturns:\fP
.RS 4
the number of bytes read, or -1 if we can't drain the buffer\&.
.RE
.PP
.SS "EVENT2_EXPORT_SYMBOL ev_ssize_t evbuffer_copyout_from (struct \fBevbuffer\fP * buf, const struct \fBevbuffer_ptr\fP * pos, void * data_out, size_t datlen)"
.PP
Read data from the middle of an evbuffer, and leave the buffer unchanged\&. If more bytes are requested than are available in the evbuffer, we only extract as many bytes as were available\&.
.PP
\fBParameters:\fP
.RS 4
\fIbuf\fP the evbuffer to be read from
.br
\fIpos\fP the position to start reading from
.br
\fIdata_out\fP the destination buffer to store the result
.br
\fIdatlen\fP the maximum size of the destination buffer
.RE
.PP
\fBReturns:\fP
.RS 4
the number of bytes read, or -1 if we can't drain the buffer\&.
.RE
.PP
.SS "EVENT2_EXPORT_SYMBOL int evbuffer_defer_callbacks (struct \fBevbuffer\fP * buffer, struct \fBevent_base\fP * base)"
.PP
Force all the callbacks on an evbuffer to be run, not immediately after the evbuffer is altered, but instead from inside the event loop\&. This can be used to serialize all the callbacks to a single thread of execution\&.
.SS "EVENT2_EXPORT_SYMBOL int evbuffer_drain (struct \fBevbuffer\fP * buf, size_t len)"
.PP
Remove a specified number of bytes data from the beginning of an evbuffer\&.
.PP
\fBParameters:\fP
.RS 4
\fIbuf\fP the evbuffer to be drained
.br
\fIlen\fP the number of bytes to drain from the beginning of the buffer
.RE
.PP
\fBReturns:\fP
.RS 4
0 on success, -1 on failure\&.
.RE
.PP
.SS "EVENT2_EXPORT_SYMBOL int evbuffer_enable_locking (struct \fBevbuffer\fP * buf, void * lock)"
.PP
Enable locking on an evbuffer so that it can safely be used by multiple threads at the same time\&. NOTE: when locking is enabled, the lock will be held when callbacks are invoked\&. This could result in deadlock if you aren't careful\&. Plan accordingly!
.PP
\fBParameters:\fP
.RS 4
\fIbuf\fP An evbuffer to make lockable\&.
.br
\fIlock\fP A lock object, or NULL if we should allocate our own\&.
.RE
.PP
\fBReturns:\fP
.RS 4
0 on success, -1 on failure\&.
.RE
.PP
.SS "EVENT2_EXPORT_SYMBOL int evbuffer_expand (struct \fBevbuffer\fP * buf, size_t datlen)"
.PP
Expands the available space in an evbuffer\&. Expands the available space in the evbuffer to at least datlen, so that appending datlen additional bytes will not require any new allocations\&.
.PP
\fBParameters:\fP
.RS 4
\fIbuf\fP the evbuffer to be expanded
.br
\fIdatlen\fP the new minimum length requirement
.RE
.PP
\fBReturns:\fP
.RS 4
0 if successful, or -1 if an error occurred
.RE
.PP
.SS "EVENT2_EXPORT_SYMBOL void evbuffer_file_segment_add_cleanup_cb (struct evbuffer_file_segment * seg, \fBevbuffer_file_segment_cleanup_cb\fP cb, void * arg)"
.PP
Add cleanup callback and argument for the callback to an evbuffer_file_segment\&. The cleanup callback will be invoked when no more references to the evbuffer_file_segment exist\&.
.SS "EVENT2_EXPORT_SYMBOL void evbuffer_file_segment_free (struct evbuffer_file_segment * seg)"
.PP
Free an evbuffer_file_segment\&. It is safe to call this function even if the segment has been added to one or more evbuffers\&. The evbuffer_file_segment will not be freed until no more references to it exist\&.
.SS "EVENT2_EXPORT_SYMBOL struct evbuffer_file_segment* evbuffer_file_segment_new (int fd, ev_off_t offset, ev_off_t length, unsigned flags)"
.PP
Create and return a new evbuffer_file_segment for reading data from a file and sending it out via an evbuffer\&. This function avoids unnecessary data copies between userland and kernel\&. Where available, it uses sendfile or splice\&.
.PP
The file descriptor must not be closed so long as any evbuffer is using this segment\&.
.PP
The results of using \fBevbuffer_remove()\fP or \fBevbuffer_pullup()\fP or any other function that reads bytes from an evbuffer on any evbuffer containing the newly returned segment are undefined, unless you pass the EVBUF_FS_DISABLE_SENDFILE flag to this function\&.
.PP
\fBParameters:\fP
.RS 4
\fIfd\fP an open file to read from\&.
.br
\fIoffset\fP an index within the file at which to start reading
.br
\fIlength\fP how much data to read, or -1 to read as much as possible\&. (-1 requires that 'fd' support fstat\&.)
.br
\fIflags\fP any number of the EVBUF_FS_* flags
.RE
.PP
\fBReturns:\fP
.RS 4
a new evbuffer_file_segment, or NULL on failure\&.
.RE
.PP
.SS "EVENT2_EXPORT_SYMBOL void evbuffer_free (struct \fBevbuffer\fP * buf)"
.PP
Deallocate storage for an evbuffer\&.
.PP
\fBParameters:\fP
.RS 4
\fIbuf\fP pointer to the evbuffer to be freed
.RE
.PP
.SS "EVENT2_EXPORT_SYMBOL int evbuffer_freeze (struct \fBevbuffer\fP * buf, int at_front)"
.PP
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\&.
.PP
If the front of a buffer is frozen, operations that drain data from the front of the buffer, or that prepend data to the buffer, will fail until it is unfrozen\&. If the back a buffer is frozen, operations that append data from the buffer will fail until it is unfrozen\&.
.PP
\fBParameters:\fP
.RS 4
\fIbuf\fP The buffer to freeze
.br
\fIat_front\fP If true, we freeze the front of the buffer\&. If false, we freeze the back\&.
.RE
.PP
\fBReturns:\fP
.RS 4
0 on success, -1 on failure\&.
.RE
.PP
.SS "EVENT2_EXPORT_SYMBOL size_t evbuffer_get_contiguous_space (const struct \fBevbuffer\fP * buf)"
.PP
Returns the number of contiguous available bytes in the first buffer chain\&. This is useful when processing data that might be split into multiple chains, or that might all be in the first chain\&. Calls to \fBevbuffer_pullup()\fP that cause reallocation and copying of data can thus be avoided\&.
.PP
\fBParameters:\fP
.RS 4
\fIbuf\fP pointer to the evbuffer
.RE
.PP
\fBReturns:\fP
.RS 4
0 if no data is available, otherwise the number of available bytes in the first buffer chain\&.
.RE
.PP
.SS "EVENT2_EXPORT_SYMBOL size_t evbuffer_get_length (const struct \fBevbuffer\fP * buf)"
.PP
Returns the total number of bytes stored in the evbuffer\&.
.PP
\fBParameters:\fP
.RS 4
\fIbuf\fP pointer to the evbuffer
.RE
.PP
\fBReturns:\fP
.RS 4
the number of bytes stored in the evbuffer
.RE
.PP
.SS "EVENT2_EXPORT_SYMBOL void evbuffer_lock (struct \fBevbuffer\fP * buf)"
.PP
Acquire the lock on an evbuffer\&. Has no effect if locking was not enabled with evbuffer_enable_locking\&.
.SS "EVENT2_EXPORT_SYMBOL struct \fBevbuffer\fP* evbuffer_new (void)"
.PP
Allocate storage for a new evbuffer\&.
.PP
\fBReturns:\fP
.RS 4
a pointer to a newly allocated evbuffer struct, or NULL if an error occurred
.RE
.PP
.SS "EVENT2_EXPORT_SYMBOL int evbuffer_peek (struct \fBevbuffer\fP * buffer, ev_ssize_t len, struct \fBevbuffer_ptr\fP * start_at, struct \fBevbuffer_iovec\fP * vec_out, int n_vec)"
.PP
Function to peek at data inside an evbuffer without removing it or copying it out\&. Pointers to the data are returned by filling the 'vec_out' array with pointers to one or more extents of data inside the buffer\&.
.PP
The total data in the extents that you get back may be more than you requested (if there is more data last extent than you asked for), or less (if you do not provide enough evbuffer_iovecs, or if the buffer does not have as much data as you asked to see)\&.
.PP
\fBParameters:\fP
.RS 4
\fIbuffer\fP the evbuffer to peek into,
.br
\fIlen\fP the number of bytes to try to peek\&. If len is negative, we will try to fill as much of vec_out as we can\&. If len is negative and vec_out is not provided, we return the number of evbuffer_iovecs that would be needed to get all the data in the buffer\&.
.br
\fIstart_at\fP an \fBevbuffer_ptr\fP indicating the point at which we should start looking for data\&. NULL means, 'At the start of the
buffer\&.'
.br
\fIvec_out\fP an array of \fBevbuffer_iovec\fP
.br
\fIn_vec\fP the length of vec_out\&. If 0, we only count how many extents would be necessary to point to the requested amount of data\&.
.RE
.PP
\fBReturns:\fP
.RS 4
The number of extents needed\&. This may be less than n_vec if we didn't need all the evbuffer_iovecs we were given, or more than n_vec if we would need more to return all the data that was requested\&.
.RE
.PP
.SS "EVENT2_EXPORT_SYMBOL int evbuffer_prepend (struct \fBevbuffer\fP * buf, const void * data, size_t size)"
.PP
Prepends data to the beginning of the evbuffer\&.
.PP
\fBParameters:\fP
.RS 4
\fIbuf\fP the evbuffer to which to prepend data
.br
\fIdata\fP a pointer to the memory to prepend
.br
\fIsize\fP the number of bytes to prepend
.RE
.PP
\fBReturns:\fP
.RS 4
0 if successful, or -1 otherwise
.RE
.PP
.SS "EVENT2_EXPORT_SYMBOL int evbuffer_prepend_buffer (struct \fBevbuffer\fP * dst, struct \fBevbuffer\fP * src)"
.PP
Prepends all data from the src evbuffer to the beginning of the dst evbuffer\&.
.PP
\fBParameters:\fP
.RS 4
\fIdst\fP the evbuffer to which to prepend data
.br
\fIsrc\fP the evbuffer to prepend; it will be emptied as a result
.RE
.PP
\fBReturns:\fP
.RS 4
0 if successful, or -1 otherwise
.RE
.PP
.SS "EVENT2_EXPORT_SYMBOL int evbuffer_ptr_set (struct \fBevbuffer\fP * buffer, struct \fBevbuffer_ptr\fP * ptr, size_t position, enum \fBevbuffer_ptr_how\fP how)"
.PP
Sets the search pointer in the buffer to position\&. There are two ways to use this function: you can call evbuffer_ptr_set(buf, &pos, N, EVBUFFER_PTR_SET) to move 'pos' to a position 'N' bytes after the start of the buffer, or evbuffer_ptr_set(buf, &pos, N, EVBUFFER_PTR_ADD) to move 'pos' forward by 'N' bytes\&.
.PP
If \fBevbuffer_ptr\fP is not initialized, this function can only be called with EVBUFFER_PTR_SET\&.
.PP
An \fBevbuffer_ptr\fP can represent any position from the start of the buffer to a position immediately after the end of the buffer\&.
.PP
\fBParameters:\fP
.RS 4
\fIbuffer\fP the evbuffer to be search
.br
\fIptr\fP a pointer to a struct \fBevbuffer_ptr\fP
.br
\fIposition\fP the position at which to start the next search
.br
\fIhow\fP determines how the pointer should be manipulated\&.
.RE
.PP
\fBReturns:\fP
.RS 4
0 on success or -1 otherwise
.RE
.PP
.SS "EVENT2_EXPORT_SYMBOL unsigned char* evbuffer_pullup (struct \fBevbuffer\fP * buf, ev_ssize_t size)"
.PP
Makes the data at the beginning of an evbuffer contiguous\&.
.PP
\fBParameters:\fP
.RS 4
\fIbuf\fP the evbuffer to make contiguous
.br
\fIsize\fP the number of bytes to make contiguous, or -1 to make the entire buffer contiguous\&.
.RE
.PP
\fBReturns:\fP
.RS 4
a pointer to the contiguous memory array, or NULL if param size requested more data than is present in the buffer\&.
.RE
.PP
.SS "EVENT2_EXPORT_SYMBOL int evbuffer_read (struct \fBevbuffer\fP * buffer, \fBevutil_socket_t\fP fd, int howmuch)"
.PP
Read from a file descriptor and store the result in an evbuffer\&.
.PP
\fBParameters:\fP
.RS 4
\fIbuffer\fP the evbuffer to store the result
.br
\fIfd\fP the file descriptor to read from
.br
\fIhowmuch\fP the number of bytes to be read
.RE
.PP
\fBReturns:\fP
.RS 4
the number of bytes read, or -1 if an error occurred
.RE
.PP
\fBSee also:\fP
.RS 4
\fBevbuffer_write()\fP
.RE
.PP
.SS "EVENT2_EXPORT_SYMBOL char* evbuffer_readln (struct \fBevbuffer\fP * buffer, size_t * n_read_out, enum \fBevbuffer_eol_style\fP eol_style)"
.PP
Read a single line from an evbuffer\&. Reads a line terminated by an EOL as determined by the evbuffer_eol_style argument\&. Returns a newly allocated nul-terminated string; the caller must free the returned value\&. The EOL is not included in the returned string\&.
.PP
\fBParameters:\fP
.RS 4
\fIbuffer\fP the evbuffer to read from
.br
\fIn_read_out\fP if non-NULL, points to a size_t that is set to the number of characters in the returned string\&. This is useful for strings that can contain NUL characters\&.
.br
\fIeol_style\fP the style of line-ending to use\&.
.RE
.PP
\fBReturns:\fP
.RS 4
pointer to a single line, or NULL if an error occurred
.RE
.PP
.SS "EVENT2_EXPORT_SYMBOL int evbuffer_remove (struct \fBevbuffer\fP * buf, void * data, size_t datlen)"
.PP
Read data from an evbuffer and drain the bytes read\&. If more bytes are requested than are available in the evbuffer, we only extract as many bytes as were available\&.
.PP
\fBParameters:\fP
.RS 4
\fIbuf\fP the evbuffer to be read from
.br
\fIdata\fP the destination buffer to store the result
.br
\fIdatlen\fP the maximum size of the destination buffer
.RE
.PP
\fBReturns:\fP
.RS 4
the number of bytes read, or -1 if we can't drain the buffer\&.
.RE
.PP
.SS "EVENT2_EXPORT_SYMBOL int evbuffer_remove_buffer (struct \fBevbuffer\fP * src, struct \fBevbuffer\fP * dst, size_t datlen)"
.PP
Read data from an evbuffer into another evbuffer, draining the bytes from the source buffer\&. This function avoids copy operations to the extent possible\&.
.PP
If more bytes are requested than are available in src, the src buffer is drained completely\&.
.PP
\fBParameters:\fP
.RS 4
\fIsrc\fP the evbuffer to be read from
.br
\fIdst\fP the destination evbuffer to store the result into
.br
\fIdatlen\fP the maximum numbers of bytes to transfer
.RE
.PP
\fBReturns:\fP
.RS 4
the number of bytes read
.RE
.PP
.SS "EVENT2_EXPORT_SYMBOL int evbuffer_remove_cb (struct \fBevbuffer\fP * buffer, \fBevbuffer_cb_func\fP cb, void * cbarg)"
.PP
Remove a callback from an evbuffer, given the function and argument used to add it\&.
.PP
\fBReturns:\fP
.RS 4
0 if a callback was removed, or -1 if no matching callback was found\&.
.RE
.PP
.SS "EVENT2_EXPORT_SYMBOL int evbuffer_remove_cb_entry (struct \fBevbuffer\fP * buffer, struct evbuffer_cb_entry * ent)"
.PP
Remove a callback from an evbuffer, given a handle returned from evbuffer_add_cb\&. Calling this function invalidates the handle\&.
.PP
\fBReturns:\fP
.RS 4
0 if a callback was removed, or -1 if no matching callback was found\&.
.RE
.PP
.SS "EVENT2_EXPORT_SYMBOL int evbuffer_reserve_space (struct \fBevbuffer\fP * buf, ev_ssize_t size, struct \fBevbuffer_iovec\fP * vec, int n_vec)"
.PP
Reserves space in the last chain or chains of an evbuffer\&. Makes space available in the last chain or chains of an evbuffer that can be arbitrarily written to by a user\&. The space does not become available for reading until it has been committed with \fBevbuffer_commit_space()\fP\&.
.PP
The space is made available as one or more extents, represented by an initial pointer and a length\&. You can force the memory to be available as only one extent\&. Allowing more extents, however, makes the function more efficient\&.
.PP
Multiple subsequent calls to this function will make the same space available until \fBevbuffer_commit_space()\fP has been called\&.
.PP
It is an error to do anything that moves around the buffer's internal memory structures before committing the space\&.
.PP
NOTE: The code currently does not ever use more than two extents\&. This may change in future versions\&.
.PP
\fBParameters:\fP
.RS 4
\fIbuf\fP the evbuffer in which to reserve space\&.
.br
\fIsize\fP how much space to make available, at minimum\&. The total length of the extents may be greater than the requested length\&.
.br
\fIvec\fP an array of one or more \fBevbuffer_iovec\fP structures to hold pointers to the reserved extents of memory\&.
.br
\fIn_vec\fP The length of the vec array\&. Must be at least 1; 2 is more efficient\&.
.RE
.PP
\fBReturns:\fP
.RS 4
the number of provided extents, or -1 on error\&.
.RE
.PP
\fBSee also:\fP
.RS 4
\fBevbuffer_commit_space()\fP
.RE
.PP
.SS "EVENT2_EXPORT_SYMBOL struct \fBevbuffer_ptr\fP evbuffer_search (struct \fBevbuffer\fP * buffer, const char * what, size_t len, const struct \fBevbuffer_ptr\fP * start)"
.PP
Search for a string within an evbuffer\&.
.PP
\fBParameters:\fP
.RS 4
\fIbuffer\fP the evbuffer to be searched
.br
\fIwhat\fP the string to be searched for
.br
\fIlen\fP the length of the search string
.br
\fIstart\fP NULL or a pointer to a valid struct \fBevbuffer_ptr\fP\&.
.RE
.PP
\fBReturns:\fP
.RS 4
a struct \fBevbuffer_ptr\fP whose 'pos' field has the offset of the first occurrence of the string in the buffer after 'start'\&. The 'pos' field of the result is -1 if the string was not found\&.
.RE
.PP
.SS "EVENT2_EXPORT_SYMBOL struct \fBevbuffer_ptr\fP evbuffer_search_eol (struct \fBevbuffer\fP * buffer, struct \fBevbuffer_ptr\fP * start, size_t * eol_len_out, enum \fBevbuffer_eol_style\fP eol_style)"
.PP
Search for an end-of-line string within an evbuffer\&.
.PP
\fBParameters:\fP
.RS 4
\fIbuffer\fP the evbuffer to be searched
.br
\fIstart\fP NULL or a pointer to a valid struct \fBevbuffer_ptr\fP to start searching at\&.
.br
\fIeol_len_out\fP If non-NULL, the pointed-to value will be set to the length of the end-of-line string\&.
.br
\fIeol_style\fP The kind of EOL to look for; see \fBevbuffer_readln()\fP for more information
.RE
.PP
\fBReturns:\fP
.RS 4
a struct \fBevbuffer_ptr\fP whose 'pos' field has the offset of the first occurrence EOL in the buffer after 'start'\&. The 'pos' field of the result is -1 if the string was not found\&.
.RE
.PP
.SS "EVENT2_EXPORT_SYMBOL struct \fBevbuffer_ptr\fP evbuffer_search_range (struct \fBevbuffer\fP * buffer, const char * what, size_t len, const struct \fBevbuffer_ptr\fP * start, const struct \fBevbuffer_ptr\fP * end)"
.PP
Search for a string within part of an evbuffer\&.
.PP
\fBParameters:\fP
.RS 4
\fIbuffer\fP the evbuffer to be searched
.br
\fIwhat\fP the string to be searched for
.br
\fIlen\fP the length of the search string
.br
\fIstart\fP NULL or a pointer to a valid struct \fBevbuffer_ptr\fP that indicates where we should start searching\&.
.br
\fIend\fP NULL or a pointer to a valid struct \fBevbuffer_ptr\fP that indicates where we should stop searching\&.
.RE
.PP
\fBReturns:\fP
.RS 4
a struct \fBevbuffer_ptr\fP whose 'pos' field has the offset of the first occurrence of the string in the buffer after 'start'\&. The 'pos' field of the result is -1 if the string was not found\&.
.RE
.PP
.SS "EVENT2_EXPORT_SYMBOL int evbuffer_set_flags (struct \fBevbuffer\fP * buf, ev_uint64_t flags)"
.PP
Change the flags that are set for an evbuffer by adding more\&.
.PP
\fBParameters:\fP
.RS 4
\fIbuffer\fP the evbuffer that the callback is watching\&.
.br
\fIcb\fP the callback whose status we want to change\&.
.br
\fIflags\fP One or more EVBUFFER_FLAG_* options
.RE
.PP
\fBReturns:\fP
.RS 4
0 on success, -1 on failure\&.
.RE
.PP
.SS "EVENT2_EXPORT_SYMBOL int evbuffer_unfreeze (struct \fBevbuffer\fP * buf, int at_front)"
.PP
Re-enable calls that modify an evbuffer\&.
.PP
\fBParameters:\fP
.RS 4
\fIbuf\fP The buffer to un-freeze
.br
\fIat_front\fP If true, we unfreeze the front of the buffer\&. If false, we unfreeze the back\&.
.RE
.PP
\fBReturns:\fP
.RS 4
0 on success, -1 on failure\&.
.RE
.PP
.SS "EVENT2_EXPORT_SYMBOL void evbuffer_unlock (struct \fBevbuffer\fP * buf)"
.PP
Release the lock on an evbuffer\&. Has no effect if locking was not enabled with evbuffer_enable_locking\&.
.SS "EVENT2_EXPORT_SYMBOL int evbuffer_write (struct \fBevbuffer\fP * buffer, \fBevutil_socket_t\fP fd)"
.PP
Write the contents of an evbuffer to a file descriptor\&. The evbuffer will be drained after the bytes have been successfully written\&.
.PP
\fBParameters:\fP
.RS 4
\fIbuffer\fP the evbuffer to be written and drained
.br
\fIfd\fP the file descriptor to be written to
.RE
.PP
\fBReturns:\fP
.RS 4
the number of bytes written, or -1 if an error occurred
.RE
.PP
\fBSee also:\fP
.RS 4
\fBevbuffer_read()\fP
.RE
.PP
.SS "EVENT2_EXPORT_SYMBOL int evbuffer_write_atmost (struct \fBevbuffer\fP * buffer, \fBevutil_socket_t\fP fd, ev_ssize_t howmuch)"
.PP
Write some of the contents of an evbuffer to a file descriptor\&. The evbuffer will be drained after the bytes have been successfully written\&.
.PP
\fBParameters:\fP
.RS 4
\fIbuffer\fP the evbuffer to be written and drained
.br
\fIfd\fP the file descriptor to be written to
.br
\fIhowmuch\fP the largest allowable number of bytes to write, or -1 to write as many bytes as we can\&.
.RE
.PP
\fBReturns:\fP
.RS 4
the number of bytes written, or -1 if an error occurred
.RE
.PP
\fBSee also:\fP
.RS 4
\fBevbuffer_read()\fP
.RE
.PP
.SH "Author"
.PP
Generated automatically by Doxygen for libevent from the source code\&.