diff --git a/annotated.html b/annotated.html new file mode 100644 index 0000000..6622f03 --- /dev/null +++ b/annotated.html @@ -0,0 +1,95 @@ + + +
+ + + + +
+ libevent
+ 2.2.1
+
+ Event notification library
+ |
+
Cbufferevent | An opaque type for handling buffered IO |
Cevbuffer | An evbuffer is an opaque data type for efficiently buffering data to be sent or received on the network |
Cevbuffer_cb_info | Structure passed to an evbuffer_cb_func evbuffer callback |
Cevbuffer_iovec | Describes a single extent of memory inside an evbuffer |
Cevbuffer_ptr | Pointer to a position within an evbuffer |
Cevent | Structure to represent a single event |
Cevent_base | Structure to hold information and state for a Libevent dispatch loop |
Cevent_config | Configuration for an event_base |
Cevhttp_ext_method | Structure that is passed to (and modified by) the extended method callback function |
Cevthread_condition_callbacks | This structure describes the interface a threading library uses for condition variables |
Cevthread_lock_callbacks | This structure describes the interface a threading library uses for locking |
Cevutil_addrinfo | A definition of struct addrinfo for systems that lack it |
Cevutil_monotonic_timer | Structure to hold information about a monotonic timer |
+ libevent
+ 2.2.1
+
+ Event notification library
+ |
+
Functions for buffering data for network sending or receiving. +More...
+#include <event2/visibility.h>
#include <event2/event-config.h>
#include <stdarg.h>
#include <event2/util.h>
Go to the source code of this file.
++Data Structures | |
struct | evbuffer |
An evbuffer is an opaque data type for efficiently buffering data to be sent or received on the network. More... | |
struct | evbuffer_cb_info |
Structure passed to an evbuffer_cb_func evbuffer callback. More... | |
struct | evbuffer_iovec |
Describes a single extent of memory inside an evbuffer. More... | |
struct | evbuffer_ptr |
Pointer to a position within an evbuffer. More... | |
+Macros | |
+#define | EVBUF_FS_CLOSE_ON_FREE 0x01 |
Flag 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. | |
#define | EVBUF_FS_DISABLE_LOCKING 0x08 |
Flag for creating evbuffer_file_segment: Do not allocate a lock for this segment. More... | |
+#define | EVBUF_FS_DISABLE_MMAP 0x02 |
Flag for creating evbuffer_file_segment: Disable memory-map based implementations. | |
#define | EVBUF_FS_DISABLE_SENDFILE 0x04 |
Flag for creating evbuffer_file_segment: Disable direct fd-to-fd implementations (sendfile). More... | |
#define | EVBUFFER_CB_ENABLED 1 |
If this flag is not set, then a callback is temporarily disabled, and should not be invoked. More... | |
#define | EVBUFFER_FLAG_DRAINS_TO_FD 1 |
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). More... | |
+Typedefs | |
typedef void(* | evbuffer_cb_func) (struct evbuffer *buffer, const struct evbuffer_cb_info *info, void *arg) |
Type definition for a callback that is invoked whenever data is added or removed from an evbuffer. More... | |
+typedef void(* | evbuffer_file_segment_cleanup_cb) (struct evbuffer_file_segment const *seg, int flags, void *arg) |
A cleanup function for a evbuffer_file_segment added to an evbuffer for reference. | |
typedef void(* | evbuffer_ref_cleanup_cb) (const void *data, size_t datalen, void *extra) |
A cleanup function for a piece of memory added to an evbuffer by reference. More... | |
+Enumerations | |
enum | evbuffer_eol_style { + EVBUFFER_EOL_ANY, +EVBUFFER_EOL_CRLF, +EVBUFFER_EOL_CRLF_STRICT, +EVBUFFER_EOL_LF, + + EVBUFFER_EOL_NUL + + } |
Used to tell evbuffer_readln what kind of line-ending to look for. More... | |
enum | evbuffer_ptr_how { EVBUFFER_PTR_SET, +EVBUFFER_PTR_ADD + } |
Defines how to adjust an evbuffer_ptr by evbuffer_ptr_set() More... | |
+Functions | |
EVENT2_EXPORT_SYMBOL int | evbuffer_add (struct evbuffer *buf, const void *data, size_t datlen) |
Append data to the end of an evbuffer. More... | |
EVENT2_EXPORT_SYMBOL int | evbuffer_add_buffer (struct evbuffer *outbuf, struct evbuffer *inbuf) |
Move all data from one evbuffer into another evbuffer. More... | |
EVENT2_EXPORT_SYMBOL int | evbuffer_add_buffer_reference (struct evbuffer *outbuf, struct evbuffer *inbuf) |
Copy data from one evbuffer into another evbuffer. More... | |
EVENT2_EXPORT_SYMBOL struct evbuffer_cb_entry * | evbuffer_add_cb (struct evbuffer *buffer, evbuffer_cb_func cb, void *cbarg) |
Add a new callback to an evbuffer. More... | |
EVENT2_EXPORT_SYMBOL int | evbuffer_add_file (struct 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. More... | |
EVENT2_EXPORT_SYMBOL int | evbuffer_add_file_segment (struct evbuffer *buf, struct evbuffer_file_segment *seg, ev_off_t offset, ev_off_t length) |
Insert some or all of an evbuffer_file_segment at the end of an evbuffer. More... | |
EVENT2_EXPORT_SYMBOL size_t | evbuffer_add_iovec (struct evbuffer *buffer, struct evbuffer_iovec *vec, int n_vec) |
Append data from 1 or more iovec's to an evbuffer. More... | |
EVENT2_EXPORT_SYMBOL int | evbuffer_add_printf (struct evbuffer *buf, const char *fmt,...) |
Append a formatted string to the end of an evbuffer. More... | |
EVENT2_EXPORT_SYMBOL int | evbuffer_add_reference (struct evbuffer *outbuf, const void *data, size_t datlen, evbuffer_ref_cleanup_cb cleanupfn, void *cleanupfn_arg) |
Reference memory into an evbuffer without copying. More... | |
EVENT2_EXPORT_SYMBOL int | evbuffer_add_reference_with_offset (struct evbuffer *outbuf, const void *data, size_t offset, size_t datlen, evbuffer_ref_cleanup_cb cleanupfn, void *cleanupfn_arg) |
Reference memory into an evbuffer without copying. More... | |
EVENT2_EXPORT_SYMBOL int | evbuffer_add_vprintf (struct evbuffer *buf, const char *fmt, va_list ap) |
Append a va_list formatted string to the end of an evbuffer. More... | |
EVENT2_EXPORT_SYMBOL int | evbuffer_cb_clear_flags (struct evbuffer *buffer, struct evbuffer_cb_entry *cb, ev_uint32_t flags) |
Change the flags that are set for a callback on a buffer by removing some. More... | |
EVENT2_EXPORT_SYMBOL int | evbuffer_cb_set_flags (struct evbuffer *buffer, struct evbuffer_cb_entry *cb, ev_uint32_t flags) |
Change the flags that are set for a callback on a buffer by adding more. More... | |
EVENT2_EXPORT_SYMBOL int | evbuffer_clear_flags (struct evbuffer *buf, ev_uint64_t flags) |
Change the flags that are set for an evbuffer by removing some. More... | |
EVENT2_EXPORT_SYMBOL int | evbuffer_commit_space (struct evbuffer *buf, struct evbuffer_iovec *vec, int n_vecs) |
Commits previously reserved space. More... | |
EVENT2_EXPORT_SYMBOL ev_ssize_t | evbuffer_copyout (struct evbuffer *buf, void *data_out, size_t datlen) |
Read data from an evbuffer, and leave the buffer unchanged. More... | |
EVENT2_EXPORT_SYMBOL ev_ssize_t | evbuffer_copyout_from (struct evbuffer *buf, const struct evbuffer_ptr *pos, void *data_out, size_t datlen) |
Read data from the middle of an evbuffer, and leave the buffer unchanged. More... | |
EVENT2_EXPORT_SYMBOL int | evbuffer_defer_callbacks (struct evbuffer *buffer, struct 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. More... | |
EVENT2_EXPORT_SYMBOL int | evbuffer_drain (struct evbuffer *buf, size_t len) |
Remove a specified number of bytes data from the beginning of an evbuffer. More... | |
EVENT2_EXPORT_SYMBOL int | evbuffer_enable_locking (struct evbuffer *buf, void *lock) |
Enable locking on an evbuffer so that it can safely be used by multiple threads at the same time. More... | |
EVENT2_EXPORT_SYMBOL int | evbuffer_expand (struct evbuffer *buf, size_t datlen) |
Expands the available space in an evbuffer. More... | |
EVENT2_EXPORT_SYMBOL void | evbuffer_file_segment_add_cleanup_cb (struct evbuffer_file_segment *seg, evbuffer_file_segment_cleanup_cb cb, void *arg) |
Add cleanup callback and argument for the callback to an evbuffer_file_segment. More... | |
EVENT2_EXPORT_SYMBOL void | evbuffer_file_segment_free (struct evbuffer_file_segment *seg) |
Free an evbuffer_file_segment. More... | |
EVENT2_EXPORT_SYMBOL struct evbuffer_file_segment * | evbuffer_file_segment_new (int fd, ev_off_t offset, ev_off_t length, unsigned flags) |
Create and return a new evbuffer_file_segment for reading data from a file and sending it out via an evbuffer. More... | |
EVENT2_EXPORT_SYMBOL void | evbuffer_free (struct evbuffer *buf) |
Deallocate storage for an evbuffer. More... | |
EVENT2_EXPORT_SYMBOL int | evbuffer_freeze (struct evbuffer *buf, int at_front) |
Prevent calls that modify an evbuffer from succeeding. More... | |
EVENT2_EXPORT_SYMBOL size_t | evbuffer_get_contiguous_space (const struct evbuffer *buf) |
Returns the number of contiguous available bytes in the first buffer chain. More... | |
EVENT2_EXPORT_SYMBOL size_t | evbuffer_get_length (const struct evbuffer *buf) |
Returns the total number of bytes stored in the evbuffer. More... | |
EVENT2_EXPORT_SYMBOL size_t | evbuffer_get_max_read (struct evbuffer *buf) |
Get maximum read buffer size. More... | |
EVENT2_EXPORT_SYMBOL void | evbuffer_lock (struct evbuffer *buf) |
Acquire the lock on an evbuffer. More... | |
EVENT2_EXPORT_SYMBOL struct evbuffer * | evbuffer_new (void) |
Allocate storage for a new evbuffer. More... | |
EVENT2_EXPORT_SYMBOL int | evbuffer_peek (struct evbuffer *buffer, ev_ssize_t len, struct evbuffer_ptr *start_at, struct evbuffer_iovec *vec_out, int n_vec) |
Function to peek at data inside an evbuffer without removing it or copying it out. More... | |
EVENT2_EXPORT_SYMBOL int | evbuffer_prepend (struct evbuffer *buf, const void *data, size_t size) |
Prepends data to the beginning of the evbuffer. More... | |
EVENT2_EXPORT_SYMBOL int | evbuffer_prepend_buffer (struct evbuffer *dst, struct evbuffer *src) |
Prepends all data from the src evbuffer to the beginning of the dst evbuffer. More... | |
EVENT2_EXPORT_SYMBOL int | evbuffer_ptr_set (struct evbuffer *buffer, struct evbuffer_ptr *ptr, size_t position, enum evbuffer_ptr_how how) |
Sets the search pointer in the buffer to position. More... | |
EVENT2_EXPORT_SYMBOL unsigned char * | evbuffer_pullup (struct evbuffer *buf, ev_ssize_t size) |
Makes the data at the beginning of an evbuffer contiguous. More... | |
EVENT2_EXPORT_SYMBOL int | evbuffer_read (struct evbuffer *buffer, evutil_socket_t fd, int howmuch) |
Read from a file descriptor and store the result in an evbuffer. More... | |
EVENT2_EXPORT_SYMBOL char * | evbuffer_readln (struct evbuffer *buffer, size_t *n_read_out, enum evbuffer_eol_style eol_style) |
Read a single line from an evbuffer. More... | |
EVENT2_EXPORT_SYMBOL int | evbuffer_remove (struct evbuffer *buf, void *data, size_t datlen) |
Read data from an evbuffer and drain the bytes read. More... | |
EVENT2_EXPORT_SYMBOL int | evbuffer_remove_buffer (struct evbuffer *src, struct evbuffer *dst, size_t datlen) |
Read data from an evbuffer into another evbuffer, draining the bytes from the source buffer. More... | |
EVENT2_EXPORT_SYMBOL int | evbuffer_remove_cb (struct evbuffer *buffer, evbuffer_cb_func cb, void *cbarg) |
Remove a callback from an evbuffer, given the function and argument used to add it. More... | |
EVENT2_EXPORT_SYMBOL int | evbuffer_remove_cb_entry (struct evbuffer *buffer, struct evbuffer_cb_entry *ent) |
Remove a callback from an evbuffer, given a handle returned from evbuffer_add_cb. More... | |
EVENT2_EXPORT_SYMBOL int | evbuffer_reserve_space (struct evbuffer *buf, ev_ssize_t size, struct evbuffer_iovec *vec, int n_vec) |
Reserves space in the last chain or chains of an evbuffer. More... | |
EVENT2_EXPORT_SYMBOL struct evbuffer_ptr | evbuffer_search (struct evbuffer *buffer, const char *what, size_t len, const struct evbuffer_ptr *start) |
Search for a string within an evbuffer. More... | |
EVENT2_EXPORT_SYMBOL struct evbuffer_ptr | evbuffer_search_eol (struct evbuffer *buffer, struct evbuffer_ptr *start, size_t *eol_len_out, enum evbuffer_eol_style eol_style) |
Search for an end-of-line string within an evbuffer. More... | |
EVENT2_EXPORT_SYMBOL struct evbuffer_ptr | evbuffer_search_range (struct evbuffer *buffer, const char *what, size_t len, const struct evbuffer_ptr *start, const struct evbuffer_ptr *end) |
Search for a string within part of an evbuffer. More... | |
EVENT2_EXPORT_SYMBOL int | evbuffer_set_flags (struct evbuffer *buf, ev_uint64_t flags) |
Change the flags that are set for an evbuffer by adding more. More... | |
EVENT2_EXPORT_SYMBOL int | evbuffer_set_max_read (struct evbuffer *buf, size_t max) |
Set maximum read buffer size. More... | |
EVENT2_EXPORT_SYMBOL int | evbuffer_unfreeze (struct evbuffer *buf, int at_front) |
Re-enable calls that modify an evbuffer. More... | |
EVENT2_EXPORT_SYMBOL void | evbuffer_unlock (struct evbuffer *buf) |
Release the lock on an evbuffer. More... | |
EVENT2_EXPORT_SYMBOL int | evbuffer_write (struct evbuffer *buffer, evutil_socket_t fd) |
Write the contents of an evbuffer to a file descriptor. More... | |
EVENT2_EXPORT_SYMBOL int | evbuffer_write_atmost (struct evbuffer *buffer, evutil_socket_t fd, ev_ssize_t howmuch) |
Write some of the contents of an evbuffer to a file descriptor. More... | |
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.
+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.
+#define EVBUF_FS_DISABLE_LOCKING 0x08 | +
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.
+ +#define EVBUF_FS_DISABLE_SENDFILE 0x04 | +
Flag for creating evbuffer_file_segment: Disable direct fd-to-fd implementations (sendfile).
+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.
+ +#define EVBUFFER_CB_ENABLED 1 | +
If this flag is not set, then a callback is temporarily disabled, and should not be invoked.
+ + +#define EVBUFFER_FLAG_DRAINS_TO_FD 1 | +
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).
+Using this option allows the implementation to use sendfile-based operations for evbuffer_add_file(); see that function for more information.
+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.
+ +typedef void(* evbuffer_cb_func) (struct evbuffer *buffer, const struct evbuffer_cb_info *info, void *arg) | +
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.
+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.
+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!
+buffer | the buffer whose size has changed |
info | a structure describing how the buffer changed. |
arg | a pointer to user data |
typedef void(* evbuffer_ref_cleanup_cb) (const void *data, size_t datalen, void *extra) | +
A cleanup function for a piece of memory added to an evbuffer by reference.
+data | buffer |
datalen | - total buffer len (including @offset if any, |
enum evbuffer_eol_style | +
Used to tell evbuffer_readln what kind of line-ending to look for.
+enum evbuffer_ptr_how | +
Defines how to adjust an evbuffer_ptr by evbuffer_ptr_set()
+Enumerator | |
---|---|
EVBUFFER_PTR_SET | Sets the pointer to the position; can be called on with an uninitialized evbuffer_ptr. + |
EVBUFFER_PTR_ADD | Advances the pointer by adding to the current position. + |
EVENT2_EXPORT_SYMBOL int evbuffer_add | +( | +struct evbuffer * | +buf, | +
+ | + | const void * | +data, | +
+ | + | size_t | +datlen | +
+ | ) | ++ |
Append data to the end of an evbuffer.
+buf | the evbuffer to be appended to |
data | pointer to the beginning of the data buffer |
datlen | the number of bytes to be copied from the data buffer |
EVENT2_EXPORT_SYMBOL int evbuffer_add_buffer | +( | +struct evbuffer * | +outbuf, | +
+ | + | struct evbuffer * | +inbuf | +
+ | ) | ++ |
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.
+outbuf | the output buffer |
inbuf | the input buffer |
EVENT2_EXPORT_SYMBOL int evbuffer_add_buffer_reference | +( | +struct evbuffer * | +outbuf, | +
+ | + | struct evbuffer * | +inbuf | +
+ | ) | ++ |
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.
+Note that buffers already containing buffer references can't be added to other buffers.
+outbuf | the output buffer |
inbuf | the input buffer |
EVENT2_EXPORT_SYMBOL struct evbuffer_cb_entry* evbuffer_add_cb | +( | +struct evbuffer * | +buffer, | +
+ | + | evbuffer_cb_func | +cb, | +
+ | + | void * | +cbarg | +
+ | ) | ++ |
Add a new callback to an evbuffer.
+Subsequent calls to evbuffer_add_cb() add new callbacks. To remove this callback, call evbuffer_remove_cb or evbuffer_remove_cb_entry.
+buffer | the evbuffer to be monitored |
cb | the callback function to invoke when the evbuffer is modified, or NULL to remove all callbacks. |
cbarg | an argument to be provided to the callback function |
EVENT2_EXPORT_SYMBOL int evbuffer_add_file | +( | +struct 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.
+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).
+The function owns the resulting file descriptor and will close (even in case of error) it when finished transferring data.
+The results of using evbuffer_remove() or evbuffer_pullup() on evbuffers whose data was added using this function are undefined.
+For more fine-grained control, use evbuffer_add_file_segment.
+outbuf | the output buffer |
fd | the file descriptor |
offset | the offset from which to read data |
length | how much data to read, or -1 to read as much as possible. (-1 requires that 'fd' support fstat.) |
EVENT2_EXPORT_SYMBOL int evbuffer_add_file_segment | +( | +struct evbuffer * | +buf, | +
+ | + | struct evbuffer_file_segment * | +seg, | +
+ | + | ev_off_t | +offset, | +
+ | + | ev_off_t | +length | +
+ | ) | ++ |
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 within the file, and the length is the length of the segment, whereas when you add a segment to an evbuffer, the offset is within the segment and the length is the length of the _part of the segment you want to use.
+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.
+buf | the evbuffer to append to |
seg | the segment to add |
offset | the offset within the segment to start from |
length | the amount of data to add, or -1 to add it all. |
EVENT2_EXPORT_SYMBOL size_t evbuffer_add_iovec | +( | +struct evbuffer * | +buffer, | +
+ | + | struct evbuffer_iovec * | +vec, | +
+ | + | int | +n_vec | +
+ | ) | ++ |
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 evbuffer_add() constantly before being used to increase performance.
+buffer | the destination buffer |
vec | the source iovec |
n_vec | the number of iovec structures. |
EVENT2_EXPORT_SYMBOL int evbuffer_add_printf | +( | +struct evbuffer * | +buf, | +
+ | + | const char * | +fmt, | +
+ | + | + | ... | +
+ | ) | ++ |
Append a formatted string to the end of an evbuffer.
+The string is formated as printf.
+buf | the evbuffer that will be appended to |
fmt | a format string |
... | arguments that will be passed to printf(3) |
EVENT2_EXPORT_SYMBOL int evbuffer_add_reference | +( | +struct evbuffer * | +outbuf, | +
+ | + | const void * | +data, | +
+ | + | size_t | +datlen, | +
+ | + | evbuffer_ref_cleanup_cb | +cleanupfn, | +
+ | + | void * | +cleanupfn_arg | +
+ | ) | ++ |
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.
+outbuf | the output buffer |
data | the memory to reference |
datlen | how memory to reference |
cleanupfn | callback to be invoked when the memory is no longer referenced by this evbuffer. |
cleanupfn_arg | optional argument to the cleanup callback |
EVENT2_EXPORT_SYMBOL int evbuffer_add_reference_with_offset | +( | +struct evbuffer * | +outbuf, | +
+ | + | const void * | +data, | +
+ | + | size_t | +offset, | +
+ | + | size_t | +datlen, | +
+ | + | evbuffer_ref_cleanup_cb | +cleanupfn, | +
+ | + | void * | +cleanupfn_arg | +
+ | ) | ++ |
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.
+outbuf | the output buffer |
data | the memory to reference |
offset | offset inside @data |
datlen | how memory to reference (excluding @offset) |
cleanupfn | callback to be invoked when the memory is no longer referenced by this evbuffer. |
cleanupfn_arg | optional argument to the cleanup callback |
EVENT2_EXPORT_SYMBOL int evbuffer_add_vprintf | +( | +struct evbuffer * | +buf, | +
+ | + | const char * | +fmt, | +
+ | + | va_list | +ap | +
+ | ) | ++ |
Append a va_list formatted string to the end of an evbuffer.
+buf | the evbuffer that will be appended to |
fmt | a format string |
ap | a varargs va_list argument array that will be passed to vprintf(3) |
EVENT2_EXPORT_SYMBOL int evbuffer_cb_clear_flags | +( | +struct evbuffer * | +buffer, | +
+ | + | struct evbuffer_cb_entry * | +cb, | +
+ | + | ev_uint32_t | +flags | +
+ | ) | ++ |
Change the flags that are set for a callback on a buffer by removing some.
+buffer | the evbuffer that the callback is watching. |
cb | the callback whose status we want to change. |
flags | EVBUFFER_CB_ENABLED to disable the callback. |
EVENT2_EXPORT_SYMBOL int evbuffer_cb_set_flags | +( | +struct evbuffer * | +buffer, | +
+ | + | struct evbuffer_cb_entry * | +cb, | +
+ | + | ev_uint32_t | +flags | +
+ | ) | ++ |
Change the flags that are set for a callback on a buffer by adding more.
+buffer | the evbuffer that the callback is watching. |
cb | the callback whose status we want to change. |
flags | EVBUFFER_CB_ENABLED to re-enable the callback. |
EVENT2_EXPORT_SYMBOL int evbuffer_clear_flags | +( | +struct evbuffer * | +buf, | +
+ | + | ev_uint64_t | +flags | +
+ | ) | ++ |
Change the flags that are set for an evbuffer by removing some.
+buf | the evbuffer that the callback is watching. |
flags | One or more EVBUFFER_FLAG_* options |
EVENT2_EXPORT_SYMBOL int evbuffer_commit_space | +( | +struct evbuffer * | +buf, | +
+ | + | struct evbuffer_iovec * | +vec, | +
+ | + | int | +n_vecs | +
+ | ) | ++ |
Commits previously reserved space.
+Commits some of the space previously reserved with evbuffer_reserve_space(). It then becomes available for reading.
+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.
+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!
+buf | the evbuffer in which to reserve space. |
vec | one or two extents returned by evbuffer_reserve_space. |
n_vecs | the number of extents. |
EVENT2_EXPORT_SYMBOL ev_ssize_t evbuffer_copyout | +( | +struct evbuffer * | +buf, | +
+ | + | void * | +data_out, | +
+ | + | size_t | +datlen | +
+ | ) | ++ |
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.
+buf | the evbuffer to be read from |
data_out | the destination buffer to store the result |
datlen | the maximum size of the destination buffer |
EVENT2_EXPORT_SYMBOL ev_ssize_t evbuffer_copyout_from | +( | +struct evbuffer * | +buf, | +
+ | + | const struct evbuffer_ptr * | +pos, | +
+ | + | void * | +data_out, | +
+ | + | size_t | +datlen | +
+ | ) | ++ |
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.
+buf | the evbuffer to be read from |
pos | the position to start reading from |
data_out | the destination buffer to store the result |
datlen | the maximum size of the destination buffer |
EVENT2_EXPORT_SYMBOL int evbuffer_defer_callbacks | +( | +struct evbuffer * | +buffer, | +
+ | + | struct 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.
+This can be used to serialize all the callbacks to a single thread of execution.
+ +EVENT2_EXPORT_SYMBOL int evbuffer_drain | +( | +struct evbuffer * | +buf, | +
+ | + | size_t | +len | +
+ | ) | ++ |
Remove a specified number of bytes data from the beginning of an evbuffer.
+buf | the evbuffer to be drained |
len | the number of bytes to drain from the beginning of the buffer |
EVENT2_EXPORT_SYMBOL int evbuffer_enable_locking | +( | +struct evbuffer * | +buf, | +
+ | + | void * | +lock | +
+ | ) | ++ |
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!
+buf | An evbuffer to make lockable. |
lock | A lock object, or NULL if we should allocate our own. |
EVENT2_EXPORT_SYMBOL int evbuffer_expand | +( | +struct evbuffer * | +buf, | +
+ | + | size_t | +datlen | +
+ | ) | ++ |
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.
+buf | the evbuffer to be expanded |
datlen | the new minimum length requirement |
EVENT2_EXPORT_SYMBOL void evbuffer_file_segment_add_cleanup_cb | +( | +struct evbuffer_file_segment * | +seg, | +
+ | + | evbuffer_file_segment_cleanup_cb | +cb, | +
+ | + | void * | +arg | +
+ | ) | ++ |
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.
+ +EVENT2_EXPORT_SYMBOL void evbuffer_file_segment_free | +( | +struct evbuffer_file_segment * | +seg | ) | ++ |
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.
+ +EVENT2_EXPORT_SYMBOL struct evbuffer_file_segment* evbuffer_file_segment_new | +( | +int | +fd, | +
+ | + | ev_off_t | +offset, | +
+ | + | ev_off_t | +length, | +
+ | + | unsigned | +flags | +
+ | ) | ++ |
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.
+The file descriptor must not be closed so long as any evbuffer is using this segment.
+The results of using evbuffer_remove() or evbuffer_pullup() 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.
+fd | an open file to read from. |
offset | an index within the file at which to start reading |
length | how much data to read, or -1 to read as much as possible. (-1 requires that 'fd' support fstat.) |
flags | any number of the EVBUF_FS_* flags |
EVENT2_EXPORT_SYMBOL void evbuffer_free | +( | +struct evbuffer * | +buf | ) | ++ |
Deallocate storage for an evbuffer.
+buf | pointer to the evbuffer to be freed |
EVENT2_EXPORT_SYMBOL int evbuffer_freeze | +( | +struct 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.
+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.
+buf | The buffer to freeze |
at_front | If true, we freeze the front of the buffer. If false, we freeze the back. |
EVENT2_EXPORT_SYMBOL size_t evbuffer_get_contiguous_space | +( | +const struct evbuffer * | +buf | ) | ++ |
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 evbuffer_pullup() that cause reallocation and copying of data can thus be avoided.
+buf | pointer to the evbuffer |
EVENT2_EXPORT_SYMBOL size_t evbuffer_get_length | +( | +const struct evbuffer * | +buf | ) | ++ |
Returns the total number of bytes stored in the evbuffer.
+buf | pointer to the evbuffer |
EVENT2_EXPORT_SYMBOL size_t evbuffer_get_max_read | +( | +struct evbuffer * | +buf | ) | ++ |
Get maximum read buffer size.
+buf | pointer to the evbuffer |
EVENT2_EXPORT_SYMBOL void evbuffer_lock | +( | +struct evbuffer * | +buf | ) | ++ |
Acquire the lock on an evbuffer.
+Has no effect if locking was not enabled with evbuffer_enable_locking.
+ +EVENT2_EXPORT_SYMBOL struct evbuffer* evbuffer_new | +( | +void | +) | ++ |
Allocate storage for a new evbuffer.
+EVENT2_EXPORT_SYMBOL int evbuffer_peek | +( | +struct evbuffer * | +buffer, | +
+ | + | ev_ssize_t | +len, | +
+ | + | struct evbuffer_ptr * | +start_at, | +
+ | + | struct evbuffer_iovec * | +vec_out, | +
+ | + | int | +n_vec | +
+ | ) | ++ |
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.
+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).
+buffer | the evbuffer to peek into, |
len | 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. |
start_at | an evbuffer_ptr indicating the point at which we should start looking for data. NULL means, "At the start of the + buffer." |
vec_out | an array of evbuffer_iovec |
n_vec | the length of vec_out. If 0, we only count how many extents would be necessary to point to the requested amount of data. |
EVENT2_EXPORT_SYMBOL int evbuffer_prepend | +( | +struct evbuffer * | +buf, | +
+ | + | const void * | +data, | +
+ | + | size_t | +size | +
+ | ) | ++ |
Prepends data to the beginning of the evbuffer.
+buf | the evbuffer to which to prepend data |
data | a pointer to the memory to prepend |
size | the number of bytes to prepend |
EVENT2_EXPORT_SYMBOL int evbuffer_prepend_buffer | +( | +struct evbuffer * | +dst, | +
+ | + | struct evbuffer * | +src | +
+ | ) | ++ |
Prepends all data from the src evbuffer to the beginning of the dst evbuffer.
+dst | the evbuffer to which to prepend data |
src | the evbuffer to prepend; it will be emptied as a result |
EVENT2_EXPORT_SYMBOL int evbuffer_ptr_set | +( | +struct evbuffer * | +buffer, | +
+ | + | struct evbuffer_ptr * | +ptr, | +
+ | + | size_t | +position, | +
+ | + | enum evbuffer_ptr_how | +how | +
+ | ) | ++ |
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.
+If evbuffer_ptr is not initialized, this function can only be called with EVBUFFER_PTR_SET.
+An evbuffer_ptr can represent any position from the start of the buffer to a position immediately after the end of the buffer.
+buffer | the evbuffer to be search |
ptr | a pointer to a struct evbuffer_ptr |
position | the position at which to start the next search |
how | determines how the pointer should be manipulated. |
EVENT2_EXPORT_SYMBOL unsigned char* evbuffer_pullup | +( | +struct evbuffer * | +buf, | +
+ | + | ev_ssize_t | +size | +
+ | ) | ++ |
Makes the data at the beginning of an evbuffer contiguous.
+buf | the evbuffer to make contiguous |
size | the number of bytes to make contiguous, or -1 to make the entire buffer contiguous. |
EVENT2_EXPORT_SYMBOL int evbuffer_read | +( | +struct evbuffer * | +buffer, | +
+ | + | evutil_socket_t | +fd, | +
+ | + | int | +howmuch | +
+ | ) | ++ |
Read from a file descriptor and store the result in an evbuffer.
+buffer | the evbuffer to store the result |
fd | the file descriptor to read from |
howmuch | the number of bytes to be read. If the given number is negative or out of maximum bytes per one read, as many bytes as we can will be read. |
EVENT2_EXPORT_SYMBOL char* evbuffer_readln | +( | +struct evbuffer * | +buffer, | +
+ | + | size_t * | +n_read_out, | +
+ | + | enum evbuffer_eol_style | +eol_style | +
+ | ) | ++ |
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.
+buffer | the evbuffer to read from |
n_read_out | 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. |
eol_style | the style of line-ending to use. |
EVENT2_EXPORT_SYMBOL int evbuffer_remove | +( | +struct evbuffer * | +buf, | +
+ | + | void * | +data, | +
+ | + | size_t | +datlen | +
+ | ) | ++ |
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.
+buf | the evbuffer to be read from |
data | the destination buffer to store the result |
datlen | the maximum size of the destination buffer |
EVENT2_EXPORT_SYMBOL int evbuffer_remove_buffer | +( | +struct evbuffer * | +src, | +
+ | + | struct 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.
+If more bytes are requested than are available in src, the src buffer is drained completely.
+src | the evbuffer to be read from |
dst | the destination evbuffer to store the result into |
datlen | the maximum numbers of bytes to transfer |
EVENT2_EXPORT_SYMBOL int evbuffer_remove_cb | +( | +struct evbuffer * | +buffer, | +
+ | + | evbuffer_cb_func | +cb, | +
+ | + | void * | +cbarg | +
+ | ) | ++ |
Remove a callback from an evbuffer, given the function and argument used to add it.
+EVENT2_EXPORT_SYMBOL int evbuffer_remove_cb_entry | +( | +struct evbuffer * | +buffer, | +
+ | + | struct evbuffer_cb_entry * | +ent | +
+ | ) | ++ |
Remove a callback from an evbuffer, given a handle returned from evbuffer_add_cb.
+Calling this function invalidates the handle.
+EVENT2_EXPORT_SYMBOL int evbuffer_reserve_space | +( | +struct evbuffer * | +buf, | +
+ | + | ev_ssize_t | +size, | +
+ | + | struct evbuffer_iovec * | +vec, | +
+ | + | int | +n_vec | +
+ | ) | ++ |
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 evbuffer_commit_space().
+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.
+Multiple subsequent calls to this function will make the same space available until evbuffer_commit_space() has been called.
+It is an error to do anything that moves around the buffer's internal memory structures before committing the space.
+NOTE: The code currently does not ever use more than two extents. This may change in future versions.
+buf | the evbuffer in which to reserve space. |
size | how much space to make available, at minimum. The total length of the extents may be greater than the requested length. |
vec | an array of one or more evbuffer_iovec structures to hold pointers to the reserved extents of memory. |
n_vec | The length of the vec array. Must be at least 1; 2 is more efficient. |
EVENT2_EXPORT_SYMBOL struct evbuffer_ptr evbuffer_search | +( | +struct evbuffer * | +buffer, | +
+ | + | const char * | +what, | +
+ | + | size_t | +len, | +
+ | + | const struct evbuffer_ptr * | +start | +
+ | ) | ++ |
Search for a string within an evbuffer.
+buffer | the evbuffer to be searched |
what | the string to be searched for |
len | the length of the search string |
start | NULL or a pointer to a valid struct evbuffer_ptr. |
EVENT2_EXPORT_SYMBOL struct evbuffer_ptr evbuffer_search_eol | +( | +struct evbuffer * | +buffer, | +
+ | + | struct evbuffer_ptr * | +start, | +
+ | + | size_t * | +eol_len_out, | +
+ | + | enum evbuffer_eol_style | +eol_style | +
+ | ) | ++ |
Search for an end-of-line string within an evbuffer.
+buffer | the evbuffer to be searched |
start | NULL or a pointer to a valid struct evbuffer_ptr to start searching at. |
eol_len_out | If non-NULL, the pointed-to value will be set to the length of the end-of-line string. |
eol_style | The kind of EOL to look for; see evbuffer_readln() for more information |
EVENT2_EXPORT_SYMBOL struct evbuffer_ptr evbuffer_search_range | +( | +struct evbuffer * | +buffer, | +
+ | + | const char * | +what, | +
+ | + | size_t | +len, | +
+ | + | const struct evbuffer_ptr * | +start, | +
+ | + | const struct evbuffer_ptr * | +end | +
+ | ) | ++ |
Search for a string within part of an evbuffer.
+buffer | the evbuffer to be searched |
what | the string to be searched for |
len | the length of the search string |
start | NULL or a pointer to a valid struct evbuffer_ptr that indicates where we should start searching. |
end | NULL or a pointer to a valid struct evbuffer_ptr that indicates where we should stop searching. |
EVENT2_EXPORT_SYMBOL int evbuffer_set_flags | +( | +struct evbuffer * | +buf, | +
+ | + | ev_uint64_t | +flags | +
+ | ) | ++ |
Change the flags that are set for an evbuffer by adding more.
+buf | the evbuffer that the callback is watching. |
flags | One or more EVBUFFER_FLAG_* options |
EVENT2_EXPORT_SYMBOL int evbuffer_set_max_read | +( | +struct evbuffer * | +buf, | +
+ | + | size_t | +max | +
+ | ) | ++ |
Set maximum read buffer size.
+Default is 4096 and it works fine most of time, so before increasing the default check carefully, since this has some negative effects (like memory fragmentation and unfair resource distribution, i.e. some events will make less progress than others).
+buf | pointer to the evbuffer |
max | buffer size |
EVENT2_EXPORT_SYMBOL int evbuffer_unfreeze | +( | +struct evbuffer * | +buf, | +
+ | + | int | +at_front | +
+ | ) | ++ |
Re-enable calls that modify an evbuffer.
+buf | The buffer to un-freeze |
at_front | If true, we unfreeze the front of the buffer. If false, we unfreeze the back. |
EVENT2_EXPORT_SYMBOL void evbuffer_unlock | +( | +struct evbuffer * | +buf | ) | ++ |
Release the lock on an evbuffer.
+Has no effect if locking was not enabled with evbuffer_enable_locking.
+ +EVENT2_EXPORT_SYMBOL int evbuffer_write | +( | +struct evbuffer * | +buffer, | +
+ | + | evutil_socket_t | +fd | +
+ | ) | ++ |
Write the contents of an evbuffer to a file descriptor.
+The evbuffer will be drained after the bytes have been successfully written.
+buffer | the evbuffer to be written and drained |
fd | the file descriptor to be written to |
EVENT2_EXPORT_SYMBOL int evbuffer_write_atmost | +( | +struct evbuffer * | +buffer, | +
+ | + | evutil_socket_t | +fd, | +
+ | + | ev_ssize_t | +howmuch | +
+ | ) | ++ |
Write some of the contents of an evbuffer to a file descriptor.
+The evbuffer will be drained after the bytes have been successfully written.
+buffer | the evbuffer to be written and drained |
fd | the file descriptor to be written to |
howmuch | the largest allowable number of bytes to write, or -1 to write as many bytes as we can. |
+ libevent
+ 2.2.1
+
+ Event notification library
+ |
+
+ libevent
+ 2.2.1
+
+ Event notification library
+ |
+
Obsolete and deprecated versions of the functions in buffer.h: provided only for backward compatibility. +More...
+#include <event2/visibility.h>
Go to the source code of this file.
++Macros | |
+#define | EVBUFFER_DATA(x) evbuffer_pullup((x), -1) |
deprecated in favor of calling the functions directly | |
+#define | EVBUFFER_LENGTH(x) evbuffer_get_length(x) |
deprecated in favor of calling the functions directly | |
+Typedefs | |
typedef void(* | evbuffer_cb) (struct evbuffer *buffer, size_t old_len, size_t new_len, void *arg) |
Type definition for a callback that is invoked whenever data is added or removed from an evbuffer. More... | |
+Functions | |
EVENT2_EXPORT_SYMBOL unsigned char * | evbuffer_find (struct evbuffer *buffer, const unsigned char *what, size_t len) |
Find a string within an evbuffer. More... | |
EVENT2_EXPORT_SYMBOL char * | evbuffer_readline (struct evbuffer *buffer) |
Obsolete alias for evbuffer_readln(buffer, NULL, EVBUFFER_EOL_ANY). More... | |
EVENT2_EXPORT_SYMBOL int | evbuffer_setcb (struct evbuffer *buffer, evbuffer_cb cb, void *cbarg) |
Replace all callbacks on an evbuffer with a single new callback, or remove them. More... | |
Obsolete and deprecated versions of the functions in buffer.h: provided only for backward compatibility.
+typedef void(* evbuffer_cb) (struct evbuffer *buffer, size_t old_len, size_t new_len, void *arg) | +
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.
+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.
+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!
+buffer | the buffer whose size has changed |
old_len | the previous length of the buffer |
new_len | the current length of the buffer |
arg | a pointer to user data |
EVENT2_EXPORT_SYMBOL unsigned char* evbuffer_find | +( | +struct evbuffer * | +buffer, | +
+ | + | const unsigned char * | +what, | +
+ | + | size_t | +len | +
+ | ) | ++ |
Find a string within an evbuffer.
+buffer | the evbuffer to be searched |
what | the string to be searched for |
len | the length of the search string |
EVENT2_EXPORT_SYMBOL char* evbuffer_readline | +( | +struct evbuffer * | +buffer | ) | ++ |
Obsolete alias for evbuffer_readln(buffer, NULL, EVBUFFER_EOL_ANY).
+buffer | the evbuffer to read from |
EVENT2_EXPORT_SYMBOL int evbuffer_setcb | +( | +struct evbuffer * | +buffer, | +
+ | + | evbuffer_cb | +cb, | +
+ | + | void * | +cbarg | +
+ | ) | ++ |
Replace all callbacks on an evbuffer with a single new callback, or remove them.
+Subsequent calls to evbuffer_setcb() replace callbacks set by previous calls. Setting the callback to NULL removes any previously set callback.
+buffer | the evbuffer to be monitored |
cb | the callback function to invoke when the evbuffer is modified, or NULL to remove all callbacks. |
cbarg | an argument to be provided to the callback function |
+ libevent
+ 2.2.1
+
+ Event notification library
+ |
+
+ libevent
+ 2.2.1
+
+ Event notification library
+ |
+
Functions for buffering data for network sending or receiving. +More...
+ +Go to the source code of this file.
++Data Structures | |
struct | bufferevent |
An opaque type for handling buffered IO. More... | |
+Macros | |
+#define | EV_RATE_LIMIT_MAX EV_SSIZE_MAX |
Maximum configurable rate- or burst-limit. | |
Bufferevent event codes | |
These flags are passed as arguments to a bufferevent's event callback. + | |
+#define | BEV_EVENT_CONNECTED 0x80 |
connect operation finished. | |
+#define | BEV_EVENT_EOF 0x10 |
eof file reached | |
+#define | BEV_EVENT_ERROR 0x20 |
unrecoverable error encountered | |
+#define | BEV_EVENT_READING 0x01 |
error encountered while reading | |
+#define | BEV_EVENT_TIMEOUT 0x40 |
user-specified timeout reached | |
+#define | BEV_EVENT_WRITING 0x02 |
error encountered while writing | |
+Typedefs | |
typedef void(* | bufferevent_data_cb) (struct bufferevent *bev, void *ctx) |
A read or write callback for a bufferevent. More... | |
typedef void(* | bufferevent_event_cb) (struct bufferevent *bev, short what, void *ctx) |
An event/error callback for a bufferevent. More... | |
+Enumerations | |
enum | bufferevent_flush_mode { BEV_NORMAL = 0, +BEV_FLUSH = 1, +BEV_FINISHED = 2 + } |
Flags that can be passed into filters to let them know how to deal with the incoming data. More... | |
enum | bufferevent_options { BEV_OPT_CLOSE_ON_FREE = (1<<0), +BEV_OPT_THREADSAFE = (1<<1), +BEV_OPT_DEFER_CALLBACKS = (1<<2), +BEV_OPT_UNLOCK_CALLBACKS = (1<<3) + } |
Options that can be specified when creating a bufferevent. More... | |
enum | bufferevent_trigger_options { BEV_TRIG_IGNORE_WATERMARKS = (1<<16), +BEV_TRIG_DEFER_CALLBACKS = BEV_OPT_DEFER_CALLBACKS + } |
Flags for bufferevent_trigger(_event) that modify when and how to trigger the callback. More... | |
+Functions | |
EVENT2_EXPORT_SYMBOL int | bufferevent_add_to_rate_limit_group (struct bufferevent *bev, struct bufferevent_rate_limit_group *g) |
Add 'bev' to the list of bufferevents whose aggregate reading and writing is restricted by 'g'. More... | |
EVENT2_EXPORT_SYMBOL int | bufferevent_base_set (struct event_base *base, struct bufferevent *bufev) |
Assign a bufferevent to a specific event_base. More... | |
EVENT2_EXPORT_SYMBOL int | bufferevent_decref (struct bufferevent *bufev) |
Public interface to manually decrement the reference count of a bufferevent. More... | |
EVENT2_EXPORT_SYMBOL int | bufferevent_disable (struct bufferevent *bufev, short event) |
Disable a bufferevent. More... | |
EVENT2_EXPORT_SYMBOL int | bufferevent_enable (struct bufferevent *bufev, short event) |
Enable a bufferevent. More... | |
EVENT2_EXPORT_SYMBOL int | bufferevent_flush (struct bufferevent *bufev, short iotype, enum bufferevent_flush_mode mode) |
Triggers the bufferevent to produce more data if possible. More... | |
EVENT2_EXPORT_SYMBOL void | bufferevent_free (struct bufferevent *bufev) |
Deallocate the storage associated with a bufferevent structure. More... | |
+EVENT2_EXPORT_SYMBOL struct event_base * | bufferevent_get_base (struct bufferevent *bev) |
Return the event_base used by a bufferevent. | |
EVENT2_EXPORT_SYMBOL short | bufferevent_get_enabled (struct bufferevent *bufev) |
Return the events that are enabled on a given bufferevent. More... | |
EVENT2_EXPORT_SYMBOL struct evbuffer * | bufferevent_get_input (struct bufferevent *bufev) |
Returns the input buffer. More... | |
+EVENT2_EXPORT_SYMBOL ev_ssize_t | bufferevent_get_max_single_read (struct bufferevent *bev) |
Get the current size limit for single read operation. | |
+EVENT2_EXPORT_SYMBOL ev_ssize_t | bufferevent_get_max_single_write (struct bufferevent *bev) |
Get the current size limit for single write operation. | |
EVENT2_EXPORT_SYMBOL struct evbuffer * | bufferevent_get_output (struct bufferevent *bufev) |
Returns the output buffer. More... | |
EVENT2_EXPORT_SYMBOL int | bufferevent_get_priority (const struct bufferevent *bufev) |
Return the priority of a bufferevent. More... | |
+EVENT2_EXPORT_SYMBOL struct bufferevent * | bufferevent_get_underlying (struct bufferevent *bufev) |
Returns the underlying bufferevent associated with a bufferevent (if the bufferevent is a wrapper), or NULL if there is no underlying bufferevent. | |
EVENT2_EXPORT_SYMBOL void | bufferevent_getcb (struct bufferevent *bufev, bufferevent_data_cb *readcb_ptr, bufferevent_data_cb *writecb_ptr, bufferevent_event_cb *eventcb_ptr, void **cbarg_ptr) |
Retrieves the callbacks for a bufferevent. More... | |
EVENT2_EXPORT_SYMBOL evutil_socket_t | bufferevent_getfd (struct bufferevent *bufev) |
Returns the file descriptor associated with a bufferevent, or -1 if no file descriptor is associated with the bufferevent. More... | |
EVENT2_EXPORT_SYMBOL int | bufferevent_getwatermark (struct bufferevent *bufev, short events, size_t *lowmark, size_t *highmark) |
Retrieves the watermarks for read or write events. More... | |
EVENT2_EXPORT_SYMBOL void | bufferevent_incref (struct bufferevent *bufev) |
Public interface to manually increase the reference count of a bufferevent this is useful in situations where a user may reference the bufferevent somewhere else (unknown to libevent) More... | |
EVENT2_EXPORT_SYMBOL void | bufferevent_lock (struct bufferevent *bufev) |
Acquire the lock on a bufferevent. More... | |
EVENT2_EXPORT_SYMBOL struct bufferevent * | bufferevent_pair_get_partner (struct bufferevent *bev) |
Given one bufferevent returned by bufferevent_pair_new(), returns the other one if it still exists. More... | |
EVENT2_EXPORT_SYMBOL int | bufferevent_pair_new (struct event_base *base, int options, struct bufferevent *pair[2]) |
Allocate a pair of linked bufferevents. More... | |
EVENT2_EXPORT_SYMBOL int | bufferevent_priority_set (struct bufferevent *bufev, int pri) |
Assign a priority to a bufferevent. More... | |
EVENT2_EXPORT_SYMBOL void | bufferevent_rate_limit_group_free (struct bufferevent_rate_limit_group *) |
Free a rate-limiting group. More... | |
EVENT2_EXPORT_SYMBOL struct bufferevent_rate_limit_group * | bufferevent_rate_limit_group_new (struct event_base *base, const struct ev_token_bucket_cfg *cfg) |
Create a new rate-limit group for bufferevents. More... | |
EVENT2_EXPORT_SYMBOL int | bufferevent_rate_limit_group_set_cfg (struct bufferevent_rate_limit_group *, const struct ev_token_bucket_cfg *) |
Change the rate-limiting settings for a given rate-limiting group. More... | |
EVENT2_EXPORT_SYMBOL int | bufferevent_rate_limit_group_set_min_share (struct bufferevent_rate_limit_group *, size_t) |
Change the smallest quantum we're willing to allocate to any single bufferevent in a group for reading or writing at a time. More... | |
EVENT2_EXPORT_SYMBOL size_t | bufferevent_read (struct bufferevent *bufev, void *data, size_t size) |
Read data from a bufferevent buffer. More... | |
EVENT2_EXPORT_SYMBOL int | bufferevent_read_buffer (struct bufferevent *bufev, struct evbuffer *buf) |
Read data from a bufferevent buffer into an evbuffer. More... | |
+EVENT2_EXPORT_SYMBOL int | bufferevent_remove_from_rate_limit_group (struct bufferevent *bev) |
Remove 'bev' from its current rate-limit group (if any). | |
EVENT2_EXPORT_SYMBOL int | bufferevent_replacefd (struct bufferevent *bufev, evutil_socket_t fd) |
Replaces the file descriptor on which the bufferevent operates. More... | |
EVENT2_EXPORT_SYMBOL int | bufferevent_set_max_single_read (struct bufferevent *bev, size_t size) |
Set the size limit for single read operation. More... | |
EVENT2_EXPORT_SYMBOL int | bufferevent_set_max_single_write (struct bufferevent *bev, size_t size) |
Set the size limit for single write operation. More... | |
EVENT2_EXPORT_SYMBOL int | bufferevent_set_rate_limit (struct bufferevent *bev, struct ev_token_bucket_cfg *cfg) |
Set the rate-limit of a the bufferevent 'bev' to the one specified in 'cfg'. More... | |
EVENT2_EXPORT_SYMBOL int | bufferevent_set_timeouts (struct bufferevent *bufev, const struct timeval *timeout_read, const struct timeval *timeout_write) |
Set the read and write timeout for a bufferevent. More... | |
EVENT2_EXPORT_SYMBOL void | bufferevent_setcb (struct bufferevent *bufev, bufferevent_data_cb readcb, bufferevent_data_cb writecb, bufferevent_event_cb eventcb, void *cbarg) |
Changes the callbacks for a bufferevent. More... | |
EVENT2_EXPORT_SYMBOL int | bufferevent_setfd (struct bufferevent *bufev, evutil_socket_t fd) |
Changes the file descriptor on which the bufferevent operates. More... | |
EVENT2_EXPORT_SYMBOL void | bufferevent_setwatermark (struct bufferevent *bufev, short events, size_t lowmark, size_t highmark) |
Sets the watermarks for read and write events. More... | |
EVENT2_EXPORT_SYMBOL int | bufferevent_socket_connect (struct bufferevent *bufev, const struct sockaddr *addr, int socklen) |
Launch a connect() attempt with a socket-based bufferevent. More... | |
EVENT2_EXPORT_SYMBOL int | bufferevent_socket_connect_hostname (struct bufferevent *bufev, struct evdns_base *evdns_base, int family, const char *hostname, int port) |
Resolve the hostname 'hostname' and connect to it as with bufferevent_socket_connect(). More... | |
EVENT2_EXPORT_SYMBOL int | bufferevent_socket_connect_hostname_hints (struct bufferevent *bufev, struct evdns_base *evdns_base, const struct evutil_addrinfo *hints_in, const char *hostname, int port) |
Resolve the hostname 'hostname' and connect to it as with bufferevent_socket_connect(). More... | |
EVENT2_EXPORT_SYMBOL int | bufferevent_socket_get_dns_error (struct bufferevent *bev) |
Return the error code for the last failed DNS lookup attempt made by bufferevent_socket_connect_hostname(). More... | |
EVENT2_EXPORT_SYMBOL struct bufferevent * | bufferevent_socket_new (struct event_base *base, evutil_socket_t fd, int options) |
Create a new socket bufferevent over an existing socket. More... | |
EVENT2_EXPORT_SYMBOL void | bufferevent_trigger (struct bufferevent *bufev, short iotype, int options) |
Triggers bufferevent data callbacks. More... | |
EVENT2_EXPORT_SYMBOL void | bufferevent_trigger_event (struct bufferevent *bufev, short what, int options) |
Triggers the bufferevent event callback. More... | |
EVENT2_EXPORT_SYMBOL void | bufferevent_unlock (struct bufferevent *bufev) |
Release the lock on a bufferevent. More... | |
EVENT2_EXPORT_SYMBOL int | bufferevent_write (struct bufferevent *bufev, const void *data, size_t size) |
Write data to a bufferevent buffer. More... | |
EVENT2_EXPORT_SYMBOL int | bufferevent_write_buffer (struct bufferevent *bufev, struct evbuffer *buf) |
Write data from an evbuffer to a bufferevent buffer. More... | |
EVENT2_EXPORT_SYMBOL void | ev_token_bucket_cfg_free (struct ev_token_bucket_cfg *cfg) |
Free all storage held in 'cfg'. More... | |
EVENT2_EXPORT_SYMBOL struct ev_token_bucket_cfg * | ev_token_bucket_cfg_new (size_t read_rate, size_t read_burst, size_t write_rate, size_t write_burst, const struct timeval *tick_len) |
Initialize and return a new object to configure the rate-limiting behavior of bufferevents. More... | |
Rate limit inspection | |
Return the current read or write bucket size for a bufferevent. +If it is not configured with a per-bufferevent ratelimit, return EV_SSIZE_MAX. This function does not inspect the group limit, if any. Note that it can return a negative value if the bufferevent has been made to read or write more than its limit. + | |
+EVENT2_EXPORT_SYMBOL ev_ssize_t | bufferevent_get_max_to_read (struct bufferevent *bev) |
+EVENT2_EXPORT_SYMBOL ev_ssize_t | bufferevent_get_max_to_write (struct bufferevent *bev) |
+EVENT2_EXPORT_SYMBOL ev_ssize_t | bufferevent_get_read_limit (struct bufferevent *bev) |
+EVENT2_EXPORT_SYMBOL const struct ev_token_bucket_cfg * | bufferevent_get_token_bucket_cfg (const struct bufferevent *bev) |
+EVENT2_EXPORT_SYMBOL ev_ssize_t | bufferevent_get_write_limit (struct bufferevent *bev) |
Group Rate limit inspection | |
Return the read or write bucket size for a bufferevent rate limit group. +Note that it can return a negative value if bufferevents in the group have been made to read or write more than their limits. + | |
+EVENT2_EXPORT_SYMBOL ev_ssize_t | bufferevent_rate_limit_group_get_read_limit (struct bufferevent_rate_limit_group *) |
+EVENT2_EXPORT_SYMBOL ev_ssize_t | bufferevent_rate_limit_group_get_write_limit (struct bufferevent_rate_limit_group *) |
Rate limit manipulation | |
Subtract a number of bytes from a bufferevent's read or write bucket. +The decrement value can be negative, if you want to manually refill the bucket. If the change puts the bucket above or below zero, the bufferevent will resume or suspend reading writing as appropriate. These functions make no change in the buckets for the bufferevent's group, if any. +Returns 0 on success, -1 on internal error. + | |
+EVENT2_EXPORT_SYMBOL int | bufferevent_decrement_read_limit (struct bufferevent *bev, ev_ssize_t decr) |
+EVENT2_EXPORT_SYMBOL int | bufferevent_decrement_write_limit (struct bufferevent *bev, ev_ssize_t decr) |
Group rate limit manipulation | |
Subtract a number of bytes from a bufferevent rate-limiting group's read or write bucket. +The decrement value can be negative, if you want to manually refill the bucket. If the change puts the bucket above or below zero, the bufferevents in the group will resume or suspend reading writing as appropriate. +Returns 0 on success, -1 on internal error. + | |
+EVENT2_EXPORT_SYMBOL int | bufferevent_rate_limit_group_decrement_read (struct bufferevent_rate_limit_group *, ev_ssize_t) |
+EVENT2_EXPORT_SYMBOL int | bufferevent_rate_limit_group_decrement_write (struct bufferevent_rate_limit_group *, ev_ssize_t) |
EVENT2_EXPORT_SYMBOL void | bufferevent_rate_limit_group_get_totals (struct bufferevent_rate_limit_group *grp, ev_uint64_t *total_read_out, ev_uint64_t *total_written_out) |
Inspect the total bytes read/written on a group. More... | |
EVENT2_EXPORT_SYMBOL void | bufferevent_rate_limit_group_reset_totals (struct bufferevent_rate_limit_group *grp) |
Reset the total bytes read/written on a group. More... | |
+Filtering support | |
typedef enum bufferevent_filter_result(* | bufferevent_filter_cb) (struct evbuffer *src, struct evbuffer *dst, ev_ssize_t dst_limit, enum bufferevent_flush_mode mode, void *ctx) |
A callback function to implement a filter for a bufferevent. More... | |
EVENT2_EXPORT_SYMBOL struct bufferevent * | bufferevent_filter_new (struct bufferevent *underlying, bufferevent_filter_cb input_filter, bufferevent_filter_cb output_filter, int options, void(*free_context)(void *), void *ctx) |
Allocate a new filtering bufferevent on top of an existing bufferevent. More... | |
enum | bufferevent_filter_result { BEV_OK = 0, +BEV_NEED_MORE = 1, +BEV_ERROR = 2 + } |
Values that filters can return. More... | |
Functions for buffering data for network sending or receiving.
+Bufferevents are higher level than evbuffers: each has an underlying evbuffer for reading and one for writing, and callbacks that are invoked under certain circumstances.
+A bufferevent provides input and output buffers that get filled and drained automatically. The user of a bufferevent no longer deals directly with the I/O, but instead is reading from input and writing to output buffers.
+Once initialized, the bufferevent structure can be used repeatedly with bufferevent_enable() and bufferevent_disable().
+When reading is enabled, the bufferevent will try to read from the file descriptor onto its input buffer, and call the read callback. When writing is enabled, the bufferevent will try to write data onto its file descriptor when the output buffer has enough data, and call the write callback when the output buffer is sufficiently drained.
+Bufferevents come in several flavors, including:
+A bufferevent that reads and writes data onto a network socket. Created with bufferevent_socket_new().
+ +A pair of bufferevents that send and receive data to one another without touching the network. Created with bufferevent_pair_new().
+ +A bufferevent that transforms data, and sends or receives it over another underlying bufferevent. Created with bufferevent_filter_new().
+ +typedef void(* bufferevent_data_cb) (struct bufferevent *bev, void *ctx) | +
A read or write callback for a 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.
+The write callback is triggered if the write buffer has been exhausted or fell below its low watermark.
+bev | the bufferevent that triggered the callback |
ctx | the user-specified context for this bufferevent |
typedef void(* bufferevent_event_cb) (struct bufferevent *bev, short what, void *ctx) | +
An event/error callback for a 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.
+bev | the bufferevent for which the error condition was reached |
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. |
ctx | the user-specified context for this bufferevent |
typedef enum bufferevent_filter_result(* bufferevent_filter_cb) (struct evbuffer *src, struct evbuffer *dst, ev_ssize_t dst_limit, enum bufferevent_flush_mode mode, void *ctx) | +
A callback function to implement a filter for a bufferevent.
+src | An evbuffer to drain data from. |
dst | An evbuffer to add data to. |
limit | A suggested upper bound of bytes to write to dst. The filter may ignore this value, but doing so means that it will overflow the high-water mark associated with dst. -1 means "no limit". |
mode | Whether we should write data as may be convenient (BEV_NORMAL), or flush as much data as we can (BEV_FLUSH), or flush as much as we can, possibly including an end-of-stream marker (BEV_FINISH). |
ctx | A user-supplied pointer. |
enum bufferevent_filter_result | +
enum bufferevent_flush_mode | +
enum bufferevent_options | +
Options that can be specified when creating a bufferevent.
+enum bufferevent_trigger_options | +
EVENT2_EXPORT_SYMBOL int bufferevent_add_to_rate_limit_group | +( | +struct bufferevent * | +bev, | +
+ | + | struct bufferevent_rate_limit_group * | +g | +
+ | ) | ++ |
Add 'bev' to the list of bufferevents whose aggregate reading and writing is restricted by 'g'.
+If 'g' is NULL, remove 'bev' from its current group.
+A bufferevent may belong to no more than one rate-limit group at a time. If 'bev' is already a member of a group, it will be removed from its old group before being added to 'g'.
+Return 0 on success and -1 on failure.
+ +EVENT2_EXPORT_SYMBOL int bufferevent_base_set | +( | +struct event_base * | +base, | +
+ | + | struct bufferevent * | +bufev | +
+ | ) | ++ |
Assign a bufferevent to a specific event_base.
+NOTE that only socket bufferevents support this function.
+base | an event_base returned by event_base_new() |
bufev | a bufferevent struct returned by bufferevent_new() or bufferevent_socket_new() |
EVENT2_EXPORT_SYMBOL int bufferevent_decref | +( | +struct bufferevent * | +bufev | ) | ++ |
Public interface to manually decrement the reference count of a bufferevent.
+Warning: make sure you know what you're doing. This is mainly used in conjunction with bufferevent_incref(). This will free up all data associated with a bufferevent if the reference count hits 0.
+bufev | the bufferevent to decrement the refcount on |
EVENT2_EXPORT_SYMBOL int bufferevent_disable | +( | +struct bufferevent * | +bufev, | +
+ | + | short | +event | +
+ | ) | ++ |
Disable a bufferevent.
+bufev | the bufferevent to be disabled. bufev must not be NULL. |
event | any combination of EV_READ | EV_WRITE. |
EVENT2_EXPORT_SYMBOL int bufferevent_enable | +( | +struct bufferevent * | +bufev, | +
+ | + | short | +event | +
+ | ) | ++ |
Enable a bufferevent.
+bufev | the bufferevent to be enabled. bufev must not be NULL. |
event | any combination of EV_READ | EV_WRITE. |
EVENT2_EXPORT_SYMBOL struct bufferevent* bufferevent_filter_new | +( | +struct bufferevent * | +underlying, | +
+ | + | bufferevent_filter_cb | +input_filter, | +
+ | + | bufferevent_filter_cb | +output_filter, | +
+ | + | int | +options, | +
+ | + | void(*)(void *) | +free_context, | +
+ | + | void * | +ctx | +
+ | ) | ++ |
Allocate a new filtering bufferevent on top of an existing bufferevent.
+underlying | the underlying bufferevent. |
input_filter | The filter to apply to data we read from the underlying bufferevent |
output_filter | The filer to apply to data we write to the underlying bufferevent |
options | A bitfield of bufferevent options. |
free_context | A function to use to free the filter context when this bufferevent is freed. |
ctx | A context pointer to pass to the filter functions. |
EVENT2_EXPORT_SYMBOL int bufferevent_flush | +( | +struct bufferevent * | +bufev, | +
+ | + | short | +iotype, | +
+ | + | enum bufferevent_flush_mode | +mode | +
+ | ) | ++ |
Triggers the bufferevent to produce more data if possible.
+bufev | the bufferevent object |
iotype | either EV_READ or EV_WRITE or both. |
mode | either BEV_NORMAL or BEV_FLUSH or BEV_FINISHED |
EVENT2_EXPORT_SYMBOL void bufferevent_free | +( | +struct bufferevent * | +bufev | ) | ++ |
Deallocate the storage associated with a bufferevent structure.
+If there is pending data to write on the bufferevent, it probably won't be flushed before the bufferevent is freed.
+bufev | the bufferevent structure to be freed. bufev must not be NULL. |
EVENT2_EXPORT_SYMBOL short bufferevent_get_enabled | +( | +struct bufferevent * | +bufev | ) | ++ |
Return the events that are enabled on a given bufferevent.
+bufev | the bufferevent to inspect |
EVENT2_EXPORT_SYMBOL struct evbuffer* bufferevent_get_input | +( | +struct bufferevent * | +bufev | ) | ++ |
Returns the input buffer.
+The user MUST NOT set the callback on this buffer.
+bufev | the bufferevent from which to get the evbuffer. bufev must not be NULL. |
EVENT2_EXPORT_SYMBOL struct evbuffer* bufferevent_get_output | +( | +struct bufferevent * | +bufev | ) | ++ |
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.
+bufev | the bufferevent from which to get the evbuffer. bufev must not be NULL. |
EVENT2_EXPORT_SYMBOL int bufferevent_get_priority | +( | +const struct bufferevent * | +bufev | ) | ++ |
Return the priority of a bufferevent.
+Only supported for socket bufferevents
+ +EVENT2_EXPORT_SYMBOL void bufferevent_getcb | +( | +struct bufferevent * | +bufev, | +
+ | + | bufferevent_data_cb * | +readcb_ptr, | +
+ | + | bufferevent_data_cb * | +writecb_ptr, | +
+ | + | bufferevent_event_cb * | +eventcb_ptr, | +
+ | + | void ** | +cbarg_ptr | +
+ | ) | ++ |
Retrieves the callbacks for a bufferevent.
+bufev | the bufferevent to examine. |
readcb_ptr | if readcb_ptr is nonnull, *readcb_ptr is set to the current read callback for the bufferevent. |
writecb_ptr | if writecb_ptr is nonnull, *writecb_ptr is set to the current write callback for the bufferevent. |
eventcb_ptr | if eventcb_ptr is nonnull, *eventcb_ptr is set to the current event callback for the bufferevent. |
cbarg_ptr | if cbarg_ptr is nonnull, *cbarg_ptr is set to the current callback argument for the bufferevent. |
EVENT2_EXPORT_SYMBOL evutil_socket_t bufferevent_getfd | +( | +struct bufferevent * | +bufev | ) | ++ |
Returns the file descriptor associated with a bufferevent, or -1 if no file descriptor is associated with the bufferevent.
+bufev must not be NULL.
+ +EVENT2_EXPORT_SYMBOL int bufferevent_getwatermark | +( | +struct bufferevent * | +bufev, | +
+ | + | short | +events, | +
+ | + | size_t * | +lowmark, | +
+ | + | size_t * | +highmark | +
+ | ) | ++ |
Retrieves the watermarks for read or write events.
+Returns non-zero if events contains not only EV_READ or EV_WRITE. Returns zero if events equal EV_READ or EV_WRITE
+bufev | the bufferevent to be examined |
events | EV_READ or EV_WRITE |
lowmark | receives the lower watermark if not NULL |
highmark | receives the high watermark if not NULL |
EVENT2_EXPORT_SYMBOL void bufferevent_incref | +( | +struct bufferevent * | +bufev | ) | ++ |
Public interface to manually increase the reference count of a bufferevent this is useful in situations where a user may reference the bufferevent somewhere else (unknown to libevent)
+bufev | the bufferevent to increase the refcount on |
EVENT2_EXPORT_SYMBOL void bufferevent_lock | +( | +struct bufferevent * | +bufev | ) | ++ |
Acquire the lock on a bufferevent.
+Has no effect if locking was not enabled with BEV_OPT_THREADSAFE.
+ +EVENT2_EXPORT_SYMBOL struct bufferevent* bufferevent_pair_get_partner | +( | +struct bufferevent * | +bev | ) | ++ |
Given one bufferevent returned by bufferevent_pair_new(), returns the other one if it still exists.
+Otherwise returns NULL.
+ +EVENT2_EXPORT_SYMBOL int bufferevent_pair_new | +( | +struct event_base * | +base, | +
+ | + | int | +options, | +
+ | + | struct bufferevent * | +pair[2] | +
+ | ) | ++ |
Allocate a pair of linked bufferevents.
+The bufferevents behave as would two bufferevent_sock instances connected to opposite ends of a socketpair(), except that no internal socketpair is allocated.
+base | The event base to associate with the socketpair. |
options | A set of options for this bufferevent |
pair | A pointer to an array to hold the two new bufferevent objects. |
EVENT2_EXPORT_SYMBOL int bufferevent_priority_set | +( | +struct bufferevent * | +bufev, | +
+ | + | int | +pri | +
+ | ) | ++ |
Assign a priority to a bufferevent.
+Only supported for socket bufferevents.
+bufev | a bufferevent struct |
pri | the priority to be assigned |
EVENT2_EXPORT_SYMBOL void bufferevent_rate_limit_group_free | +( | +struct bufferevent_rate_limit_group * | +) | ++ |
Free a rate-limiting group.
+The group must have no members when this function is called.
+ +EVENT2_EXPORT_SYMBOL void bufferevent_rate_limit_group_get_totals | +( | +struct bufferevent_rate_limit_group * | +grp, | +
+ | + | ev_uint64_t * | +total_read_out, | +
+ | + | ev_uint64_t * | +total_written_out | +
+ | ) | ++ |
Inspect the total bytes read/written on a group.
+Set the variable pointed to by total_read_out to the total number of bytes ever read on grp, and the variable pointed to by total_written_out to the total number of bytes ever written on grp.
+ +EVENT2_EXPORT_SYMBOL struct bufferevent_rate_limit_group* bufferevent_rate_limit_group_new | +( | +struct event_base * | +base, | +
+ | + | const struct ev_token_bucket_cfg * | +cfg | +
+ | ) | ++ |
Create a new rate-limit group for bufferevents.
+A rate-limit group constrains the maximum number of bytes sent and received, in toto, by all of its bufferevents.
+base | An event_base to run any necessary timeouts for the group. Note that all bufferevents in the group do not necessarily need to share this event_base. |
cfg | The rate-limit for this group. |
Note that all rate-limits hare are currently best-effort: future versions of Libevent may implement them more tightly.
+Note also that only some bufferevent types currently respect rate-limiting. They are: socket-based bufferevents (normal and IOCP-based), and SSL-based bufferevents.
+ +EVENT2_EXPORT_SYMBOL void bufferevent_rate_limit_group_reset_totals | +( | +struct bufferevent_rate_limit_group * | +grp | ) | ++ |
Reset the total bytes read/written on a group.
+Reset the number of bytes read or written on grp as given by bufferevent_rate_limit_group_reset_totals().
+ +EVENT2_EXPORT_SYMBOL int bufferevent_rate_limit_group_set_cfg | +( | +struct bufferevent_rate_limit_group * | +, | +
+ | + | const struct ev_token_bucket_cfg * | ++ |
+ | ) | ++ |
Change the rate-limiting settings for a given rate-limiting group.
+Return 0 on success, -1 on failure.
+ +EVENT2_EXPORT_SYMBOL int bufferevent_rate_limit_group_set_min_share | +( | +struct bufferevent_rate_limit_group * | +, | +
+ | + | size_t | ++ |
+ | ) | ++ |
Change the smallest quantum we're willing to allocate to any single bufferevent in a group for reading or writing at a time.
+The rationale is that, because of TCP/IP protocol overheads and kernel behavior, if a rate-limiting group is so tight on bandwidth that you're only willing to send 1 byte per tick per bufferevent, you might instead want to batch up the reads and writes so that you send N bytes per 1/N of the bufferevents (chosen at random) each tick, so you still wind up send 1 byte per tick per bufferevent on average, but you don't send so many tiny packets.
+The default min-share is currently 64 bytes.
+Returns 0 on success, -1 on failure.
+ +EVENT2_EXPORT_SYMBOL size_t bufferevent_read | +( | +struct bufferevent * | +bufev, | +
+ | + | void * | +data, | +
+ | + | size_t | +size | +
+ | ) | ++ |
Read data from a bufferevent buffer.
+The bufferevent_read() function is used to read data from the input buffer.
+bufev | the bufferevent to be read from |
data | pointer to a buffer that will store the data |
size | the size of the data buffer, in bytes |
EVENT2_EXPORT_SYMBOL int bufferevent_read_buffer | +( | +struct bufferevent * | +bufev, | +
+ | + | struct evbuffer * | +buf | +
+ | ) | ++ |
Read data from a bufferevent buffer into an evbuffer.
+This avoids memory copies.
+bufev | the bufferevent to be read from |
buf | the evbuffer to which to add data |
EVENT2_EXPORT_SYMBOL int bufferevent_replacefd | +( | +struct bufferevent * | +bufev, | +
+ | + | evutil_socket_t | +fd | +
+ | ) | ++ |
Replaces the file descriptor on which the bufferevent operates.
+Not supported for all bufferevent types.
+Unlike bufferevent_setfd() it will close previous file descriptor (if any).
+bufev | the bufferevent object for which to change the file descriptor |
fd | the file descriptor to operate on |
EVENT2_EXPORT_SYMBOL int bufferevent_set_max_single_read | +( | +struct bufferevent * | +bev, | +
+ | + | size_t | +size | +
+ | ) | ++ |
Set the size limit for single read operation.
+Set to 0 for a reasonable default.
+Return 0 on success and -1 on failure.
+EVENT2_EXPORT_SYMBOL int bufferevent_set_max_single_write | +( | +struct bufferevent * | +bev, | +
+ | + | size_t | +size | +
+ | ) | ++ |
Set the size limit for single write operation.
+Set to 0 for a reasonable default.
+Return 0 on success and -1 on failure.
+ +EVENT2_EXPORT_SYMBOL int bufferevent_set_rate_limit | +( | +struct bufferevent * | +bev, | +
+ | + | struct ev_token_bucket_cfg * | +cfg | +
+ | ) | ++ |
Set the rate-limit of a the bufferevent 'bev' to the one specified in 'cfg'.
+If 'cfg' is NULL, disable any per-bufferevent rate-limiting on 'bev'.
+Note that only some bufferevent types currently respect rate-limiting. They are: socket-based bufferevents (normal and IOCP-based), and SSL-based bufferevents.
+Return 0 on success, -1 on failure.
+ +EVENT2_EXPORT_SYMBOL int bufferevent_set_timeouts | +( | +struct bufferevent * | +bufev, | +
+ | + | const struct timeval * | +timeout_read, | +
+ | + | const struct timeval * | +timeout_write | +
+ | ) | ++ |
Set the read and write timeout for a bufferevent.
+A bufferevent's timeout will fire the first time that the indicated amount of time has elapsed since a successful read or write operation, during which the bufferevent was trying to read or write.
+(In other words, if reading or writing is disabled, or if the bufferevent's read or write operation has been suspended because there's no data to write, or not enough bandwidth, or so on, the timeout isn't active. The timeout only becomes active when we we're willing to actually read or write.)
+Calling bufferevent_enable or setting a timeout for a bufferevent whose timeout is already pending resets its timeout.
+If the timeout elapses, the corresponding operation (EV_READ or EV_WRITE) becomes disabled until you re-enable it again. The bufferevent's event callback is called with the BEV_EVENT_TIMEOUT|BEV_EVENT_READING or BEV_EVENT_TIMEOUT|BEV_EVENT_WRITING.
+bufev | the bufferevent to be modified |
timeout_read | the read timeout, or NULL |
timeout_write | the write timeout, or NULL |
EVENT2_EXPORT_SYMBOL void bufferevent_setcb | +( | +struct bufferevent * | +bufev, | +
+ | + | bufferevent_data_cb | +readcb, | +
+ | + | bufferevent_data_cb | +writecb, | +
+ | + | bufferevent_event_cb | +eventcb, | +
+ | + | void * | +cbarg | +
+ | ) | ++ |
Changes the callbacks for a bufferevent.
+bufev | the bufferevent object for which to change callbacks. bufev must not be NULL. |
readcb | callback to invoke when there is data to be read, or NULL if no callback is desired |
writecb | callback to invoke when the file descriptor is ready for writing, or NULL if no callback is desired |
eventcb | callback to invoke when there is an event on the file descriptor |
cbarg | an argument that will be supplied to each of the callbacks (readcb, writecb, and errorcb) |
EVENT2_EXPORT_SYMBOL int bufferevent_setfd | +( | +struct bufferevent * | +bufev, | +
+ | + | evutil_socket_t | +fd | +
+ | ) | ++ |
Changes the file descriptor on which the bufferevent operates.
+Not supported for all bufferevent types.
+bufev | the bufferevent object for which to change the file descriptor |
fd | the file descriptor to operate on |
EVENT2_EXPORT_SYMBOL void bufferevent_setwatermark | +( | +struct bufferevent * | +bufev, | +
+ | + | short | +events, | +
+ | + | size_t | +lowmark, | +
+ | + | size_t | +highmark | +
+ | ) | ++ |
Sets the watermarks for read and write events.
+On input, a bufferevent does not invoke the user read callback unless there is at least low watermark data in the buffer. If the read buffer is beyond the high watermark, the bufferevent stops reading from the network. But be aware that bufferevent input/read buffer can overrun high watermark limit (typical example is openssl bufferevent), so you should not relay in this.
+On output, the user write callback is invoked whenever the buffered data falls below the low watermark. Filters that write to this bufev will try not to write more bytes to this buffer than the high watermark would allow, except when flushing.
+bufev | the bufferevent to be modified. bufev must not be NULL. |
events | EV_READ, EV_WRITE or both |
lowmark | the lower watermark to set |
highmark | the high watermark to set |
EVENT2_EXPORT_SYMBOL int bufferevent_socket_connect | +( | +struct bufferevent * | +bufev, | +
+ | + | const struct sockaddr * | +addr, | +
+ | + | int | +socklen | +
+ | ) | ++ |
Launch a connect() attempt with a socket-based bufferevent.
+When the connect succeeds, the eventcb will be invoked with BEV_EVENT_CONNECTED set.
+If the bufferevent does not already have a socket set, we allocate a new socket here and make it nonblocking before we begin.
+If no address is provided, we assume that the socket is already connecting, and configure the bufferevent so that a BEV_EVENT_CONNECTED event will be yielded when it is done connecting.
+bufev | an existing bufferevent allocated with bufferevent_socket_new(). |
addr | the address we should connect to |
socklen | The length of the address |
EVENT2_EXPORT_SYMBOL int bufferevent_socket_connect_hostname | +( | +struct bufferevent * | +bufev, | +
+ | + | struct evdns_base * | +evdns_base, | +
+ | + | int | +family, | +
+ | + | const char * | +hostname, | +
+ | + | int | +port | +
+ | ) | ++ |
Resolve the hostname 'hostname' and connect to it as with bufferevent_socket_connect().
+bufev | An existing bufferevent allocated with bufferevent_socket_new() |
evdns_base | Optionally, an evdns_base to use for resolving hostnames asynchronously. May be set to NULL for a blocking resolve. |
family | A preferred address family to resolve addresses to, or AF_UNSPEC for no preference. Only AF_INET, AF_INET6, and AF_UNSPEC are supported. |
hostname | The hostname to resolve; see below for notes on recognized formats |
port | The port to connect to on the resolved address. |
EVENT2_EXPORT_SYMBOL int bufferevent_socket_connect_hostname_hints | +( | +struct bufferevent * | +bufev, | +
+ | + | struct evdns_base * | +evdns_base, | +
+ | + | const struct evutil_addrinfo * | +hints_in, | +
+ | + | const char * | +hostname, | +
+ | + | int | +port | +
+ | ) | ++ |
Resolve the hostname 'hostname' and connect to it as with bufferevent_socket_connect().
+bufev | An existing bufferevent allocated with bufferevent_socket_new() |
evdns_base | Optionally, an evdns_base to use for resolving hostnames asynchronously. May be set to NULL for a blocking resolve. |
hints_in | points to an addrinfo structure that specifies criteria for selecting the socket address structures to be used |
hostname | The hostname to resolve; see below for notes on recognized formats |
port | The port to connect to on the resolved address. |
Recognized hostname formats are:
www.example.com (hostname) +1.2.3.4 (ipv4address) +::1 (ipv6address) +[::1] ([ipv6address]) +
Performance note: If you do not provide an evdns_base, this function may block while it waits for a DNS response. This is probably not what you want.
+ +EVENT2_EXPORT_SYMBOL int bufferevent_socket_get_dns_error | +( | +struct bufferevent * | +bev | ) | ++ |
Return the error code for the last failed DNS lookup attempt made by bufferevent_socket_connect_hostname().
+bev | The bufferevent object. |
EVENT2_EXPORT_SYMBOL struct bufferevent* bufferevent_socket_new | +( | +struct event_base * | +base, | +
+ | + | evutil_socket_t | +fd, | +
+ | + | int | +options | +
+ | ) | ++ |
Create a new socket bufferevent over an existing socket.
+base | the event base to associate with the new bufferevent. base must not be NULL. |
fd | the file descriptor from which data is read and written to. This file descriptor is not allowed to be a pipe(2). It is safe to set the fd to -1, so long as you later set it with bufferevent_setfd or bufferevent_socket_connect(). |
options | Zero or more BEV_OPT_* flags |
EVENT2_EXPORT_SYMBOL void bufferevent_trigger | +( | +struct bufferevent * | +bufev, | +
+ | + | short | +iotype, | +
+ | + | int | +options | +
+ | ) | ++ |
Triggers bufferevent data callbacks.
+The function will honor watermarks unless options contain BEV_TRIG_IGNORE_WATERMARKS. If the options contain BEV_OPT_DEFER_CALLBACKS, the callbacks are deferred.
+bufev | the bufferevent object |
iotype | either EV_READ or EV_WRITE or both. |
options |
EVENT2_EXPORT_SYMBOL void bufferevent_trigger_event | +( | +struct bufferevent * | +bufev, | +
+ | + | short | +what, | +
+ | + | int | +options | +
+ | ) | ++ |
Triggers the bufferevent event callback.
+If the options contain BEV_OPT_DEFER_CALLBACKS, the callbacks are deferred.
+bufev | the bufferevent object |
what | the flags to pass onto the event callback |
options |
EVENT2_EXPORT_SYMBOL void bufferevent_unlock | +( | +struct bufferevent * | +bufev | ) | ++ |
Release the lock on a bufferevent.
+Has no effect if locking was not enabled with BEV_OPT_THREADSAFE.
+ +EVENT2_EXPORT_SYMBOL int bufferevent_write | +( | +struct bufferevent * | +bufev, | +
+ | + | const void * | +data, | +
+ | + | size_t | +size | +
+ | ) | ++ |
Write data to a bufferevent buffer.
+The bufferevent_write() function can be used to write data to the file descriptor. The data is appended to the output buffer and written to the descriptor automatically as it becomes available for writing.
+bufev | the bufferevent to be written to |
data | a pointer to the data to be written |
size | the length of the data, in bytes |
EVENT2_EXPORT_SYMBOL int bufferevent_write_buffer | +( | +struct bufferevent * | +bufev, | +
+ | + | struct evbuffer * | +buf | +
+ | ) | ++ |
Write data from an evbuffer to a bufferevent buffer.
+The evbuffer is being drained as a result.
+bufev | the bufferevent to be written to |
buf | the evbuffer to be written |
EVENT2_EXPORT_SYMBOL void ev_token_bucket_cfg_free | +( | +struct ev_token_bucket_cfg * | +cfg | ) | ++ |
Free all storage held in 'cfg'.
+Note: 'cfg' is not currently reference-counted; it is not safe to free it until no bufferevent is using it.
+ +EVENT2_EXPORT_SYMBOL struct ev_token_bucket_cfg* ev_token_bucket_cfg_new | +( | +size_t | +read_rate, | +
+ | + | size_t | +read_burst, | +
+ | + | size_t | +write_rate, | +
+ | + | size_t | +write_burst, | +
+ | + | const struct timeval * | +tick_len | +
+ | ) | ++ |
Initialize and return a new object to configure the rate-limiting behavior of bufferevents.
+read_rate | The maximum number of bytes to read per tick on average. |
read_burst | The maximum number of bytes to read in any single tick. |
write_rate | The maximum number of bytes to write per tick on average. |
write_burst | The maximum number of bytes to write in any single tick. |
tick_len | The length of a single tick. Defaults to one second. Any fractions of a millisecond are ignored. |
Note that all rate-limits hare are currently best-effort: future versions of Libevent may implement them more tightly.
+ +
+ libevent
+ 2.2.1
+
+ Event notification library
+ |
+
+ libevent
+ 2.2.1
+
+ Event notification library
+ |
+
Deprecated versions of the functions in bufferevent.h: provided only for backwards compatibility. +More...
+#include <event2/visibility.h>
Go to the source code of this file.
++Macros | |
+#define | EVBUFFER_EOF BEV_EVENT_EOF |
+#define | EVBUFFER_ERROR BEV_EVENT_ERROR |
+#define | EVBUFFER_INPUT(x) bufferevent_get_input(x) |
macro for getting access to the input buffer of a bufferevent | |
+#define | EVBUFFER_OUTPUT(x) bufferevent_get_output(x) |
macro for getting access to the output buffer of a bufferevent | |
+#define | EVBUFFER_READ BEV_EVENT_READING |
+#define | EVBUFFER_TIMEOUT BEV_EVENT_TIMEOUT |
+#define | EVBUFFER_WRITE BEV_EVENT_WRITING |
+#define | evbuffercb bufferevent_data_cb |
+#define | everrorcb bufferevent_event_cb |
+Functions | |
EVENT2_EXPORT_SYMBOL struct bufferevent * | bufferevent_new (evutil_socket_t fd, evbuffercb readcb, evbuffercb writecb, everrorcb errorcb, void *cbarg) |
Create a new bufferevent for an fd. More... | |
EVENT2_EXPORT_SYMBOL void | bufferevent_settimeout (struct bufferevent *bufev, int timeout_read, int timeout_write) |
Set the read and write timeout for a buffered event. More... | |
Deprecated versions of the functions in bufferevent.h: provided only for backwards compatibility.
+EVENT2_EXPORT_SYMBOL struct bufferevent* bufferevent_new | +( | +evutil_socket_t | +fd, | +
+ | + | evbuffercb | +readcb, | +
+ | + | evbuffercb | +writecb, | +
+ | + | everrorcb | +errorcb, | +
+ | + | void * | +cbarg | +
+ | ) | ++ |
Create a new bufferevent for an fd.
+This function is deprecated. Use bufferevent_socket_new() and bufferevent_setcb() instead.
+Libevent provides an abstraction on top of the regular event callbacks. This abstraction is called a buffered event. A buffered event provides input and output buffers that get filled and drained automatically. The user of a buffered event no longer deals directly with the I/O, but instead is reading from input and writing to output buffers.
+Once initialized, the bufferevent structure can be used repeatedly with bufferevent_enable() and bufferevent_disable().
+When read enabled the bufferevent will try to read from the file descriptor and call the read callback. The write callback is executed whenever the output buffer is drained below the write low watermark, which is 0 by default.
+If multiple bases are in use, bufferevent_base_set() must be called before enabling the bufferevent for the first time.
+fd | the file descriptor from which data is read and written to. This file descriptor is not allowed to be a pipe(2). |
readcb | callback to invoke when there is data to be read, or NULL if no callback is desired |
writecb | callback to invoke when the file descriptor is ready for writing, or NULL if no callback is desired |
errorcb | callback to invoke when there is an error on the file descriptor |
cbarg | an argument that will be supplied to each of the callbacks (readcb, writecb, and errorcb) |
EVENT2_EXPORT_SYMBOL void bufferevent_settimeout | +( | +struct bufferevent * | +bufev, | +
+ | + | int | +timeout_read, | +
+ | + | int | +timeout_write | +
+ | ) | ++ |
Set the read and write timeout for a buffered event.
+bufev | the bufferevent to be modified |
timeout_read | the read timeout |
timeout_write | the write timeout |
+ libevent
+ 2.2.1
+
+ Event notification library
+ |
+
+ libevent
+ 2.2.1
+
+ Event notification library
+ |
+
OpenSSL support for bufferevents. +More...
+#include <event2/visibility.h>
#include <event2/event-config.h>
#include <event2/bufferevent.h>
#include <event2/util.h>
Go to the source code of this file.
++Macros | |
#define | BUFFEREVENT_SSL_BATCH_WRITE 2 |
Control writes in the SSL bufferevents. More... | |
#define | BUFFEREVENT_SSL_DIRTY_SHUTDOWN 1 |
Control how to report dirty SSL shutdowns. More... | |
+Typedefs | |
+typedef struct mbedtls_ssl_context | mbedtls_dyncontext |
+Enumerations | |
enum | bufferevent_ssl_state { BUFFEREVENT_SSL_OPEN = 0, +BUFFEREVENT_SSL_CONNECTING = 1, +BUFFEREVENT_SSL_ACCEPTING = 2 + } |
The state of an SSL object to be used when creating a new SSL bufferevent. | |
+Functions | |
+EVENT2_EXPORT_SYMBOL unsigned long | bufferevent_get_mbedtls_error (struct bufferevent *bev) |
Return the most recent MbedTLS error reported on an SSL bufferevent. | |
+EVENT2_EXPORT_SYMBOL unsigned long | bufferevent_get_openssl_error (struct bufferevent *bev) |
Return the most recent OpenSSL error reported on an SSL bufferevent. | |
+EVENT2_EXPORT_SYMBOL void | bufferevent_mbedtls_dyncontext_free (mbedtls_dyncontext *ctx) |
Deallocate heap-based MbedTLS context. | |
+EVENT2_EXPORT_SYMBOL mbedtls_dyncontext * | bufferevent_mbedtls_dyncontext_new (struct mbedtls_ssl_config *conf) |
Create a new heap-based MbedTLS context for use it in bufferevent_mbedtls_* functions. | |
EVENT2_EXPORT_SYMBOL struct bufferevent * | bufferevent_mbedtls_filter_new (struct event_base *base, struct bufferevent *underlying, mbedtls_dyncontext *ssl, enum bufferevent_ssl_state state, int options) |
Create a new SSL bufferevent to send its data over another bufferevent. More... | |
EVENT2_EXPORT_SYMBOL int | bufferevent_mbedtls_get_allow_dirty_shutdown (struct bufferevent *bev) |
Get value of the BUFFEREVENT_SSL_DIRTY_SHUTDOWN flag. More... | |
+EVENT2_EXPORT_SYMBOL struct mbedtls_ssl_context * | bufferevent_mbedtls_get_ssl (struct bufferevent *bufev) |
Return the underlying mbedtls SSL * object for an SSL bufferevent. | |
+EVENT2_EXPORT_SYMBOL int | bufferevent_mbedtls_renegotiate (struct bufferevent *bev) |
Tells a bufferevent to begin SSL renegotiation. | |
EVENT2_EXPORT_SYMBOL void | bufferevent_mbedtls_set_allow_dirty_shutdown (struct bufferevent *bev, int allow_dirty_shutdown) |
Set value of the BUFFEREVENT_SSL_DIRTY_SHUTDOWN flag. More... | |
EVENT2_EXPORT_SYMBOL struct bufferevent * | bufferevent_mbedtls_socket_new (struct event_base *base, evutil_socket_t fd, mbedtls_dyncontext *ssl, enum bufferevent_ssl_state state, int options) |
Create a new SSL bufferevent to send its data over an SSL * on a socket. More... | |
EVENT2_EXPORT_SYMBOL struct bufferevent * | bufferevent_openssl_filter_new (struct event_base *base, struct bufferevent *underlying, struct ssl_st *ssl, enum bufferevent_ssl_state state, int options) |
Create a new SSL bufferevent to send its data over another bufferevent. More... | |
EVENT2_EXPORT_SYMBOL int | bufferevent_openssl_get_allow_dirty_shutdown (struct bufferevent *bev) |
Get value of the BUFFEREVENT_SSL_DIRTY_SHUTDOWN flag. More... | |
+EVENT2_EXPORT_SYMBOL struct ssl_st * | bufferevent_openssl_get_ssl (struct bufferevent *bufev) |
Return the underlying openssl SSL * object for an SSL bufferevent. | |
EVENT2_EXPORT_SYMBOL void | bufferevent_openssl_set_allow_dirty_shutdown (struct bufferevent *bev, int allow_dirty_shutdown) |
Set value of the BUFFEREVENT_SSL_DIRTY_SHUTDOWN flag. More... | |
EVENT2_EXPORT_SYMBOL struct bufferevent * | bufferevent_openssl_socket_new (struct event_base *base, evutil_socket_t fd, struct ssl_st *ssl, enum bufferevent_ssl_state state, int options) |
Create a new SSL bufferevent to send its data over an SSL * on a socket. More... | |
+EVENT2_EXPORT_SYMBOL int | bufferevent_ssl_renegotiate (struct bufferevent *bev) |
Tells a bufferevent to begin SSL renegotiation. | |
OpenSSL support for bufferevents.
+#define BUFFEREVENT_SSL_BATCH_WRITE 2 | +
Control writes in the SSL bufferevents.
+By default SSL bufferevent will peek bytes from the buffer as the arrived. with respect to the segment boundaries in the buffer. However, by ignoring these segment boundaries number of packets to send can be decreased.
+This flags will ignore the segment boundaries.
+Useful in conjunction with http layer.
+ +#define BUFFEREVENT_SSL_DIRTY_SHUTDOWN 1 | +
Control how to report dirty SSL shutdowns.
+If the peer (or the network, or an attacker) closes the TCP connection before closing the SSL channel, and the protocol is SSL >= v3, this is a "dirty" shutdown. If BUFFEREVENT_SSL_DIRTY_SHUTDOWN is not set (default), this is reported as BEV_EVENT_ERROR.
+If instead BUFFEREVENT_SSL_DIRTY_SHUTDOWN is set, a dirty shutdown is reported as BEV_EVENT_EOF.
+(Note that if the protocol is < SSLv3, you will always receive BEV_EVENT_EOF, since SSL 2 and earlier cannot distinguish a secure connection close from a dirty one. This is one reason (among many) not to use SSL 2.)
+ +EVENT2_EXPORT_SYMBOL struct bufferevent* bufferevent_mbedtls_filter_new | +( | +struct event_base * | +base, | +
+ | + | struct bufferevent * | +underlying, | +
+ | + | mbedtls_dyncontext * | +ssl, | +
+ | + | enum bufferevent_ssl_state | +state, | +
+ | + | int | +options | +
+ | ) | ++ |
Create a new SSL bufferevent to send its data over another bufferevent.
+base | An event_base to use to detect reading and writing. It must also be the base for the underlying bufferevent. |
underlying | A socket to use for this SSL |
ssl | A SSL* object from openssl. |
state | The current state of the SSL connection |
options | One or more bufferevent_options |
EVENT2_EXPORT_SYMBOL int bufferevent_mbedtls_get_allow_dirty_shutdown | +( | +struct bufferevent * | +bev | ) | ++ |
Get value of the BUFFEREVENT_SSL_DIRTY_SHUTDOWN flag.
+EVENT2_EXPORT_SYMBOL void bufferevent_mbedtls_set_allow_dirty_shutdown | +( | +struct bufferevent * | +bev, | +
+ | + | int | +allow_dirty_shutdown | +
+ | ) | ++ |
Set value of the BUFFEREVENT_SSL_DIRTY_SHUTDOWN flag.
+EVENT2_EXPORT_SYMBOL struct bufferevent* bufferevent_mbedtls_socket_new | +( | +struct event_base * | +base, | +
+ | + | evutil_socket_t | +fd, | +
+ | + | mbedtls_dyncontext * | +ssl, | +
+ | + | enum bufferevent_ssl_state | +state, | +
+ | + | int | +options | +
+ | ) | ++ |
Create a new SSL bufferevent to send its data over an SSL * on a socket.
+base | An event_base to use to detect reading and writing |
fd | A socket to use for this SSL |
ssl | A SSL* object from mbedtls. |
state | The current state of the SSL connection |
options | One or more bufferevent_options |
EVENT2_EXPORT_SYMBOL struct bufferevent* bufferevent_openssl_filter_new | +( | +struct event_base * | +base, | +
+ | + | struct bufferevent * | +underlying, | +
+ | + | struct ssl_st * | +ssl, | +
+ | + | enum bufferevent_ssl_state | +state, | +
+ | + | int | +options | +
+ | ) | ++ |
Create a new SSL bufferevent to send its data over another bufferevent.
+base | An event_base to use to detect reading and writing. It must also be the base for the underlying bufferevent. |
underlying | A socket to use for this SSL |
ssl | A SSL* object from openssl. |
state | The current state of the SSL connection |
options | One or more bufferevent_options |
EVENT2_EXPORT_SYMBOL int bufferevent_openssl_get_allow_dirty_shutdown | +( | +struct bufferevent * | +bev | ) | ++ |
Get value of the BUFFEREVENT_SSL_DIRTY_SHUTDOWN flag.
+EVENT2_EXPORT_SYMBOL void bufferevent_openssl_set_allow_dirty_shutdown | +( | +struct bufferevent * | +bev, | +
+ | + | int | +allow_dirty_shutdown | +
+ | ) | ++ |
Set value of the BUFFEREVENT_SSL_DIRTY_SHUTDOWN flag.
+EVENT2_EXPORT_SYMBOL struct bufferevent* bufferevent_openssl_socket_new | +( | +struct event_base * | +base, | +
+ | + | evutil_socket_t | +fd, | +
+ | + | struct ssl_st * | +ssl, | +
+ | + | enum bufferevent_ssl_state | +state, | +
+ | + | int | +options | +
+ | ) | ++ |
Create a new SSL bufferevent to send its data over an SSL * on a socket.
+base | An event_base to use to detect reading and writing |
fd | A socket to use for this SSL |
ssl | A SSL* object from openssl. |
state | The current state of the SSL connection |
options | One or more bufferevent_options |
+ libevent
+ 2.2.1
+
+ Event notification library
+ |
+
+ libevent
+ 2.2.1
+
+ Event notification library
+ |
+
|
+evbuffer_cb_info | +event_base | +evthread_lock_callbacks | +|
evbuffer_iovec | +event_config | +evutil_addrinfo | +||
bufferevent | +evbuffer_ptr | +evhttp_ext_method | +evutil_monotonic_timer | +|
|
+event | +evthread_condition_callbacks | +||
evbuffer | +||||
+ libevent
+ 2.2.1
+
+ Event notification library
+ |
+
+ libevent
+ 2.2.1
+
+ Event notification library
+ |
+
+Files | |
file | buffer.h [code] |
Functions for buffering data for network sending or receiving. | |
file | buffer_compat.h [code] |
Obsolete and deprecated versions of the functions in buffer.h: provided only for backward compatibility. | |
file | bufferevent.h [code] |
Functions for buffering data for network sending or receiving. | |
file | bufferevent_compat.h [code] |
Deprecated versions of the functions in bufferevent.h: provided only for backwards compatibility. | |
file | bufferevent_ssl.h [code] |
OpenSSL support for bufferevents. | |
file | dns.h [code] |
Provides a few APIs to use for resolving DNS names, and a facility for implementing simple DNS servers. | |
file | dns_compat.h [code] |
Potentially non-threadsafe versions of the functions in dns.h: provided only for backwards compatibility. | |
file | event.h [code] |
Core functions for waiting for and receiving events, and using event bases. | |
file | event_compat.h [code] |
Potentially non-threadsafe versions of the functions in event.h: provided only for backwards compatibility. | |
file | http.h [code] |
Basic support for HTTP serving. | |
file | http_compat.h [code] |
Potentially non-threadsafe versions of the functions in http.h: provided only for backwards compatibility. | |
file | listener.h [code] |
A callback that we invoke when a listener has a new connection. | |
file | rpc.h [code] |
This header files provides basic support for an RPC server and client. | |
file | rpc_compat.h [code] |
Deprecated versions of the functions in rpc.h: provided only for backwards compatibility. | |
file | tag.h [code] |
Helper functions for reading and writing tagged data onto buffers. | |
file | tag_compat.h [code] |
Obsolete/deprecated functions from tag.h; provided only for backwards compatibility. | |
file | thread.h [code] |
Functions for multi-threaded applications using Libevent. | |
file | util.h [code] |
Common convenience functions for cross-platform portability and related socket manipulations. | |
file | watch.h [code] |
"Prepare" and "check" watchers. | |
+ libevent
+ 2.2.1
+
+ Event notification library
+ |
+
Provides a few APIs to use for resolving DNS names, and a facility for implementing simple DNS servers. +More...
+ +Go to the source code of this file.
++Macros | |
+#define | DNS_CNAME 4 |
+#define | DNS_CNAME_CALLBACK 0x80 |
Make a separate callback for CNAME in answer. | |
+#define | DNS_ERR_CANCEL 69 |
The request was canceled via a call to evdns_cancel_request. | |
+#define | DNS_ERR_FORMAT 1 |
The name server was unable to interpret the query. | |
#define | DNS_ERR_NODATA 70 |
There were no answers and no error condition in the DNS packet. More... | |
+#define | DNS_ERR_NONE 0 |
Error codes 0-5 are as described in RFC 1035. | |
+#define | DNS_ERR_NOTEXIST 3 |
The domain name does not exist. | |
+#define | DNS_ERR_NOTIMPL 4 |
The name server does not support the requested kind of query. | |
+#define | DNS_ERR_REFUSED 5 |
The name server refuses to reform the specified operation for policy reasons. | |
+#define | DNS_ERR_SERVERFAILED 2 |
The name server was unable to process this query due to a problem with the name server. | |
+#define | DNS_ERR_SHUTDOWN 68 |
The request was canceled because the DNS subsystem was shut down. | |
+#define | DNS_ERR_TIMEOUT 67 |
Communication with the server timed out. | |
+#define | DNS_ERR_TRUNCATED 65 |
The reply was truncated or ill-formatted. | |
+#define | DNS_ERR_UNKNOWN 66 |
An unknown error occurred. | |
+#define | DNS_IPv4_A 1 |
+#define | DNS_IPv6_AAAA 3 |
+#define | DNS_NO_SEARCH DNS_QUERY_NO_SEARCH |
+#define | DNS_OPTION_HOSTSFILE 8 |
+#define | DNS_OPTION_MISC 4 |
+#define | DNS_OPTION_NAMESERVERS 2 |
+#define | DNS_OPTION_NAMESERVERS_NO_DEFAULT 16 |
+#define | DNS_OPTION_SEARCH 1 |
#define | DNS_OPTIONS_ALL |
All above: More... | |
+#define | DNS_PTR 2 |
+#define | DNS_QUERY_IGNTC 0x04 |
Ignore truncation flag in responses (don't fallback to TCP connections). | |
+#define | DNS_QUERY_NO_SEARCH 0x01 |
Disable searching for the query. | |
+#define | DNS_QUERY_USEVC 0x02 |
Use TCP connections ("virtual circuits") for queries rather than UDP datagrams. | |
+#define | EVDNS_ADDITIONAL_SECTION 2 |
+#define | EVDNS_ANSWER_SECTION 0 |
+#define | EVDNS_AUTHORITY_SECTION 1 |
+#define | EVDNS_BASE_CONFIG_WINDOWS_NAMESERVERS_IMPLEMENTED |
+#define | EVDNS_BASE_DISABLE_WHEN_INACTIVE 0x8000 |
Flag for evdns_base_new: Do not prevent the libevent event loop from exiting when we have no active dns requests. | |
#define | EVDNS_BASE_INITIALIZE_NAMESERVERS 1 |
Flag for evdns_base_new: process resolv.conf. More... | |
#define | EVDNS_BASE_NAMESERVERS_NO_DEFAULT 0x10000 |
Flag for evdns_base_new: If EVDNS_BASE_INITIALIZE_NAMESERVERS isset, do not add default nameserver if there are no nameservers in resolv.conf. More... | |
+#define | EVDNS_BASE_NO_CACHE 0x10 |
Flag for evdns_base_new: disable caching of DNS responses by default for async resolver. | |
+#define | EVDNS_CLASS_INET 1 |
+#define | EVDNS_ERROR_FAILED_TO_OPEN_FILE 1 |
+#define | EVDNS_ERROR_FAILED_TO_STAT_FILE 2 |
+#define | EVDNS_ERROR_FILE_TOO_LARGE 3 |
+#define | EVDNS_ERROR_NO_NAMESERVERS_CONFIGURED 6 |
+#define | EVDNS_ERROR_NONE 0 |
+#define | EVDNS_ERROR_OUT_OF_MEMORY 4 |
+#define | EVDNS_ERROR_SHORT_READ_FROM_FILE 5 |
+#define | EVDNS_FLAGS_AA 0x400 |
+#define | EVDNS_FLAGS_RD 0x080 |
+#define | EVDNS_QTYPE_ALL 255 |
+#define | EVDNS_QTYPE_AXFR 252 |
+#define | EVDNS_TYPE_A 1 |
+#define | EVDNS_TYPE_AAAA 28 |
+#define | EVDNS_TYPE_CNAME 5 |
+#define | EVDNS_TYPE_MX 15 |
+#define | EVDNS_TYPE_NS 2 |
+#define | EVDNS_TYPE_PTR 12 |
+#define | EVDNS_TYPE_SOA 6 |
+#define | EVDNS_TYPE_TXT 16 |
+Typedefs | |
typedef void(* | evdns_callback_type) (int result, char type, int count, int ttl, void *addresses, void *arg) |
The callback that contains the results from a lookup. More... | |
typedef void(* | evdns_debug_log_fn_type) (int is_warning, const char *msg) |
A callback that is invoked when a log message is generated. More... | |
+typedef void(* | evdns_getaddrinfo_cb) (int result, struct evutil_addrinfo *res, void *arg) |
Callback for evdns_getaddrinfo. | |
typedef void(* | evdns_request_callback_fn_type) (struct evdns_server_request *, void *) |
A callback to implement a DNS server. More... | |
+Enumerations | |
enum | evdns_server_option { EVDNS_SOPT_TCP_MAX_CLIENTS, +EVDNS_SOPT_TCP_IDLE_TIMEOUT + } |
List of configurable evdns_server_port options. More... | |
+Functions | |
EVENT2_EXPORT_SYMBOL struct evdns_server_port * | evdns_add_server_port_with_base (struct event_base *base, evutil_socket_t socket, int flags, evdns_request_callback_fn_type callback, void *user_data) |
Create a new UDP DNS server port. More... | |
EVENT2_EXPORT_SYMBOL struct evdns_server_port * | evdns_add_server_port_with_listener (struct event_base *base, struct evconnlistener *listener, int flags, evdns_request_callback_fn_type callback, void *user_data) |
Create a new TCP DNS server port. More... | |
EVENT2_EXPORT_SYMBOL void | evdns_base_clear_host_addresses (struct evdns_base *base) |
Remove all hosts entries that have been loaded into the event_base via evdns_base_load_hosts or via event_base_resolv_conf_parse. More... | |
EVENT2_EXPORT_SYMBOL int | evdns_base_clear_nameservers_and_suspend (struct evdns_base *base) |
Remove all configured nameservers, and suspend all pending resolves. More... | |
EVENT2_EXPORT_SYMBOL int | evdns_base_config_windows_nameservers (struct evdns_base *) |
Obtain nameserver information using the Windows API. More... | |
EVENT2_EXPORT_SYMBOL int | evdns_base_count_nameservers (struct evdns_base *base) |
Get the number of configured nameservers. More... | |
EVENT2_EXPORT_SYMBOL void | evdns_base_free (struct evdns_base *base, int fail_requests) |
Shut down the asynchronous DNS resolver and terminate all active requests. More... | |
EVENT2_EXPORT_SYMBOL int | evdns_base_get_nameserver_addr (struct evdns_base *base, int idx, struct sockaddr *sa, ev_socklen_t len) |
Retrieve the address of the 'idx'th configured nameserver. More... | |
EVENT2_EXPORT_SYMBOL int | evdns_base_get_nameserver_fd (struct evdns_base *base, int idx) |
Retrieve the fd of the 'idx'th configured nameserver. More... | |
EVENT2_EXPORT_SYMBOL int | evdns_base_load_hosts (struct evdns_base *base, const char *hosts_fname) |
Load an /etc/hosts-style file from 'hosts_fname' into 'base'. More... | |
EVENT2_EXPORT_SYMBOL int | evdns_base_nameserver_add (struct evdns_base *base, unsigned long int address) |
Add a nameserver. More... | |
EVENT2_EXPORT_SYMBOL int | evdns_base_nameserver_ip_add (struct evdns_base *base, const char *ip_as_string) |
Add a nameserver by string address. More... | |
+EVENT2_EXPORT_SYMBOL int | evdns_base_nameserver_sockaddr_add (struct evdns_base *base, const struct sockaddr *sa, ev_socklen_t len, unsigned flags) |
Add a nameserver by sockaddr. | |
EVENT2_EXPORT_SYMBOL struct evdns_base * | evdns_base_new (struct event_base *event_base, int flags) |
Initialize the asynchronous DNS library. More... | |
EVENT2_EXPORT_SYMBOL int | evdns_base_resolv_conf_parse (struct evdns_base *base, int flags, const char *const filename) |
Parse a resolv.conf file. More... | |
EVENT2_EXPORT_SYMBOL struct evdns_request * | evdns_base_resolve_ipv4 (struct evdns_base *base, const char *name, int flags, evdns_callback_type callback, void *ptr) |
Lookup an A record for a given name. More... | |
EVENT2_EXPORT_SYMBOL struct evdns_request * | evdns_base_resolve_ipv6 (struct evdns_base *base, const char *name, int flags, evdns_callback_type callback, void *ptr) |
Lookup an AAAA record for a given name. More... | |
EVENT2_EXPORT_SYMBOL struct evdns_request * | evdns_base_resolve_reverse (struct evdns_base *base, const struct in_addr *in, int flags, evdns_callback_type callback, void *ptr) |
Lookup a PTR record for a given IP address. More... | |
EVENT2_EXPORT_SYMBOL struct evdns_request * | evdns_base_resolve_reverse_ipv6 (struct evdns_base *base, const struct in6_addr *in, int flags, evdns_callback_type callback, void *ptr) |
Lookup a PTR record for a given IPv6 address. More... | |
EVENT2_EXPORT_SYMBOL int | evdns_base_resume (struct evdns_base *base) |
Resume normal operation and continue any suspended resolve requests. More... | |
EVENT2_EXPORT_SYMBOL void | evdns_base_search_add (struct evdns_base *base, const char *domain) |
Add a domain to the list of search domains. More... | |
+EVENT2_EXPORT_SYMBOL void | evdns_base_search_clear (struct evdns_base *base) |
Clear the list of search domains. | |
EVENT2_EXPORT_SYMBOL void | evdns_base_search_ndots_set (struct evdns_base *base, const int ndots) |
Set the 'ndots' parameter for searches. More... | |
EVENT2_EXPORT_SYMBOL int | evdns_base_set_option (struct evdns_base *base, const char *option, const char *val) |
Set the value of a configuration option. More... | |
EVENT2_EXPORT_SYMBOL int | evdns_cache_lookup (struct evdns_base *base, const char *nodename, struct evutil_addrinfo *hints, ev_uint16_t port, struct evutil_addrinfo **res) |
Lookup an entry from the evdns cache. More... | |
EVENT2_EXPORT_SYMBOL void | evdns_cache_write (struct evdns_base *dns_base, char *nodename, struct evutil_addrinfo *res, int ttl) |
Write an entry to the evdns cache. More... | |
EVENT2_EXPORT_SYMBOL void | evdns_cancel_request (struct evdns_base *base, struct evdns_request *req) |
Cancels a pending DNS resolution request. More... | |
+EVENT2_EXPORT_SYMBOL void | evdns_close_server_port (struct evdns_server_port *port) |
Close down a DNS server port, and free associated structures. | |
const EVENT2_EXPORT_SYMBOL char * | evdns_err_to_string (int err) |
Convert a DNS error code to a string. More... | |
EVENT2_EXPORT_SYMBOL struct evdns_getaddrinfo_request * | evdns_getaddrinfo (struct evdns_base *dns_base, const char *nodename, const char *servname, const struct evutil_addrinfo *hints_in, evdns_getaddrinfo_cb cb, void *arg) |
Make a non-blocking getaddrinfo request using the dns_base in 'dns_base'. More... | |
+EVENT2_EXPORT_SYMBOL void | evdns_getaddrinfo_cancel (struct evdns_getaddrinfo_request *req) |
EVENT2_EXPORT_SYMBOL int | evdns_server_port_set_option (struct evdns_server_port *port, enum evdns_server_option option, size_t value) |
Configure DNS server. More... | |
+EVENT2_EXPORT_SYMBOL int | evdns_server_request_add_a_reply (struct evdns_server_request *req, const char *name, int n, const void *addrs, int ttl) |
+EVENT2_EXPORT_SYMBOL int | evdns_server_request_add_aaaa_reply (struct evdns_server_request *req, const char *name, int n, const void *addrs, int ttl) |
+EVENT2_EXPORT_SYMBOL int | evdns_server_request_add_cname_reply (struct evdns_server_request *req, const char *name, const char *cname, int ttl) |
+EVENT2_EXPORT_SYMBOL int | evdns_server_request_add_ptr_reply (struct evdns_server_request *req, struct in_addr *in, const char *inaddr_name, const char *hostname, int ttl) |
+EVENT2_EXPORT_SYMBOL int | evdns_server_request_add_reply (struct evdns_server_request *req, int section, const char *name, int type, int dns_class, int ttl, int datalen, int is_name, const char *data) |
+EVENT2_EXPORT_SYMBOL int | evdns_server_request_drop (struct evdns_server_request *req) |
Free a DNS request without sending back a reply. | |
+EVENT2_EXPORT_SYMBOL int | evdns_server_request_get_requesting_addr (struct evdns_server_request *req, struct sockaddr *sa, int addr_len) |
Get the address that made a DNS request. | |
+EVENT2_EXPORT_SYMBOL int | evdns_server_request_respond (struct evdns_server_request *req, int err) |
Send back a response to a DNS request, and free the request structure. | |
EVENT2_EXPORT_SYMBOL void | evdns_server_request_set_flags (struct evdns_server_request *req, int flags) |
Sets some flags in a reply we're building. More... | |
EVENT2_EXPORT_SYMBOL void | evdns_set_log_fn (evdns_debug_log_fn_type fn) |
Set the callback function to handle DNS log messages. More... | |
Provides a few APIs to use for resolving DNS names, and a facility for implementing simple DNS servers.
+Welcome, gentle reader
+Async DNS lookups are really a whole lot harder than they should be, mostly stemming from the fact that the libc resolver has never been very good at them. Before you use this library you should see if libc can do the job for you with the modern async call getaddrinfo_a (see http://www.imperialviolet.org/page25.html#e498). Otherwise, please continue.
+The library keeps track of the state of nameservers and will avoid them when they go down. Otherwise it will round robin between them.
+Quick start guide:
When the lookup is complete the callback function is called. The first argument will be one of the DNS_ERR_* defines in evdns.h. Hopefully it will be DNS_ERR_NONE, in which case type will be DNS_IPv4_A, count will be the number of IP addresses, ttl is the time which the data can be cached for (in seconds), addresses will point to an array of uint32_t's and arg will be whatever you passed to evdns_resolve.
+Searching:
+In order for this library to be a good replacement for glibc's resolver it supports searching. This involves setting a list of default domains, in which names will be queried for. The number of dots in the query name determines the order in which this list is used.
+Searching appears to be a single lookup from the point of view of the API, although many DNS queries may be generated from a single call to evdns_resolve. Searching can also drastically slow down the resolution of names.
+To disable searching:
The order of searches depends on the number of dots in the name. If the number is greater than the ndots setting then the names is first tried globally. Otherwise each search domain is appended in turn.
+The ndots setting can either be set from a resolv.conf, or by calling evdns_search_ndots_set.
+For example, with ndots set to 1 (the default) and a search domain list of ["myhome.net"]:
++ Query: www + Order: www.myhome.net, www.
Query: www.abc + Order: www.abc., www.abc.myhome.net +
Internals:
+Requests are kept in two queues. The first is the inflight queue. In this queue requests have an allocated transaction id and nameserver. They will soon be transmitted if they haven't already been.
+The second is the waiting queue. The size of the inflight ring is limited and all other requests wait in waiting queue for space. This bounds the number of concurrent requests so that we don't flood the nameserver. Several algorithms require a full walk of the inflight queue and so bounding its size keeps thing going nicely under huge (many thousands of requests) loads.
+If a nameserver loses too many requests it is considered down and we try not to use it. After a while we send a probe to that nameserver (a lookup for google.com) and, if it replies, we consider it working again. If the nameserver fails a probe we wait longer to try again with the next probe.
+#define DNS_ERR_NODATA 70 | +
There were no answers and no error condition in the DNS packet.
+This can happen when you ask for an address that exists, but a record type that doesn't.
+ +#define DNS_OPTIONS_ALL | +
All above:
+#define EVDNS_BASE_INITIALIZE_NAMESERVERS 1 | +
Flag for evdns_base_new: process resolv.conf.
+
+
#define EVDNS_BASE_NAMESERVERS_NO_DEFAULT 0x10000 | +
Flag for evdns_base_new: If EVDNS_BASE_INITIALIZE_NAMESERVERS isset, do not add default nameserver if there are no nameservers in resolv.conf.
+typedef void(* evdns_callback_type) (int result, char type, int count, int ttl, void *addresses, void *arg) | +
The callback that contains the results from a lookup.
+typedef void(* evdns_debug_log_fn_type) (int is_warning, const char *msg) | +
A callback that is invoked when a log message is generated.
+is_warning | indicates if the log message is a 'warning' |
msg | the content of the log message |
typedef void(* evdns_request_callback_fn_type) (struct evdns_server_request *, void *) | +
A callback to implement a DNS server.
+The callback function receives a DNS request. It should then optionally add a number of answers to the reply using the evdns_server_request_add_*_reply functions, before calling either evdns_server_request_respond to send the reply back, or evdns_server_request_drop to decline to answer the request.
+req | A newly received request |
user_data | A pointer that was passed to evdns_add_server_port_with_base(). |
enum evdns_server_option | +
List of configurable evdns_server_port options.
+EVENT2_EXPORT_SYMBOL struct evdns_server_port* evdns_add_server_port_with_base | +( | +struct event_base * | +base, | +
+ | + | evutil_socket_t | +socket, | +
+ | + | int | +flags, | +
+ | + | evdns_request_callback_fn_type | +callback, | +
+ | + | void * | +user_data | +
+ | ) | ++ |
Create a new UDP DNS server port.
+base | The event base to handle events for the server port. |
socket | A UDP socket to accept DNS requests. |
flags | Always 0 for now. |
callback | A function to invoke whenever we get a DNS request on the socket. |
user_data | Data to pass to the callback. |
EVENT2_EXPORT_SYMBOL struct evdns_server_port* evdns_add_server_port_with_listener | +( | +struct event_base * | +base, | +
+ | + | struct evconnlistener * | +listener, | +
+ | + | int | +flags, | +
+ | + | evdns_request_callback_fn_type | +callback, | +
+ | + | void * | +user_data | +
+ | ) | ++ |
Create a new TCP DNS server port.
+base | The event base to handle events for the server port. |
listener | A TCP listener to accept DNS requests. |
flags | Always 0 for now. |
callback | A function to invoke whenever we get a DNS request on the socket. |
user_data | Data to pass to the callback. |
EVENT2_EXPORT_SYMBOL void evdns_base_clear_host_addresses | +( | +struct evdns_base * | +base | ) | ++ |
Remove all hosts entries that have been loaded into the event_base via evdns_base_load_hosts or via event_base_resolv_conf_parse.
+base | the evdns base to remove outdated host addresses from |
EVENT2_EXPORT_SYMBOL int evdns_base_clear_nameservers_and_suspend | +( | +struct evdns_base * | +base | ) | ++ |
Remove all configured nameservers, and suspend all pending resolves.
+Resolves will not necessarily be re-attempted until evdns_base_resume() is called.
+base | the evdns_base to which to apply this operation |
EVENT2_EXPORT_SYMBOL int evdns_base_config_windows_nameservers | +( | +struct evdns_base * | +) | ++ |
Obtain nameserver information using the Windows API.
+Attempt to configure a set of nameservers based on platform settings on a win32 host. Preferentially tries to use GetNetworkParams; if that fails, looks in the registry.
+EVENT2_EXPORT_SYMBOL int evdns_base_count_nameservers | +( | +struct evdns_base * | +base | ) | ++ |
Get the number of configured nameservers.
+This returns the number of configured nameservers (not necessarily the number of running nameservers). This is useful for double-checking whether our calls to the various nameserver configuration functions have been successful.
+base | the evdns_base to which to apply this operation |
EVENT2_EXPORT_SYMBOL void evdns_base_free | +( | +struct evdns_base * | +base, | +
+ | + | int | +fail_requests | +
+ | ) | ++ |
Shut down the asynchronous DNS resolver and terminate all active requests.
+If the 'fail_requests' option is enabled, all active requests will return an empty result with the error flag set to DNS_ERR_SHUTDOWN. Otherwise, the requests will be silently discarded.
+base | the evdns base to free |
fail_requests | if zero, active requests will be aborted; if non-zero, active requests will return DNS_ERR_SHUTDOWN. |
EVENT2_EXPORT_SYMBOL int evdns_base_get_nameserver_addr | +( | +struct evdns_base * | +base, | +
+ | + | int | +idx, | +
+ | + | struct sockaddr * | +sa, | +
+ | + | ev_socklen_t | +len | +
+ | ) | ++ |
Retrieve the address of the 'idx'th configured nameserver.
+base | The evdns_base to examine. |
idx | The index of the nameserver to get the address of. |
sa | A location to receive the server's address. |
len | The number of bytes available at sa. |
EVENT2_EXPORT_SYMBOL int evdns_base_get_nameserver_fd | +( | +struct evdns_base * | +base, | +
+ | + | int | +idx | +
+ | ) | ++ |
Retrieve the fd of the 'idx'th configured nameserver.
+base | The evdns_base to examine. |
idx | The index of the nameserver to get the address of. |
EVENT2_EXPORT_SYMBOL int evdns_base_load_hosts | +( | +struct evdns_base * | +base, | +
+ | + | const char * | +hosts_fname | +
+ | ) | ++ |
Load an /etc/hosts-style file from 'hosts_fname' into 'base'.
+If hosts_fname is NULL, add minimal entries for localhost, and nothing else.
+Note that only evdns_getaddrinfo uses the /etc/hosts entries.
+This function does not replace previously loaded hosts entries; to do that, call evdns_base_clear_host_addresses first.
+Return 0 on success, negative on failure.
+ +EVENT2_EXPORT_SYMBOL int evdns_base_nameserver_add | +( | +struct evdns_base * | +base, | +
+ | + | unsigned long int | +address | +
+ | ) | ++ |
Add a nameserver.
+The address should be an IPv4 address in network byte order. The type of address is chosen so that it matches in_addr.s_addr.
+base | the evdns_base to which to add the name server. base must not be NULL. |
address | an IP address in network byte order |
EVENT2_EXPORT_SYMBOL int evdns_base_nameserver_ip_add | +( | +struct evdns_base * | +base, | +
+ | + | const char * | +ip_as_string | +
+ | ) | ++ |
Add a nameserver by string address.
+This function parses a n IPv4 or IPv6 address from a string and adds it as a nameserver. It supports the following formats:
If no port is specified, it defaults to 53.
+base | the evdns_base to which to apply this operation. base must not be NULL |
EVENT2_EXPORT_SYMBOL struct evdns_base* evdns_base_new | +( | +struct event_base * | +event_base, | +
+ | + | int | +flags | +
+ | ) | ++ |
Initialize the asynchronous DNS library.
+This function initializes support for non-blocking name resolution by calling evdns_resolv_conf_parse() on UNIX and evdns_config_windows_nameservers() on Windows.
+event_base | the event base to associate the dns client with |
flags | any of EVDNS_BASE_INITIALIZE_NAMESERVERS| EVDNS_BASE_DISABLE_WHEN_INACTIVE|EVDNS_BASE_NAMESERVERS_NO_DEFAULT| EVDNS_BASE_NO_CACHE |
EVENT2_EXPORT_SYMBOL int evdns_base_resolv_conf_parse | +( | +struct evdns_base * | +base, | +
+ | + | int | +flags, | +
+ | + | const char *const | +filename | +
+ | ) | ++ |
Parse a resolv.conf file.
+The 'flags' parameter determines what information is parsed from the resolv.conf file. See the man page for resolv.conf for the format of this file.
+The following directives are not parsed from the file: sortlist, rotate, no-check-names, inet6, debug.
+If this function encounters an error, the possible return values are: EVDNS_ERROR_FAILED_TO_OPEN_FILE (1) - failed to open file EVDNS_ERROR_FAILED_TO_STAT_FILE (2) - failed to stat file EVDNS_ERROR_FILE_TOO_LARGE (3) - file too large EVDNS_ERROR_OUT_OF_MEMORY (4) - out of memory EVDNS_ERROR_SHORT_READ_FROM_FILE (5) - short read from file EVDNS_ERROR_NO_NAMESERVERS_CONFIGURED (6) - no nameservers configured.
+base | the evdns_base to which to apply this operation. base must not be NULL. |
flags | any of DNS_OPTION_NAMESERVERS|DNS_OPTION_SEARCH|DNS_OPTION_MISC| DNS_OPTION_HOSTSFILE|DNS_OPTIONS_ALL|DNS_OPTION_NAMESERVERS_NO_DEFAULT |
filename | the path to the resolv.conf file |
EVENT2_EXPORT_SYMBOL struct evdns_request* evdns_base_resolve_ipv4 | +( | +struct evdns_base * | +base, | +
+ | + | const char * | +name, | +
+ | + | int | +flags, | +
+ | + | evdns_callback_type | +callback, | +
+ | + | void * | +ptr | +
+ | ) | ++ |
Lookup an A record for a given name.
+base | the evdns_base to which to apply this operation |
name | a DNS hostname |
flags | either 0, or combination of DNS_QUERY_* flags. |
callback | a callback function to invoke when the request is completed |
ptr | an argument to pass to the callback function |
EVENT2_EXPORT_SYMBOL struct evdns_request* evdns_base_resolve_ipv6 | +( | +struct evdns_base * | +base, | +
+ | + | const char * | +name, | +
+ | + | int | +flags, | +
+ | + | evdns_callback_type | +callback, | +
+ | + | void * | +ptr | +
+ | ) | ++ |
Lookup an AAAA record for a given name.
+base | the evdns_base to which to apply this operation |
name | a DNS hostname |
flags | either 0, or combination of DNS_QUERY_* flags. |
callback | a callback function to invoke when the request is completed |
ptr | an argument to pass to the callback function |
EVENT2_EXPORT_SYMBOL struct evdns_request* evdns_base_resolve_reverse | +( | +struct evdns_base * | +base, | +
+ | + | const struct in_addr * | +in, | +
+ | + | int | +flags, | +
+ | + | evdns_callback_type | +callback, | +
+ | + | void * | +ptr | +
+ | ) | ++ |
Lookup a PTR record for a given IP address.
+base | the evdns_base to which to apply this operation |
in | an IPv4 address |
flags | either 0, or combination of DNS_QUERY_* flags. |
callback | a callback function to invoke when the request is completed |
ptr | an argument to pass to the callback function |
EVENT2_EXPORT_SYMBOL struct evdns_request* evdns_base_resolve_reverse_ipv6 | +( | +struct evdns_base * | +base, | +
+ | + | const struct in6_addr * | +in, | +
+ | + | int | +flags, | +
+ | + | evdns_callback_type | +callback, | +
+ | + | void * | +ptr | +
+ | ) | ++ |
Lookup a PTR record for a given IPv6 address.
+base | the evdns_base to which to apply this operation |
in | an IPv6 address |
flags | either 0, or combination of DNS_QUERY_* flags. |
callback | a callback function to invoke when the request is completed |
ptr | an argument to pass to the callback function |
EVENT2_EXPORT_SYMBOL int evdns_base_resume | +( | +struct evdns_base * | +base | ) | ++ |
Resume normal operation and continue any suspended resolve requests.
+Re-attempt resolves left in limbo after an earlier call to evdns_base_clear_nameservers_and_suspend().
+base | the evdns_base to which to apply this operation |
EVENT2_EXPORT_SYMBOL void evdns_base_search_add | +( | +struct evdns_base * | +base, | +
+ | + | const char * | +domain | +
+ | ) | ++ |
Add a domain to the list of search domains.
+domain | the domain to be added to the search list |
EVENT2_EXPORT_SYMBOL void evdns_base_search_ndots_set | +( | +struct evdns_base * | +base, | +
+ | + | const int | +ndots | +
+ | ) | ++ |
Set the 'ndots' parameter for searches.
+Sets the number of dots which, when found in a name, causes the first query to be without any search domain.
+ndots | the new ndots parameter |
EVENT2_EXPORT_SYMBOL int evdns_base_set_option | +( | +struct evdns_base * | +base, | +
+ | + | const char * | +option, | +
+ | + | const char * | +val | +
+ | ) | ++ |
Set the value of a configuration option.
+The currently available configuration options are:
+ndots, timeout, max-timeouts, max-inflight, attempts, randomize-case, bind-to, initial-probe-timeout, max-probe-timeout, probe-backoff-factor, getaddrinfo-allow-skew, so-rcvbuf, so-sndbuf, tcp-idle-timeout, use-vc, ignore-tc, edns-udp-size.
+In versions before Libevent 2.0.3-alpha, the option name needed to end with a colon.
+In case of options without values (use-vc, ingore-tc) val should be an empty string or NULL.
+base | the evdns_base to which to apply this operation. base must not be NULL. |
option | the name of the configuration option to be modified |
val | the value to be set |
EVENT2_EXPORT_SYMBOL int evdns_cache_lookup | +( | +struct evdns_base * | +base, | +
+ | + | const char * | +nodename, | +
+ | + | struct evutil_addrinfo * | +hints, | +
+ | + | ev_uint16_t | +port, | +
+ | + | struct evutil_addrinfo ** | +res | +
+ | ) | ++ |
Lookup an entry from the evdns cache.
+base | the evdns base associated with the cache |
nodename | the DNS name for which information is being sought |
hints | see man getaddrinfo() |
port | used to fill in port numbers in the resulting address list |
res | pointer to an evutil_addrinfo struct for result |
EVENT2_EXPORT_SYMBOL void evdns_cache_write | +( | +struct evdns_base * | +dns_base, | +
+ | + | char * | +nodename, | +
+ | + | struct evutil_addrinfo * | +res, | +
+ | + | int | +ttl | +
+ | ) | ++ |
Write an entry to the evdns cache.
+dns_base | the evdns base to add the entry to |
nodename | the DNS name |
res | the address information associated with the DNS name |
ttl | the time to live associated with the address information |
EVENT2_EXPORT_SYMBOL void evdns_cancel_request | +( | +struct evdns_base * | +base, | +
+ | + | struct evdns_request * | +req | +
+ | ) | ++ |
Cancels a pending DNS resolution request.
+base | the evdns_base that was used to make the request |
req | the evdns_request that was returned by calling a resolve function |
const EVENT2_EXPORT_SYMBOL char* evdns_err_to_string | +( | +int | +err | ) | ++ |
Convert a DNS error code to a string.
+err | the DNS error code |
EVENT2_EXPORT_SYMBOL struct evdns_getaddrinfo_request* evdns_getaddrinfo | +( | +struct evdns_base * | +dns_base, | +
+ | + | const char * | +nodename, | +
+ | + | const char * | +servname, | +
+ | + | const struct evutil_addrinfo * | +hints_in, | +
+ | + | evdns_getaddrinfo_cb | +cb, | +
+ | + | void * | +arg | +
+ | ) | ++ |
Make a non-blocking getaddrinfo request using the dns_base in 'dns_base'.
+If we can answer the request immediately (with an error or not!), then we invoke cb immediately and return NULL. This can happen e.g. if the requested address is in the hosts file, or cached, or invalid. Otherwise we return an evdns_getaddrinfo_request and invoke cb later.
+When the callback is invoked, we pass as its first argument the error code that getaddrinfo would return (or 0 for no error). As its second argument, we pass the evutil_addrinfo structures we found (or NULL on error). We pass 'arg' as the third argument.
+Limitations:
+EVENT2_EXPORT_SYMBOL int evdns_server_port_set_option | +( | +struct evdns_server_port * | +port, | +
+ | + | enum evdns_server_option | +option, | +
+ | + | size_t | +value | +
+ | ) | ++ |
Configure DNS server.
+port | the evdns_server_port to which to apply this operation |
option |
val | value of the option |
EVENT2_EXPORT_SYMBOL void evdns_server_request_set_flags | +( | +struct evdns_server_request * | +req, | +
+ | + | int | +flags | +
+ | ) | ++ |
Sets some flags in a reply we're building.
+Allows setting of the AA or RD flags
+ +EVENT2_EXPORT_SYMBOL void evdns_set_log_fn | +( | +evdns_debug_log_fn_type | +fn | ) | ++ |
Set the callback function to handle DNS log messages.
+If this callback is not set, evdns log messages are handled with the regular Libevent logging system.
+fn | the callback to be invoked when a log message is generated |
+ libevent
+ 2.2.1
+
+ Event notification library
+ |
+
+ libevent
+ 2.2.1
+
+ Event notification library
+ |
+
Potentially non-threadsafe versions of the functions in dns.h: provided only for backwards compatibility. +More...
+ +Go to the source code of this file.
++Functions | |
EVENT2_EXPORT_SYMBOL struct evdns_server_port * | evdns_add_server_port (evutil_socket_t socket, int flags, evdns_request_callback_fn_type callback, void *user_data) |
As evdns_server_new_with_base. More... | |
EVENT2_EXPORT_SYMBOL int | evdns_clear_nameservers_and_suspend (void) |
Remove all configured nameservers, and suspend all pending resolves. More... | |
EVENT2_EXPORT_SYMBOL int | evdns_count_nameservers (void) |
Get the number of configured nameservers. More... | |
EVENT2_EXPORT_SYMBOL struct evdns_base * | evdns_get_global_base (void) |
Return the global evdns_base created by event_init() and used by the other deprecated functions. More... | |
EVENT2_EXPORT_SYMBOL int | evdns_init (void) |
Initialize the asynchronous DNS library. More... | |
EVENT2_EXPORT_SYMBOL int | evdns_nameserver_add (unsigned long int address) |
Add a nameserver. More... | |
EVENT2_EXPORT_SYMBOL int | evdns_nameserver_ip_add (const char *ip_as_string) |
Add a nameserver. More... | |
EVENT2_EXPORT_SYMBOL int | evdns_resolv_conf_parse (int flags, const char *const filename) |
Parse a resolv.conf file. More... | |
EVENT2_EXPORT_SYMBOL int | evdns_resolve_ipv4 (const char *name, int flags, evdns_callback_type callback, void *ptr) |
Lookup an A record for a given name. More... | |
EVENT2_EXPORT_SYMBOL int | evdns_resolve_ipv6 (const char *name, int flags, evdns_callback_type callback, void *ptr) |
Lookup an AAAA record for a given name. More... | |
EVENT2_EXPORT_SYMBOL int | evdns_resolve_reverse (const struct in_addr *in, int flags, evdns_callback_type callback, void *ptr) |
Lookup a PTR record for a given IP address. More... | |
EVENT2_EXPORT_SYMBOL int | evdns_resolve_reverse_ipv6 (const struct in6_addr *in, int flags, evdns_callback_type callback, void *ptr) |
Lookup a PTR record for a given IPv6 address. More... | |
EVENT2_EXPORT_SYMBOL int | evdns_resume (void) |
Resume normal operation and continue any suspended resolve requests. More... | |
EVENT2_EXPORT_SYMBOL void | evdns_search_add (const char *domain) |
Add a domain to the list of search domains. More... | |
EVENT2_EXPORT_SYMBOL void | evdns_search_clear (void) |
Clear the list of search domains. More... | |
EVENT2_EXPORT_SYMBOL void | evdns_search_ndots_set (const int ndots) |
Set the 'ndots' parameter for searches. More... | |
EVENT2_EXPORT_SYMBOL int | evdns_set_option (const char *option, const char *val, int flags) |
Set the value of a configuration option. More... | |
EVENT2_EXPORT_SYMBOL void | evdns_shutdown (int fail_requests) |
Shut down the asynchronous DNS resolver and terminate all active requests. More... | |
Potentially non-threadsafe versions of the functions in dns.h: provided only for backwards compatibility.
+EVENT2_EXPORT_SYMBOL struct evdns_server_port* evdns_add_server_port | +( | +evutil_socket_t | +socket, | +
+ | + | int | +flags, | +
+ | + | evdns_request_callback_fn_type | +callback, | +
+ | + | void * | +user_data | +
+ | ) | ++ |
As evdns_server_new_with_base.
+EVENT2_EXPORT_SYMBOL int evdns_clear_nameservers_and_suspend | +( | +void | +) | ++ |
Remove all configured nameservers, and suspend all pending resolves.
+Resolves will not necessarily be re-attempted until evdns_resume() is called.
+EVENT2_EXPORT_SYMBOL int evdns_count_nameservers | +( | +void | +) | ++ |
Get the number of configured nameservers.
+This returns the number of configured nameservers (not necessarily the number of running nameservers). This is useful for double-checking whether our calls to the various nameserver configuration functions have been successful.
+EVENT2_EXPORT_SYMBOL struct evdns_base* evdns_get_global_base | +( | +void | +) | ++ |
Return the global evdns_base created by event_init() and used by the other deprecated functions.
+EVENT2_EXPORT_SYMBOL int evdns_init | +( | +void | +) | ++ |
Initialize the asynchronous DNS library.
+This function initializes support for non-blocking name resolution by calling evdns_resolv_conf_parse() on UNIX and evdns_config_windows_nameservers() on Windows.
+EVENT2_EXPORT_SYMBOL int evdns_nameserver_add | +( | +unsigned long int | +address | ) | ++ |
Add a nameserver.
+The address should be an IPv4 address in network byte order. The type of address is chosen so that it matches in_addr.s_addr.
+address | an IP address in network byte order |
EVENT2_EXPORT_SYMBOL int evdns_nameserver_ip_add | +( | +const char * | +ip_as_string | ) | ++ |
Add a nameserver.
+This wraps the evdns_nameserver_add() function by parsing a string as an IP address and adds it as a nameserver.
+EVENT2_EXPORT_SYMBOL int evdns_resolv_conf_parse | +( | +int | +flags, | +
+ | + | const char *const | +filename | +
+ | ) | ++ |
Parse a resolv.conf file.
+The 'flags' parameter determines what information is parsed from the resolv.conf file. See the man page for resolv.conf for the format of this file.
+The following directives are not parsed from the file: sortlist, rotate, no-check-names, inet6, debug.
+If this function encounters an error, the possible return values are: 1 = failed to open file, 2 = failed to stat file, 3 = file too large, 4 = out of memory, 5 = short read from file, 6 = no nameservers listed in the file
+flags | any of DNS_OPTION_NAMESERVERS|DNS_OPTION_SEARCH|DNS_OPTION_MISC| DNS_OPTIONS_ALL |
filename | the path to the resolv.conf file |
EVENT2_EXPORT_SYMBOL int evdns_resolve_ipv4 | +( | +const char * | +name, | +
+ | + | int | +flags, | +
+ | + | evdns_callback_type | +callback, | +
+ | + | void * | +ptr | +
+ | ) | ++ |
Lookup an A record for a given name.
+name | a DNS hostname |
flags | either 0, or DNS_QUERY_NO_SEARCH to disable searching for this query. |
callback | a callback function to invoke when the request is completed |
ptr | an argument to pass to the callback function |
EVENT2_EXPORT_SYMBOL int evdns_resolve_ipv6 | +( | +const char * | +name, | +
+ | + | int | +flags, | +
+ | + | evdns_callback_type | +callback, | +
+ | + | void * | +ptr | +
+ | ) | ++ |
Lookup an AAAA record for a given name.
+name | a DNS hostname |
flags | either 0, or DNS_QUERY_NO_SEARCH to disable searching for this query. |
callback | a callback function to invoke when the request is completed |
ptr | an argument to pass to the callback function |
EVENT2_EXPORT_SYMBOL int evdns_resolve_reverse | +( | +const struct in_addr * | +in, | +
+ | + | int | +flags, | +
+ | + | evdns_callback_type | +callback, | +
+ | + | void * | +ptr | +
+ | ) | ++ |
Lookup a PTR record for a given IP address.
+in | an IPv4 address |
flags | either 0, or DNS_QUERY_NO_SEARCH to disable searching for this query. |
callback | a callback function to invoke when the request is completed |
ptr | an argument to pass to the callback function |
EVENT2_EXPORT_SYMBOL int evdns_resolve_reverse_ipv6 | +( | +const struct in6_addr * | +in, | +
+ | + | int | +flags, | +
+ | + | evdns_callback_type | +callback, | +
+ | + | void * | +ptr | +
+ | ) | ++ |
Lookup a PTR record for a given IPv6 address.
+in | an IPv6 address |
flags | either 0, or DNS_QUERY_NO_SEARCH to disable searching for this query. |
callback | a callback function to invoke when the request is completed |
ptr | an argument to pass to the callback function |
EVENT2_EXPORT_SYMBOL int evdns_resume | +( | +void | +) | ++ |
Resume normal operation and continue any suspended resolve requests.
+Re-attempt resolves left in limbo after an earlier call to evdns_clear_nameservers_and_suspend().
+EVENT2_EXPORT_SYMBOL void evdns_search_add | +( | +const char * | +domain | ) | ++ |
Add a domain to the list of search domains.
+domain | the domain to be added to the search list |
EVENT2_EXPORT_SYMBOL void evdns_search_clear | +( | +void | +) | ++ |
Clear the list of search domains.
+EVENT2_EXPORT_SYMBOL void evdns_search_ndots_set | +( | +const int | +ndots | ) | ++ |
Set the 'ndots' parameter for searches.
+Sets the number of dots which, when found in a name, causes the first query to be without any search domain.
+ndots | the new ndots parameter |
EVENT2_EXPORT_SYMBOL int evdns_set_option | +( | +const char * | +option, | +
+ | + | const char * | +val, | +
+ | + | int | +flags | +
+ | ) | ++ |
Set the value of a configuration option.
+The currently available configuration options are:
+ndots, timeout, max-timeouts, max-inflight, and attempts
+option | the name of the configuration option to be modified |
val | the value to be set |
flags | Ignored. |
EVENT2_EXPORT_SYMBOL void evdns_shutdown | +( | +int | +fail_requests | ) | ++ |
Shut down the asynchronous DNS resolver and terminate all active requests.
+If the 'fail_requests' option is enabled, all active requests will return an empty result with the error flag set to DNS_ERR_SHUTDOWN. Otherwise, the requests will be silently discarded.
+fail_requests | if zero, active requests will be aborted; if non-zero, active requests will return DNS_ERR_SHUTDOWN. |
+ libevent
+ 2.2.1
+
+ Event notification library
+ |
+
+ libevent
+ 2.2.1
+
+ Event notification library
+ |
+
Core functions for waiting for and receiving events, and using event bases. +More...
+#include <event2/visibility.h>
#include <event2/event-config.h>
#include <stdio.h>
#include <event2/util.h>
Go to the source code of this file.
++Data Structures | |
struct | event |
Structure to represent a single event. More... | |
struct | event_base |
Structure to hold information and state for a Libevent dispatch loop. More... | |
struct | event_config |
Configuration for an event_base. More... | |
+Macros | |
+#define | _EVENT_LOG_DEBUG EVENT_LOG_DEBUG |
+#define | _EVENT_LOG_ERR EVENT_LOG_ERR |
+#define | _EVENT_LOG_MSG EVENT_LOG_MSG |
+#define | _EVENT_LOG_WARN EVENT_LOG_WARN |
+#define | EVENT_DBG_ALL 0xffffffffu |
+#define | EVENT_DBG_NONE 0 |
+#define | event_get_signal(ev) ((int)event_get_fd(ev)) |
Get the signal number assigned to a signal event. | |
+#define | EVENT_MAX_PRIORITIES 256 |
Largest number of priorities that Libevent can support. | |
+#define | EVENT_SET_MEM_FUNCTIONS_IMPLEMENTED |
This definition is present if Libevent was built with support for event_set_mem_functions() | |
+#define | LIBEVENT_VERSION EVENT__VERSION |
As event_get_version, but gives the version of Libevent's headers. | |
+#define | LIBEVENT_VERSION_NUMBER EVENT__NUMERIC_VERSION |
As event_get_version_number, but gives the version number of Libevent's headers. | |
event type flag | |
Flags to pass to event_base_get_num_events() to specify the kinds of events we want to aggregate counts for + | |
+#define | EVENT_BASE_COUNT_ACTIVE 1U |
count the number of active events, which have been triggered. | |
+#define | EVENT_BASE_COUNT_ADDED 4U |
count the number of events which have been added to event base, including internal events. | |
+#define | EVENT_BASE_COUNT_VIRTUAL 2U |
count the number of virtual events, which is used to represent an internal condition, other than a pending event, that keeps the loop from exiting. | |
Log severities | |
+#define | EVENT_LOG_DEBUG 0 |
+#define | EVENT_LOG_ERR 3 |
+#define | EVENT_LOG_MSG 1 |
+#define | EVENT_LOG_WARN 2 |
Loop flags | |
These flags control the behavior of event_base_loop(). + | |
#define | EVLOOP_NO_EXIT_ON_EMPTY 0x04 |
Do not exit the loop because we have no pending events. More... | |
+#define | EVLOOP_NONBLOCK 0x02 |
Do not block: see which events are ready now, run the callbacks of the highest-priority ones, then exit. | |
+#define | EVLOOP_ONCE 0x01 |
Block until we have an active event, then exit once all active events have had their callbacks run. | |
event flags | |
Flags to pass to event_new(), event_assign(), event_pending(), and anything else with an argument of the form "short events" + | |
#define | EV_CLOSED 0x80 |
Detects connection close events. More... | |
+#define | EV_ET 0x20 |
Select edge-triggered behavior, if supported by the backend. | |
#define | EV_FINALIZE 0x40 |
If this option is provided, then event_del() will not block in one thread while waiting for the event callback to complete in another thread. More... | |
#define | EV_PERSIST 0x10 |
Persistent event: won't get removed automatically when activated. More... | |
+#define | EV_READ 0x02 |
Wait for a socket or FD to become readable. | |
+#define | EV_SIGNAL 0x08 |
Wait for a POSIX signal to be raised. | |
#define | EV_TIMEOUT 0x01 |
Indicates that a timeout has occurred. More... | |
+#define | EV_WRITE 0x04 |
Wait for a socket or FD to become writeable. | |
evtimer_* macros | |
Aliases for working with one-shot timer events If you need EV_PERSIST timer use event_*() functions. + | |
+#define | evtimer_add(ev, tv) event_add((ev), (tv)) |
+#define | evtimer_assign(ev, b, cb, arg) event_assign((ev), (b), -1, 0, (cb), (arg)) |
+#define | evtimer_del(ev) event_del(ev) |
+#define | evtimer_initialized(ev) event_initialized(ev) |
+#define | evtimer_new(b, cb, arg) event_new((b), -1, 0, (cb), (arg)) |
+#define | evtimer_pending(ev, tv) event_pending((ev), EV_TIMEOUT, (tv)) |
evsignal_* macros | |
Aliases for working with signal events + | |
+#define | evsignal_add(ev, tv) event_add((ev), (tv)) |
+#define | evsignal_assign(ev, b, x, cb, arg) event_assign((ev), (b), (x), EV_SIGNAL|EV_PERSIST, cb, (arg)) |
+#define | evsignal_del(ev) event_del(ev) |
+#define | evsignal_initialized(ev) event_initialized(ev) |
+#define | evsignal_new(b, x, cb, arg) event_new((b), (x), EV_SIGNAL|EV_PERSIST, (cb), (arg)) |
+#define | evsignal_pending(ev, tv) event_pending((ev), EV_SIGNAL, (tv)) |
evuser_* macros | |
Aliases for working with user-triggered events If you need EV_PERSIST event use event_*() functions. + | |
+#define | evuser_del(ev) event_del(ev) |
+#define | evuser_initialized(ev) event_initialized(ev) |
+#define | evuser_new(b, cb, arg) event_new((b), -1, 0, (cb), (arg)) |
+#define | evuser_pending(ev, tv) event_pending((ev), 0, (tv)) |
+#define | evuser_trigger(ev) event_active((ev), 0, 0) |
+Typedefs | |
+typedef int(* | event_base_foreach_event_cb) (const struct event_base *, const struct event *, void *) |
Callback for iterating events in an event base via event_base_foreach_event. | |
typedef void(* | event_callback_fn) (evutil_socket_t, short, void *) |
A callback function for an event. More... | |
typedef void(* | event_fatal_cb) (int err) |
A function to be called if Libevent encounters a fatal internal error. More... | |
+typedef void(* | event_finalize_callback_fn) (struct event *, void *) |
Callback type for event_finalize and event_free_finalize(). | |
typedef void(* | event_log_cb) (int severity, const char *msg) |
A callback function used to intercept Libevent's log messages. More... | |
+Enumerations | |
enum | event_base_config_flag { + EVENT_BASE_FLAG_NOLOCK = 0x01, +EVENT_BASE_FLAG_IGNORE_ENV = 0x02, +EVENT_BASE_FLAG_STARTUP_IOCP = 0x04, +EVENT_BASE_FLAG_NO_CACHE_TIME = 0x08, + + EVENT_BASE_FLAG_EPOLL_USE_CHANGELIST = 0x10, +EVENT_BASE_FLAG_PRECISE_TIMER = 0x20, +EVENT_BASE_FLAG_EPOLL_DISALLOW_TIMERFD = 0x40, +EVENT_BASE_FLAG_USE_SIGNALFD = 0x80 + + } |
A flag passed to event_config_set_flag(). More... | |
enum | event_method_feature { EV_FEATURE_ET = 0x01, +EV_FEATURE_O1 = 0x02, +EV_FEATURE_FDS = 0x04, +EV_FEATURE_EARLY_CLOSE = 0x08 + } |
A flag used to describe which features an event_base (must) provide. More... | |
+Functions | |
EVENT2_EXPORT_SYMBOL void | event_active (struct event *ev, int res, short ncalls) |
Make an event active. More... | |
EVENT2_EXPORT_SYMBOL int | event_add (struct event *ev, const struct timeval *timeout) |
Add an event to the set of pending events. More... | |
EVENT2_EXPORT_SYMBOL int | event_assign (struct event *ev, struct event_base *base, evutil_socket_t fd, short events, event_callback_fn callback, void *callback_arg) |
Prepare a new, already-allocated event structure to be added. More... | |
EVENT2_EXPORT_SYMBOL void | event_base_active_by_fd (struct event_base *base, evutil_socket_t fd, short events) |
Activates all pending events for the given fd and event mask. More... | |
EVENT2_EXPORT_SYMBOL void | event_base_active_by_signal (struct event_base *base, int sig) |
Activates all pending signals with a given signal number. More... | |
EVENT2_EXPORT_SYMBOL int | event_base_dispatch (struct event_base *base) |
Event dispatching loop. More... | |
EVENT2_EXPORT_SYMBOL void | event_base_dump_events (struct event_base *base, FILE *output) |
Writes a human-readable description of all inserted and/or active events to a provided stdio stream. More... | |
EVENT2_EXPORT_SYMBOL int | event_base_foreach_event (struct event_base *base, event_base_foreach_event_cb fn, void *arg) |
Iterate over all added or active events events in an event loop, and invoke a given callback on each one. More... | |
EVENT2_EXPORT_SYMBOL void | event_base_free (struct event_base *eb) |
Deallocate all memory associated with an event_base, and free the base. More... | |
+EVENT2_EXPORT_SYMBOL void | event_base_free_nofinalize (struct event_base *) |
As event_base_free, but do not run finalizers. | |
EVENT2_EXPORT_SYMBOL int | event_base_get_features (const struct event_base *base) |
Return a bitmask of the features implemented by an event base. More... | |
EVENT2_EXPORT_SYMBOL int | event_base_get_max_events (struct event_base *eb, unsigned int flags, int clear) |
Get the maximum number of events in a given event_base as specified in the flags. More... | |
const EVENT2_EXPORT_SYMBOL char * | event_base_get_method (const struct event_base *eb) |
Get the kernel event notification mechanism used by Libevent. More... | |
EVENT2_EXPORT_SYMBOL int | event_base_get_npriorities (struct event_base *eb) |
Get the number of different event priorities. More... | |
EVENT2_EXPORT_SYMBOL int | event_base_get_num_events (struct event_base *eb, unsigned int flags) |
Gets the number of events in event_base, as specified in the flags. More... | |
EVENT2_EXPORT_SYMBOL struct event * | event_base_get_running_event (struct event_base *base) |
If called from within the callback for an event, returns that event. More... | |
const EVENT2_EXPORT_SYMBOL char * | event_base_get_signal_method (const struct event_base *eb) |
Get the kernel signal handling mechanism used by Libevent. More... | |
EVENT2_EXPORT_SYMBOL int | event_base_gettimeofday_cached (struct event_base *base, struct timeval *tv) |
Sets 'tv' to the current time (as returned by gettimeofday()), looking at the cached value in 'base' if possible, and calling gettimeofday() or clock_gettime() as appropriate if there is no cached time. More... | |
EVENT2_EXPORT_SYMBOL int | event_base_got_break (struct event_base *eb) |
Checks if the event loop was told to abort immediately by event_base_loopbreak(). More... | |
EVENT2_EXPORT_SYMBOL int | event_base_got_exit (struct event_base *eb) |
Checks if the event loop was told to exit by event_base_loopexit(). More... | |
EVENT2_EXPORT_SYMBOL const struct timeval * | event_base_init_common_timeout (struct event_base *base, const struct timeval *duration) |
Prepare an event_base to use a large number of timeouts with the same duration. More... | |
EVENT2_EXPORT_SYMBOL int | event_base_loop (struct event_base *eb, int flags) |
Wait for events to become active, and run their callbacks. More... | |
EVENT2_EXPORT_SYMBOL int | event_base_loopbreak (struct event_base *eb) |
Abort the active event_base_loop() immediately. More... | |
EVENT2_EXPORT_SYMBOL int | event_base_loopcontinue (struct event_base *eb) |
Tell the active event_base_loop() to scan for new events immediately. More... | |
EVENT2_EXPORT_SYMBOL int | event_base_loopexit (struct event_base *eb, const struct timeval *tv) |
Exit the event loop after the specified time. More... | |
EVENT2_EXPORT_SYMBOL struct event_base * | event_base_new (void) |
Create and return a new event_base to use with the rest of Libevent. More... | |
EVENT2_EXPORT_SYMBOL struct event_base * | event_base_new_with_config (const struct event_config *cfg) |
Initialize the event API. More... | |
EVENT2_EXPORT_SYMBOL int | event_base_once (struct event_base *base, evutil_socket_t fd, short events, event_callback_fn callback, void *arg, const struct timeval *timeout) |
Schedule a one-time event. More... | |
EVENT2_EXPORT_SYMBOL int | event_base_priority_init (struct event_base *eb, int npriorities) |
Set the number of different event priorities. More... | |
EVENT2_EXPORT_SYMBOL int | event_base_set (struct event_base *eb, struct event *ev) |
Associate a different event base with an event. More... | |
EVENT2_EXPORT_SYMBOL int | event_base_update_cache_time (struct event_base *base) |
Update cached_tv in the 'base' to the current time. More... | |
EVENT2_EXPORT_SYMBOL int | event_config_avoid_method (struct event_config *cfg, const char *method) |
Enters an event method that should be avoided into the configuration. More... | |
EVENT2_EXPORT_SYMBOL void | event_config_free (struct event_config *cfg) |
Deallocates all memory associated with an event configuration object. More... | |
EVENT2_EXPORT_SYMBOL struct event_config * | event_config_new (void) |
Allocates a new event configuration object. More... | |
EVENT2_EXPORT_SYMBOL int | event_config_require_features (struct event_config *cfg, int feature) |
Enters a required event method feature that the application demands. More... | |
EVENT2_EXPORT_SYMBOL int | event_config_set_flag (struct event_config *cfg, int flag) |
Sets one or more flags to configure what parts of the eventual event_base will be initialized, and how they'll work. More... | |
EVENT2_EXPORT_SYMBOL int | event_config_set_max_dispatch_interval (struct event_config *cfg, const struct timeval *max_interval, int max_callbacks, int min_priority) |
Record an interval and/or a number of callbacks after which the event base should check for new events. More... | |
EVENT2_EXPORT_SYMBOL int | event_config_set_num_cpus_hint (struct event_config *cfg, int cpus) |
Records a hint for the number of CPUs in the system. More... | |
EVENT2_EXPORT_SYMBOL void | event_debug_unassign (struct event *) |
When debugging mode is enabled, informs Libevent that an event should no longer be considered as assigned. More... | |
EVENT2_EXPORT_SYMBOL int | event_del (struct event *ev) |
Remove an event from the set of monitored events. More... | |
+EVENT2_EXPORT_SYMBOL int | event_del_block (struct event *ev) |
As event_del(), but always blocks while the event's callback is running in another thread, even if the event was constructed with the EV_FINALIZE flag. | |
+EVENT2_EXPORT_SYMBOL int | event_del_noblock (struct event *ev) |
As event_del(), but never blocks while the event's callback is running in another thread, even if the event was constructed without the EV_FINALIZE flag. | |
EVENT2_EXPORT_SYMBOL void | event_enable_debug_logging (ev_uint32_t which) |
Turn on debugging logs and have them sent to the default log handler. More... | |
EVENT2_EXPORT_SYMBOL void | event_enable_debug_mode (void) |
Enable some relatively expensive debugging checks in Libevent that would normally be turned off. More... | |
EVENT2_EXPORT_SYMBOL void | event_free (struct event *) |
Deallocate a struct event * returned by event_new(). More... | |
EVENT2_EXPORT_SYMBOL void | event_get_assignment (const struct event *event, struct event_base **base_out, evutil_socket_t *fd_out, short *events_out, event_callback_fn *callback_out, void **arg_out) |
Extract all of arguments given to construct a given event. More... | |
+EVENT2_EXPORT_SYMBOL struct event_base * | event_get_base (const struct event *ev) |
Get the event_base associated with an event. | |
+EVENT2_EXPORT_SYMBOL event_callback_fn | event_get_callback (const struct event *ev) |
Return the callback assigned to an event. | |
+EVENT2_EXPORT_SYMBOL void * | event_get_callback_arg (const struct event *ev) |
Return the callback argument assigned to an event. | |
+EVENT2_EXPORT_SYMBOL short | event_get_events (const struct event *ev) |
Return the events (EV_READ, EV_WRITE, etc) assigned to an event. | |
+EVENT2_EXPORT_SYMBOL evutil_socket_t | event_get_fd (const struct event *ev) |
Get the socket or signal assigned to an event, or -1 if the event has no socket. | |
EVENT2_EXPORT_SYMBOL int | event_get_priority (const struct event *ev) |
Return the priority of an event. More... | |
EVENT2_EXPORT_SYMBOL size_t | event_get_struct_event_size (void) |
Return the size of struct event that the Libevent library was compiled with. More... | |
const EVENT2_EXPORT_SYMBOL char ** | event_get_supported_methods (void) |
Gets all event notification mechanisms supported by Libevent. More... | |
const EVENT2_EXPORT_SYMBOL char * | event_get_version (void) |
Get the Libevent version. More... | |
EVENT2_EXPORT_SYMBOL ev_uint32_t | event_get_version_number (void) |
Return a numeric representation of Libevent's version. More... | |
+EVENT2_EXPORT_SYMBOL int | event_gettime_monotonic (struct event_base *base, struct timeval *tp) |
Query the current monotonic time from the timer for a struct event_base. | |
EVENT2_EXPORT_SYMBOL int | event_initialized (const struct event *ev) |
Test if an event structure might be initialized. More... | |
EVENT2_EXPORT_SYMBOL struct event * | event_new (struct event_base *base, evutil_socket_t fd, short events, event_callback_fn callback, void *callback_arg) |
Allocate and assign a new event structure, ready to be added. More... | |
EVENT2_EXPORT_SYMBOL int | event_pending (const struct event *ev, short events, struct timeval *tv) |
Checks if a specific event is pending or scheduled. More... | |
EVENT2_EXPORT_SYMBOL int | event_priority_set (struct event *ev, int priority) |
Assign a priority to an event. More... | |
EVENT2_EXPORT_SYMBOL int | event_reinit (struct event_base *base) |
Reinitialize the event base after a fork. More... | |
EVENT2_EXPORT_SYMBOL int | event_remove_timer (struct event *ev) |
Remove a timer from a pending event without removing the event itself. More... | |
EVENT2_EXPORT_SYMBOL void * | event_self_cbarg (void) |
Return a value used to specify that the event itself must be used as the callback argument. More... | |
EVENT2_EXPORT_SYMBOL void | event_set_fatal_callback (event_fatal_cb cb) |
Override Libevent's behavior in the event of a fatal internal error. More... | |
EVENT2_EXPORT_SYMBOL void | event_set_log_callback (event_log_cb cb) |
Redirect Libevent's log messages. More... | |
EVENT2_EXPORT_SYMBOL void | event_set_mem_functions (void *(*malloc_fn)(size_t sz), void *(*realloc_fn)(void *ptr, size_t sz), void(*free_fn)(void *ptr)) |
Override the functions that Libevent uses for memory management. More... | |
EVENT2_EXPORT_SYMBOL void | libevent_global_shutdown (void) |
Release up all globally-allocated resources allocated by Libevent. More... | |
Finalization functions | |
These functions are used to safely tear down an event in a multithreaded application. +If you construct your events with EV_FINALIZE to avoid deadlocks, you will need a way to remove an event in the certainty that it will definitely not be running its callback when you deallocate it and its callback argument. +To do this, call one of event_finalize() or event_free_finalize with 0 for its first argument, the event to tear down as its second argument, and a callback function as its third argument. The callback will be invoked as part of the event loop, with the event's priority. +After you call a finalizer function, event_add() and event_active() will no longer work on the event, and event_del() will produce a no-op. You must not try to change the event's fields with event_assign() or event_set() while the finalize callback is in progress. Once the callback has been invoked, you should treat the event structure as containing uninitialized memory. +The event_free_finalize() function frees the event after it's finalized; event_finalize() does not. +A finalizer callback must not make events pending or active. It must not add events, activate events, or attempt to "resuscitate" the event being finalized in any way. +
| |
+EVENT2_EXPORT_SYMBOL int | event_finalize (unsigned, struct event *, event_finalize_callback_fn) |
+EVENT2_EXPORT_SYMBOL int | event_free_finalize (unsigned, struct event *, event_finalize_callback_fn) |
Core functions for waiting for and receiving events, and using event bases.
+#define EV_CLOSED 0x80 | +
Detects connection close events.
+You can use this to detect when a connection has been closed, without having to read all the pending data from a connection.
+Not all backends support EV_CLOSED. To detect or require it, use the feature flag EV_FEATURE_EARLY_CLOSE.
+ +#define EV_FINALIZE 0x40 | +
If this option is provided, then event_del() will not block in one thread while waiting for the event callback to complete in another thread.
+To use this option safely, you may need to use event_finalize() or event_free_finalize() in order to safely tear down an event in a multithreaded application. See those functions for more information.
+ +#define EV_PERSIST 0x10 | +
Persistent event: won't get removed automatically when activated.
+When a persistent event with a timeout becomes activated, its timeout is reset to 0.
+ +#define EV_TIMEOUT 0x01 | +
Indicates that a timeout has occurred.
+It's not necessary to pass this flag to event_for new()/event_assign() to get a timeout.
+ +#define EVLOOP_NO_EXIT_ON_EMPTY 0x04 | +
Do not exit the loop because we have no pending events.
+Instead, keep running until event_base_loopexit() or event_base_loopbreak() makes us stop.
+ +typedef void(* event_callback_fn) (evutil_socket_t, short, void *) | +
A callback function for an event.
+It receives three arguments:
+fd | An fd or signal |
events | One or more EV_* flags |
arg | A user-supplied argument. |
typedef void(* event_fatal_cb) (int err) | +
A function to be called if Libevent encounters a fatal internal error.
+typedef void(* event_log_cb) (int severity, const char *msg) | +
A callback function used to intercept Libevent's log messages.
+enum event_base_config_flag | +
A flag passed to event_config_set_flag().
+These flags change the behavior of an allocated event_base.
+ +Enumerator | |
---|---|
EVENT_BASE_FLAG_NOLOCK | Do not allocate a lock for the event base, even if we have locking set up. +Setting this option will make it unsafe and nonfunctional to call functions on the base concurrently from multiple threads. + |
EVENT_BASE_FLAG_IGNORE_ENV | Do not check the EVENT_* environment variables when configuring an event_base |
EVENT_BASE_FLAG_STARTUP_IOCP | Windows only: enable the IOCP dispatcher at startup. +If this flag is set then bufferevent_socket_new() and +evconn_listener_new() will use IOCP-backed implementations +instead of the usual select-based one on Windows. + +Note: it is experimental feature, and has some bugs. + |
EVENT_BASE_FLAG_NO_CACHE_TIME | Instead of checking the current time every time the event loop is ready to run timeout callbacks, check after each timeout callback. + |
EVENT_BASE_FLAG_EPOLL_USE_CHANGELIST | If we are using the epoll backend, this flag says that it is safe to use Libevent's internal change-list code to batch up adds and deletes in order to try to do as few syscalls as possible. +Setting this flag can make your code run faster, but it may trigger a Linux bug: it is not safe to use this flag if you have any fds cloned by dup() or its variants. Doing so will produce strange and hard-to-diagnose bugs. +This flag can also be activated by setting the EVENT_EPOLL_USE_CHANGELIST environment variable. +This flag has no effect if you wind up using a backend other than epoll. + |
EVENT_BASE_FLAG_PRECISE_TIMER | Ordinarily, Libevent implements its time and timeout code using the fastest monotonic timer that we have. +If this flag is set, however, we use less efficient more precise timer, assuming one is present. + |
EVENT_BASE_FLAG_EPOLL_DISALLOW_TIMERFD | With EVENT_BASE_FLAG_PRECISE_TIMER, epoll backend will use timerfd for more accurate timers, this will allows to disable this. +That said that this is something in between lack of (CLOCK_MONOTONIC_COARSE) and enabled EVENT_BASE_FLAG_PRECISE_TIMER (CLOCK_MONOTONIC + timerfd). +This flag has no effect if you wind up using a backend other than epoll and if you do not have EVENT_BASE_FLAG_PRECISE_TIMER enabled. + |
EVENT_BASE_FLAG_USE_SIGNALFD | Use signalfd(2) to handle signals over sigaction/signal. +But note, that in some edge cases signalfd() may works differently. + |
enum event_method_feature | +
A flag used to describe which features an event_base (must) provide.
+Because of OS limitations, not every Libevent backend supports every possible feature. You can use this type with event_config_require_features() to tell Libevent to only proceed if your event_base implements a given feature, and you can receive this type from event_base_get_features() to see which features are available.
+EVENT2_EXPORT_SYMBOL void event_active | +( | +struct event * | +ev, | +
+ | + | int | +res, | +
+ | + | short | +ncalls | +
+ | ) | ++ |
Make an event active.
+You can use this function on a pending or a non-pending event to make it active, so that its callback will be run by event_base_dispatch() or event_base_loop().
+One common use in multithreaded programs is to wake the thread running event_base_loop() from another thread.
+If event_active() is called on the same event more than once before the event is run, the flags are OR'd with the flags passed in previous calls.
+ev | an event to make active. |
res | a set of flags to pass to the event's callback. |
ncalls | an obsolete argument: this is ignored. |
EVENT2_EXPORT_SYMBOL int event_add | +( | +struct event * | +ev, | +
+ | + | const struct timeval * | +timeout | +
+ | ) | ++ |
Add an event to the set of pending events.
+The function event_add() schedules the execution of the event 'ev' when the condition specified by event_assign() or event_new() occurs, or when the time specified in timeout has elapsed. If a timeout is NULL, no timeout occurs and the function will only be called if a matching event occurs. The event in the ev argument must be already initialized by event_assign() or event_new() and may not be used in calls to event_assign() until it is no longer pending.
+If the event in the ev argument already has a scheduled timeout, calling event_add() replaces the old timeout with the new one if tv is non-NULL.
+ev | an event struct initialized via event_assign() or event_new() |
timeout | the maximum amount of time to wait for the event, or NULL to wait forever |
EVENT2_EXPORT_SYMBOL int event_assign | +( | +struct event * | +ev, | +
+ | + | struct event_base * | +base, | +
+ | + | evutil_socket_t | +fd, | +
+ | + | short | +events, | +
+ | + | event_callback_fn | +callback, | +
+ | + | void * | +callback_arg | +
+ | ) | ++ |
Prepare a new, already-allocated event structure to be added.
+The function event_assign() prepares the event structure ev to be used in future calls to event_add() and event_del(). Unlike event_new(), it doesn't allocate memory itself: it requires that you have already allocated a struct event, probably on the heap. Doing this will typically make your code depend on the size of the event structure, and thereby create incompatibility with future versions of Libevent.
+The easiest way to avoid this problem is just to use event_new() and event_free() instead.
+A slightly harder way to future-proof your code is to use event_get_struct_event_size() to determine the required size of an event at runtime.
+Note that it is NOT safe to call this function on an event that is active or pending. Doing so WILL corrupt internal data structures in Libevent, and lead to strange, hard-to-diagnose bugs. You can use event_assign to change an existing event, but only if it is not active or pending!
+The arguments for this function, and the behavior of the events that it makes, are as for event_new().
+ev | an event struct to be modified |
base | the event base to which ev should be attached. |
fd | the file descriptor to be monitored |
events | desired events to monitor; can be EV_READ and/or EV_WRITE |
callback | callback function to be invoked when the event occurs |
callback_arg | an argument to be passed to the callback function |
EVENT2_EXPORT_SYMBOL void event_base_active_by_fd | +( | +struct event_base * | +base, | +
+ | + | evutil_socket_t | +fd, | +
+ | + | short | +events | +
+ | ) | ++ |
Activates all pending events for the given fd and event mask.
+This function activates pending events only. Events which have not been added will not become active.
+base | the event_base on which to activate the events. |
fd | An fd to active events on. |
events | One or more of EV_{READ,WRITE,TIMEOUT}. |
EVENT2_EXPORT_SYMBOL void event_base_active_by_signal | +( | +struct event_base * | +base, | +
+ | + | int | +sig | +
+ | ) | ++ |
Activates all pending signals with a given signal number.
+This function activates pending events only. Events which have not been added will not become active.
+base | the event_base on which to activate the events. |
sig | The signal to active events on. |
EVENT2_EXPORT_SYMBOL int event_base_dispatch | +( | +struct event_base * | +base | ) | ++ |
Event dispatching loop.
+This loop will run the event base until either there are no more pending or active, or until something calls event_base_loopbreak() or event_base_loopexit().
+base | the event_base structure returned by event_base_new() or event_base_new_with_config(). base must not be NULL. |
EVENT2_EXPORT_SYMBOL void event_base_dump_events | +( | +struct event_base * | +base, | +
+ | + | FILE * | +output | +
+ | ) | ++ |
Writes a human-readable description of all inserted and/or active events to a provided stdio stream.
+This is intended for debugging; its format is not guaranteed to be the same between libevent versions.
+base | An event_base on which to scan the events. |
output | A stdio file to write on. |
EVENT2_EXPORT_SYMBOL int event_base_foreach_event | +( | +struct event_base * | +base, | +
+ | + | event_base_foreach_event_cb | +fn, | +
+ | + | void * | +arg | +
+ | ) | ++ |
Iterate over all added or active events events in an event loop, and invoke a given callback on each one.
+The callback must not call any function that modifies the event base, that modifies any event in the event base, or that adds or removes any event to the event base. Doing so is unsupported and will lead to undefined behavior – likely, to crashes.
+event_base_foreach_event() holds a lock on the event_base() for the whole time it's running: slow callbacks are not advisable.
+Note that Libevent adds some events of its own to make pieces of its functionality work. You must not assume that the only events you'll encounter will be the ones you added yourself.
+The callback function must return 0 to continue iteration, or some other integer to stop iterating.
+base | An event_base on which to scan the events. |
fn | A callback function to receive the events. |
arg | An argument passed to the callback function. |
EVENT2_EXPORT_SYMBOL void event_base_free | +( | +struct event_base * | +eb | ) | ++ |
Deallocate all memory associated with an event_base, and free the base.
+Note that this function will not close any fds or free any memory passed to event_new as the argument to callback.
+If there are any pending finalizer callbacks, this function will invoke them.
+eb | an event_base to be freed |
EVENT2_EXPORT_SYMBOL int event_base_get_features | +( | +const struct event_base * | +base | ) | ++ |
Return a bitmask of the features implemented by an event base.
+This will be a bitwise OR of one or more of the values of event_method_feature
+EVENT2_EXPORT_SYMBOL int event_base_get_max_events | +( | +struct event_base * | +eb, | +
+ | + | unsigned int | +flags, | +
+ | + | int | +clear | +
+ | ) | ++ |
Get the maximum number of events in a given event_base as specified in the flags.
+eb | the event_base structure returned by event_base_new() |
flags | a bitwise combination of the kinds of events to aggregate counts for |
clear | option used to reset the maximum count. |
const EVENT2_EXPORT_SYMBOL char* event_base_get_method | +( | +const struct event_base * | +eb | ) | ++ |
Get the kernel event notification mechanism used by Libevent.
+eb | the event_base structure returned by event_base_new() |
EVENT2_EXPORT_SYMBOL int event_base_get_npriorities | +( | +struct event_base * | +eb | ) | ++ |
Get the number of different event priorities.
+eb | the event_base structure returned by event_base_new() |
EVENT2_EXPORT_SYMBOL int event_base_get_num_events | +( | +struct event_base * | +eb, | +
+ | + | unsigned int | +flags | +
+ | ) | ++ |
Gets the number of events in event_base, as specified in the flags.
+Since event base has some internal events added to make some of its functionalities work, EVENT_BASE_COUNT_ADDED may return more than the number of events you added using event_add().
+If you pass EVENT_BASE_COUNT_ACTIVE and EVENT_BASE_COUNT_ADDED together, an active event will be counted twice. However, this might not be the case in future libevent versions. The return value is an indication of the work load, but the user shouldn't rely on the exact value as this may change in the future.
+eb | the event_base structure returned by event_base_new() |
flags | a bitwise combination of the kinds of events to aggregate counts for |
EVENT2_EXPORT_SYMBOL struct event* event_base_get_running_event | +( | +struct event_base * | +base | ) | ++ |
If called from within the callback for an event, returns that event.
+The behavior of this function is not defined when called from outside the callback function for an event.
+ +const EVENT2_EXPORT_SYMBOL char* event_base_get_signal_method | +( | +const struct event_base * | +eb | ) | ++ |
Get the kernel signal handling mechanism used by Libevent.
+eb | the event_base structure returned by event_base_new() |
EVENT2_EXPORT_SYMBOL int event_base_gettimeofday_cached | +( | +struct event_base * | +base, | +
+ | + | struct timeval * | +tv | +
+ | ) | ++ |
Sets 'tv' to the current time (as returned by gettimeofday()), looking at the cached value in 'base' if possible, and calling gettimeofday() or clock_gettime() as appropriate if there is no cached time.
+Generally, this value will only be cached while actually processing event callbacks, and may be very inaccurate if your callbacks take a long time to execute.
+Returns 0 on success, negative on failure.
+ +EVENT2_EXPORT_SYMBOL int event_base_got_break | +( | +struct event_base * | +eb | ) | ++ |
Checks if the event loop was told to abort immediately by event_base_loopbreak().
+This function will return true for an event_base at every point after event_base_loopbreak() is called, until the event loop is next entered.
+eb | the event_base structure returned by event_init() |
EVENT2_EXPORT_SYMBOL int event_base_got_exit | +( | +struct event_base * | +eb | ) | ++ |
Checks if the event loop was told to exit by event_base_loopexit().
+This function will return true for an event_base at every point after event_loopexit() is called, until the event loop is next entered.
+eb | the event_base structure returned by event_init() |
EVENT2_EXPORT_SYMBOL const struct timeval* event_base_init_common_timeout | +( | +struct event_base * | +base, | +
+ | + | const struct timeval * | +duration | +
+ | ) | ++ |
Prepare an event_base to use a large number of timeouts with the same duration.
+Libevent's default scheduling algorithm is optimized for having a large number of timeouts with their durations more or less randomly distributed. But if you have a large number of timeouts that all have the same duration (for example, if you have a large number of connections that all have a 10-second timeout), then you can improve Libevent's performance by telling Libevent about it.
+To do this, call this function with the common duration. It will return a pointer to a different, opaque timeout value. (Don't depend on its actual contents!) When you use this timeout value in event_add(), Libevent will schedule the event more efficiently.
+(This optimization probably will not be worthwhile until you have thousands or tens of thousands of events with the same timeout.)
+ +EVENT2_EXPORT_SYMBOL int event_base_loop | +( | +struct event_base * | +eb, | +
+ | + | int | +flags | +
+ | ) | ++ |
Wait for events to become active, and run their callbacks.
+This is a more flexible version of event_base_dispatch().
+By default, this loop will run the event base until either there are no more pending or active events, or until something calls event_base_loopbreak() or event_base_loopexit(). You can override this behavior with the 'flags' argument.
+eb | the event_base structure returned by event_base_new() or event_base_new_with_config() |
flags | any combination of EVLOOP_ONCE | EVLOOP_NONBLOCK | EVLOOP_NO_EXIT_ON_EMPTY |
EVENT2_EXPORT_SYMBOL int event_base_loopbreak | +( | +struct event_base * | +eb | ) | ++ |
Abort the active event_base_loop() immediately.
+event_base_loop() will abort the loop after the next event is completed; event_base_loopbreak() is typically invoked from this event's callback. This behavior is analogous to the "break;" statement.
+Subsequent invocations of event_base_loop() will proceed normally.
+eb | the event_base structure returned by event_init() |
EVENT2_EXPORT_SYMBOL int event_base_loopcontinue | +( | +struct event_base * | +eb | ) | ++ |
Tell the active event_base_loop() to scan for new events immediately.
+Calling this function makes the currently active event_base_loop() start the loop over again (scanning for new events) after the current event callback finishes. If the event loop is not running, this function has no effect.
+event_base_loopbreak() is typically invoked from this event's callback. This behavior is analogous to the "continue;" statement.
+Subsequent invocations of event loop will proceed normally.
+eb | the event_base structure returned by event_init() |
EVENT2_EXPORT_SYMBOL int event_base_loopexit | +( | +struct event_base * | +eb, | +
+ | + | const struct timeval * | +tv | +
+ | ) | ++ |
Exit the event loop after the specified time.
+The next event_base_loop() iteration after the given timer expires will complete normally (handling all queued events) then exit without blocking for events again.
+Subsequent invocations of event_base_loop() will proceed normally.
+eb | the event_base structure returned by event_init() |
tv | the amount of time after which the loop should terminate, or NULL to exit after running all currently active events. |
EVENT2_EXPORT_SYMBOL struct event_base* event_base_new | +( | +void | +) | ++ |
Create and return a new event_base to use with the rest of Libevent.
+EVENT2_EXPORT_SYMBOL struct event_base* event_base_new_with_config | +( | +const struct event_config * | +cfg | ) | ++ |
Initialize the event API.
+Use event_base_new_with_config() to initialize a new event base, taking the specified configuration under consideration. The configuration object can currently be used to avoid certain event notification mechanisms.
+cfg | the event configuration object |
EVENT2_EXPORT_SYMBOL int event_base_once | +( | +struct event_base * | +base, | +
+ | + | evutil_socket_t | +fd, | +
+ | + | short | +events, | +
+ | + | event_callback_fn | +callback, | +
+ | + | void * | +arg, | +
+ | + | const struct timeval * | +timeout | +
+ | ) | ++ |
Schedule a one-time event.
+The function event_base_once() is similar to event_new(). However, it schedules a callback to be called exactly once, and does not require the caller to prepare an event structure.
+Note that in Libevent 2.0 and earlier, if the event is never triggered, the internal memory used to hold it will never be freed. In Libevent 2.1, the internal memory will get freed by event_base_free() if the event is never triggered. The 'arg' value, however, will not get freed in either case–you'll need to free that on your own if you want it to go away.
+base | an event_base |
fd | a file descriptor to monitor, or -1 for no fd. |
events | event(s) to monitor; can be any of EV_READ | EV_WRITE, or EV_TIMEOUT |
callback | callback function to be invoked when the event occurs |
arg | an argument to be passed to the callback function |
timeout | the maximum amount of time to wait for the event. NULL makes an EV_READ/EV_WRITE event make forever; NULL makes an EV_TIMEOUT event success immediately. |
EVENT2_EXPORT_SYMBOL int event_base_priority_init | +( | +struct event_base * | +eb, | +
+ | + | int | +npriorities | +
+ | ) | ++ |
Set the number of different event priorities.
+By default Libevent schedules all active events with the same priority. However, some time it is desirable to process some events with a higher priority than others. For that reason, Libevent supports strict priority queues. Active events with a lower priority are always processed before events with a higher priority.
+The number of different priorities can be set initially with the event_base_priority_init() function. This function should be called before the first call to event_base_dispatch(). The event_priority_set() function can be used to assign a priority to an event. By default, Libevent assigns the middle priority to all events unless their priority is explicitly set.
+Note that urgent-priority events can starve less-urgent events: after running all urgent-priority callbacks, Libevent checks for more urgent events again, before running less-urgent events. Less-urgent events will not have their callbacks run until there are no events more urgent than them that want to be active.
+eb | the event_base structure returned by event_base_new() |
npriorities | the maximum number of priorities |
EVENT2_EXPORT_SYMBOL int event_base_set | +( | +struct event_base * | +eb, | +
+ | + | struct event * | +ev | +
+ | ) | ++ |
Associate a different event base with an event.
+The event to be associated must not be currently active or pending.
+eb | the event base |
ev | the event |
EVENT2_EXPORT_SYMBOL int event_base_update_cache_time | +( | +struct event_base * | +base | ) | ++ |
Update cached_tv in the 'base' to the current time.
+You can use this function is useful for selectively increasing the accuracy of the cached time value in 'base' during callbacks that take a long time to execute.
+This function has no effect if the base is currently not in its event loop, or if timeval caching is disabled via EVENT_BASE_FLAG_NO_CACHE_TIME.
+EVENT2_EXPORT_SYMBOL int event_config_avoid_method | +( | +struct event_config * | +cfg, | +
+ | + | const char * | +method | +
+ | ) | ++ |
Enters an event method that should be avoided into the configuration.
+This can be used to avoid event mechanisms that do not support certain file descriptor types, or for debugging to avoid certain event mechanisms. An application can make use of multiple event bases to accommodate incompatible file descriptor types.
+cfg | the event configuration object |
method | the name of the event method to avoid |
EVENT2_EXPORT_SYMBOL void event_config_free | +( | +struct event_config * | +cfg | ) | ++ |
Deallocates all memory associated with an event configuration object.
+cfg | the event configuration object to be freed. |
EVENT2_EXPORT_SYMBOL struct event_config* event_config_new | +( | +void | +) | ++ |
Allocates a new event configuration object.
+The event configuration object can be used to change the behavior of an event base.
+EVENT2_EXPORT_SYMBOL int event_config_require_features | +( | +struct event_config * | +cfg, | +
+ | + | int | +feature | +
+ | ) | ++ |
Enters a required event method feature that the application demands.
+Note that not every feature or combination of features is supported on every platform. Code that requests features should be prepared to handle the case where event_base_new_with_config() returns NULL, as in:
+ event_config_require_features(cfg, EV_FEATURE_ET); + base = event_base_new_with_config(cfg); + if (base == NULL) { + // We can't get edge-triggered behavior here. + event_config_require_features(cfg, 0); + base = event_base_new_with_config(cfg); + } +
cfg | the event configuration object |
feature | a bitfield of one or more event_method_feature values. Replaces values from previous calls to this function. |
EVENT2_EXPORT_SYMBOL int event_config_set_flag | +( | +struct event_config * | +cfg, | +
+ | + | int | +flag | +
+ | ) | ++ |
Sets one or more flags to configure what parts of the eventual event_base will be initialized, and how they'll work.
+EVENT2_EXPORT_SYMBOL int event_config_set_max_dispatch_interval | +( | +struct event_config * | +cfg, | +
+ | + | const struct timeval * | +max_interval, | +
+ | + | int | +max_callbacks, | +
+ | + | int | +min_priority | +
+ | ) | ++ |
Record an interval and/or a number of callbacks after which the event base should check for new events.
+By default, the event base will run as many events are as activated at the highest activated priority before checking for new events. If you configure it by setting max_interval, it will check the time after each callback, and not allow more than max_interval to elapse before checking for new events. If you configure it by setting max_callbacks to a value >= 0, it will run no more than max_callbacks callbacks before checking for new events.
+This option can decrease the latency of high-priority events, and avoid priority inversions where multiple low-priority events keep us from polling for high-priority events, but at the expense of slightly decreasing the throughput. Use it with caution!
+cfg | The event_base configuration object. |
max_interval | An interval after which Libevent should stop running callbacks and check for more events, or NULL if there should be no such interval. |
max_callbacks | A number of callbacks after which Libevent should stop running callbacks and check for more events, or -1 if there should be no such limit. |
min_priority | A priority below which max_interval and max_callbacks should not be enforced. If this is set to 0, they are enforced for events of every priority; if it's set to 1, they're enforced for events of priority 1 and above, and so on. |
EVENT2_EXPORT_SYMBOL int event_config_set_num_cpus_hint | +( | +struct event_config * | +cfg, | +
+ | + | int | +cpus | +
+ | ) | ++ |
Records a hint for the number of CPUs in the system.
+This is used for tuning thread pools, etc, for optimal performance. In Libevent 2.0, it is only on Windows, and only when IOCP is in use.
+cfg | the event configuration object |
cpus | the number of cpus |
EVENT2_EXPORT_SYMBOL void event_debug_unassign | +( | +struct event * | +) | ++ |
When debugging mode is enabled, informs Libevent that an event should no longer be considered as assigned.
+When debugging mode is not enabled, does nothing.
+This function must only be called on a non-added event. The parameter must not be NULL.
+EVENT2_EXPORT_SYMBOL int event_del | +( | +struct event * | +ev | ) | ++ |
Remove an event from the set of monitored events.
+The function event_del() will cancel the event in the argument ev. If the event has already executed or has never been added the call will have no effect.
+ev | an event struct to be removed from the working set. ev must not be NULL. |
EVENT2_EXPORT_SYMBOL void event_enable_debug_logging | +( | +ev_uint32_t | +which | ) | ++ |
Turn on debugging logs and have them sent to the default log handler.
+This is a global setting; if you are going to call it, you must call this before any calls that create an event-base. You must call it before any multithreaded use of Libevent.
+Debug logs are verbose.
+which | Controls which debug messages are turned on. This option is unused for now; for forward compatibility, you must pass in the constant "EVENT_DBG_ALL" to turn debugging logs on, or "EVENT_DBG_NONE" to turn debugging logs off. |
EVENT2_EXPORT_SYMBOL void event_enable_debug_mode | +( | +void | +) | ++ |
Enable some relatively expensive debugging checks in Libevent that would normally be turned off.
+Generally, these checks cause code that would otherwise crash mysteriously to fail earlier with an assertion failure. Note that this method MUST be called before any events or event_bases have been created.
+Debug mode can currently catch the following errors: An event is re-assigned while it is added Any function is called on a non-assigned event
+Note that debugging mode uses memory to track every event that has been initialized (via event_assign, event_set, or event_new) but not yet released (via event_free or event_debug_unassign). If you want to use debug mode, and you find yourself running out of memory, you will need to use event_debug_unassign to explicitly stop tracking events that are no longer considered set-up.
+EVENT2_EXPORT_SYMBOL void event_free | +( | +struct event * | +) | ++ |
Deallocate a struct event * returned by event_new().
+If the event is pending or active, this function makes it non-pending and non-active first.
+ +EVENT2_EXPORT_SYMBOL void event_get_assignment | +( | +const struct event * | +event, | +
+ | + | struct event_base ** | +base_out, | +
+ | + | evutil_socket_t * | +fd_out, | +
+ | + | short * | +events_out, | +
+ | + | event_callback_fn * | +callback_out, | +
+ | + | void ** | +arg_out | +
+ | ) | ++ |
Extract all of arguments given to construct a given event.
+The event_base is copied into *base_out, the fd is copied into *fd_out, and so on.
+If any of the "_out" arguments is NULL, it will be ignored.
+ +EVENT2_EXPORT_SYMBOL int event_get_priority | +( | +const struct event * | +ev | ) | ++ |
Return the priority of an event.
+ + +EVENT2_EXPORT_SYMBOL size_t event_get_struct_event_size | +( | +void | +) | ++ |
Return the size of struct event that the Libevent library was compiled with.
+This will be NO GREATER than sizeof(struct event) if you're running with the same version of Libevent that your application was built with, but otherwise might not.
+Note that it might be SMALLER than sizeof(struct event) if some future version of Libevent adds extra padding to the end of struct event. We might do this to help ensure ABI-compatibility between different versions of Libevent.
+ +const EVENT2_EXPORT_SYMBOL char** event_get_supported_methods | +( | +void | +) | ++ |
Gets all event notification mechanisms supported by Libevent.
+This functions returns the event mechanism in order preferred by Libevent. Note that this list will include all backends that Libevent has compiled-in support for, and will not necessarily check your OS to see whether it has the required resources.
+const EVENT2_EXPORT_SYMBOL char* event_get_version | +( | +void | +) | ++ |
Get the Libevent version.
+Note that this will give you the version of the library that you're currently linked against, not the version of the headers that you've compiled against.
+EVENT2_EXPORT_SYMBOL ev_uint32_t event_get_version_number | +( | +void | +) | ++ |
Return a numeric representation of Libevent's version.
+Note that this will give you the version of the library that you're currently linked against, not the version of the headers you've used to compile.
+The format uses one byte each for the major, minor, and patchlevel parts of the version number. The low-order byte is unused. For example, version 2.0.1-alpha has a numeric representation of 0x02000100
+ +EVENT2_EXPORT_SYMBOL int event_initialized | +( | +const struct event * | +ev | ) | ++ |
Test if an event structure might be initialized.
+The event_initialized() function can be used to check if an event has been initialized.
+Warning: This function is only useful for distinguishing a zeroed-out piece of memory from an initialized event, it can easily be confused by uninitialized memory. Thus, it should ONLY be used to distinguish an initialized event from zero.
+ev | an event structure to be tested. ev must not be NULL. |
EVENT2_EXPORT_SYMBOL struct event* event_new | +( | +struct event_base * | +base, | +
+ | + | evutil_socket_t | +fd, | +
+ | + | short | +events, | +
+ | + | event_callback_fn | +callback, | +
+ | + | void * | +callback_arg | +
+ | ) | ++ |
Allocate and assign a new event structure, ready to be added.
+The function event_new() returns a new event that can be used in future calls to event_add() and event_del(). The fd and events arguments determine which conditions will trigger the event; the callback and callback_arg arguments tell Libevent what to do when the event becomes active.
+If events contains one of EV_READ, EV_WRITE, or EV_READ|EV_WRITE, then fd is a file descriptor or socket that should get monitored for readiness to read, readiness to write, or readiness for either operation (respectively). If events contains EV_SIGNAL, then fd is a signal number to wait for. If events contains none of those flags, then the event can be triggered only by a timeout or by manual activation with event_active(): In this case, fd must be -1.
+The EV_PERSIST flag can also be passed in the events argument: it makes event_add() persistent until event_del() is called.
+The EV_ET flag is compatible with EV_READ and EV_WRITE, and supported only by certain backends. It tells Libevent to use edge-triggered events.
+The EV_TIMEOUT flag has no effect here.
+It is okay to have multiple events all listening on the same fds; but they must either all be edge-triggered, or not be edge-triggered at all.
+When the event becomes active, the event loop will run the provided callback function, with three arguments. The first will be the provided fd value. The second will be a bitfield of the events that triggered: EV_READ, EV_WRITE, or EV_SIGNAL. Here the EV_TIMEOUT flag indicates that a timeout occurred, and EV_ET indicates that an edge-triggered event occurred. The third event will be the callback_arg pointer that you provide.
+base | the event base to which the event should be attached. |
fd | the file descriptor or signal to be monitored, or -1. |
events | desired events to monitor: bitfield of EV_READ, EV_WRITE, EV_SIGNAL, EV_PERSIST, EV_ET. |
callback | callback function to be invoked when the event occurs |
callback_arg | an argument to be passed to the callback function |
EVENT2_EXPORT_SYMBOL int event_pending | +( | +const struct event * | +ev, | +
+ | + | short | +events, | +
+ | + | struct timeval * | +tv | +
+ | ) | ++ |
Checks if a specific event is pending or scheduled.
+ev | an event struct previously passed to event_add() |
events | the requested event type; any of EV_TIMEOUT|EV_READ| EV_WRITE|EV_SIGNAL |
tv | if this field is not NULL, and the event has a timeout, this field is set to hold the time at which the timeout will expire. |
EVENT2_EXPORT_SYMBOL int event_priority_set | +( | +struct event * | +ev, | +
+ | + | int | +priority | +
+ | ) | ++ |
Assign a priority to an event.
+ev | an event struct |
priority | the new priority to be assigned |
EVENT2_EXPORT_SYMBOL int event_reinit | +( | +struct event_base * | +base | ) | ++ |
Reinitialize the event base after a fork.
+Some event mechanisms do not survive across fork. The event base needs to be reinitialized with the event_reinit() function.
+base | the event base that needs to be re-initialized |
EVENT2_EXPORT_SYMBOL int event_remove_timer | +( | +struct event * | +ev | ) | ++ |
Remove a timer from a pending event without removing the event itself.
+If the event has a scheduled timeout, this function unschedules it but leaves the event otherwise pending.
+ev | an event struct initialized via event_assign() or event_new() |
EVENT2_EXPORT_SYMBOL void* event_self_cbarg | +( | +void | +) | ++ |
Return a value used to specify that the event itself must be used as the callback argument.
+The function event_new() takes a callback argument which is passed to the event's callback function. To specify that the argument to be passed to the callback function is the event that event_new() returns, pass in the return value of event_self_cbarg() as the callback argument for event_new().
+For example:
+ struct event *ev = event_new(base, sock, events, callback, event_self_cbarg()); +
For consistency with event_new(), it is possible to pass the return value of this function as the callback argument for event_assign() – this achieves the same result as passing the event in directly.
+EVENT2_EXPORT_SYMBOL void event_set_fatal_callback | +( | +event_fatal_cb | +cb | ) | ++ |
Override Libevent's behavior in the event of a fatal internal error.
+By default, Libevent will call exit(1) if a programming error makes it impossible to continue correct operation. This function allows you to supply another callback instead. Note that if the function is ever invoked, something is wrong with your program, or with Libevent: any subsequent calls to Libevent may result in undefined behavior.
+Libevent will (almost) always log an EVENT_LOG_ERR message before calling this function; look at the last log message to see why Libevent has died.
+ +EVENT2_EXPORT_SYMBOL void event_set_log_callback | +( | +event_log_cb | +cb | ) | ++ |
Redirect Libevent's log messages.
+cb | a function taking two arguments: an integer severity between EVENT_LOG_DEBUG and EVENT_LOG_ERR, and a string. If cb is NULL, then the default log is used. |
NOTE: The function you provide must not call any other libevent functionality. Doing so can produce undefined behavior.
+ +EVENT2_EXPORT_SYMBOL void event_set_mem_functions | +( | +void *(*)(size_t sz) | +malloc_fn, | +
+ | + | void *(*)(void *ptr, size_t sz) | +realloc_fn, | +
+ | + | void(*)(void *ptr) | +free_fn | +
+ | ) | ++ |
Override the functions that Libevent uses for memory management.
+Usually, Libevent uses the standard libc functions malloc, realloc, and free to allocate memory. Passing replacements for those functions to event_set_mem_functions() overrides this behavior.
+Note that all memory returned from Libevent will be allocated by the replacement functions rather than by malloc() and realloc(). Thus, if you have replaced those functions, it will not be appropriate to free() memory that you get from Libevent. Instead, you must use the free_fn replacement that you provided.
+Note also that if you are going to call this function, you should do so before any call to any Libevent function that does allocation. Otherwise, those functions will allocate their memory using malloc(), but then later free it using your provided free_fn.
+malloc_fn | A replacement for malloc. |
realloc_fn | A replacement for realloc |
free_fn | A replacement for free. |
EVENT2_EXPORT_SYMBOL void libevent_global_shutdown | +( | +void | +) | ++ |
Release up all globally-allocated resources allocated by Libevent.
+This function does not free developer-controlled resources like event_bases, events, bufferevents, listeners, and so on. It only releases resources like global locks that there is no other way to free.
+It is not actually necessary to call this function before exit: every resource that it frees would be released anyway on exit. It mainly exists so that resource-leak debugging tools don't see Libevent as holding resources at exit.
+You should only call this function when no other Libevent functions will be invoked – e.g., when cleanly exiting a program.
+ +
+ libevent
+ 2.2.1
+
+ Event notification library
+ |
+
+ libevent
+ 2.2.1
+
+ Event notification library
+ |
+
Potentially non-threadsafe versions of the functions in event.h: provided only for backwards compatibility. +More...
+ +Go to the source code of this file.
++Macros | |
+#define | EVENT_FD(ev) ((int)event_get_fd(ev)) |
+#define | EVENT_SIGNAL(ev) event_get_signal(ev) |
+#define | evsignal_set(ev, x, cb, arg) event_set((ev), (x), EV_SIGNAL|EV_PERSIST, (cb), (arg)) |
+#define | evtimer_set(ev, cb, arg) event_set((ev), -1, 0, (cb), (arg)) |
timeout_* macros | |
Use the evtimer_* macros instead. + | |
+#define | timeout_add(ev, tv) event_add((ev), (tv)) |
+#define | timeout_del(ev) event_del(ev) |
+#define | timeout_initialized(ev) event_initialized(ev) |
+#define | timeout_pending(ev, tv) event_pending((ev), EV_TIMEOUT, (tv)) |
+#define | timeout_set(ev, cb, arg) event_set((ev), -1, 0, (cb), (arg)) |
signal_* macros | |
Use the evsignal_* macros instead. + | |
+#define | signal_add(ev, tv) event_add((ev), (tv)) |
+#define | signal_del(ev) event_del(ev) |
+#define | signal_initialized(ev) event_initialized(ev) |
+#define | signal_pending(ev, tv) event_pending((ev), EV_SIGNAL, (tv)) |
+#define | signal_set(ev, x, cb, arg) event_set((ev), (x), EV_SIGNAL|EV_PERSIST, (cb), (arg)) |
+Functions | |
EVENT2_EXPORT_SYMBOL int | event_dispatch (void) |
Loop to process events. More... | |
const EVENT2_EXPORT_SYMBOL char * | event_get_method (void) |
Get the kernel event notification mechanism used by Libevent. More... | |
EVENT2_EXPORT_SYMBOL struct event_base * | event_init (void) |
Initialize the event API. More... | |
EVENT2_EXPORT_SYMBOL int | event_loop (int) |
Handle events. More... | |
EVENT2_EXPORT_SYMBOL int | event_loopbreak (void) |
Abort the active event_loop() immediately. More... | |
EVENT2_EXPORT_SYMBOL int | event_loopexit (const struct timeval *) |
Exit the event loop after the specified time. More... | |
EVENT2_EXPORT_SYMBOL int | event_once (evutil_socket_t, short, void(*)(evutil_socket_t, short, void *), void *, const struct timeval *) |
Schedule a one-time event to occur. More... | |
EVENT2_EXPORT_SYMBOL int | event_priority_init (int) |
Set the number of different event priorities. More... | |
EVENT2_EXPORT_SYMBOL void | event_set (struct event *, evutil_socket_t, short, void(*)(evutil_socket_t, short, void *), void *) |
Prepare an event structure to be added. More... | |
Potentially non-threadsafe versions of the functions in event.h: provided only for backwards compatibility.
+In the oldest versions of Libevent, event_base was not a first-class structure. Instead, there was a single event base that every function manipulated. Later, when separate event bases were added, the old functions that didn't take an event_base argument needed to work by manipulating the "current" event base. This could lead to thread-safety issues, and obscure, hard-to-diagnose bugs.
+EVENT2_EXPORT_SYMBOL int event_dispatch | +( | +void | +) | ++ |
Loop to process events.
+Like event_base_dispatch(), but uses the "current" base.
+const EVENT2_EXPORT_SYMBOL char* event_get_method | +( | +void | +) | ++ |
Get the kernel event notification mechanism used by Libevent.
+EVENT2_EXPORT_SYMBOL struct event_base* event_init | +( | +void | +) | ++ |
Initialize the event API.
+The event API needs to be initialized with event_init() before it can be used. Sets the global current base that gets used for events that have no base associated with them.
+EVENT2_EXPORT_SYMBOL int event_loop | +( | +int | +) | ++ |
Handle events.
+This function behaves like event_base_loop(), but uses the "current" base
+EVENT2_EXPORT_SYMBOL int event_loopbreak | +( | +void | +) | ++ |
Abort the active event_loop() immediately.
+This function behaves like event_base_loopbreakt(), except that it uses the "current" base.
+EVENT2_EXPORT_SYMBOL int event_loopexit | +( | +const struct timeval * | +) | ++ |
Exit the event loop after the specified time.
+This function behaves like event_base_loopexit(), except that it uses the "current" base.
+EVENT2_EXPORT_SYMBOL int event_once | +( | +evutil_socket_t | +, | +
+ | + | short | +, | +
+ | + | void(*)(evutil_socket_t, short, void *) | +, | +
+ | + | void * | +, | +
+ | + | const struct timeval * | ++ |
+ | ) | ++ |
Schedule a one-time event to occur.
+EVENT2_EXPORT_SYMBOL int event_priority_init | +( | +int | +) | ++ |
Set the number of different event priorities.
+EVENT2_EXPORT_SYMBOL void event_set | +( | +struct event * | +, | +
+ | + | evutil_socket_t | +, | +
+ | + | short | +, | +
+ | + | void(*)(evutil_socket_t, short, void *) | +, | +
+ | + | void * | ++ |
+ | ) | ++ |
Prepare an event structure to be added.
+
+ libevent
+ 2.2.1
+
+ Event notification library
+ |
+
+ libevent
+ 2.2.1
+
+ Event notification library
+ |
+
▼ event2 | |
buffer.h | Functions for buffering data for network sending or receiving |
buffer_compat.h | Obsolete and deprecated versions of the functions in buffer.h: provided only for backward compatibility |
bufferevent.h | Functions for buffering data for network sending or receiving |
bufferevent_compat.h | Deprecated versions of the functions in bufferevent.h: provided only for backwards compatibility |
bufferevent_ssl.h | OpenSSL support for bufferevents |
dns.h | Provides a few APIs to use for resolving DNS names, and a facility for implementing simple DNS servers |
dns_compat.h | Potentially non-threadsafe versions of the functions in dns.h: provided only for backwards compatibility |
event.h | Core functions for waiting for and receiving events, and using event bases |
event_compat.h | Potentially non-threadsafe versions of the functions in event.h: provided only for backwards compatibility |
http.h | Basic support for HTTP serving |
http_compat.h | Potentially non-threadsafe versions of the functions in http.h: provided only for backwards compatibility |
listener.h | A callback that we invoke when a listener has a new connection |
rpc.h | This header files provides basic support for an RPC server and client |
rpc_compat.h | Deprecated versions of the functions in rpc.h: provided only for backwards compatibility |
tag.h | Helper functions for reading and writing tagged data onto buffers |
tag_compat.h | Obsolete/deprecated functions from tag.h; provided only for backwards compatibility |
thread.h | Functions for multi-threaded applications using Libevent |
util.h | Common convenience functions for cross-platform portability and related socket manipulations |
watch.h | "Prepare" and "check" watchers |
+ libevent
+ 2.2.1
+
+ Event notification library
+ |
+
+ libevent
+ 2.2.1
+
+ Event notification library
+ |
+
+ libevent
+ 2.2.1
+
+ Event notification library
+ |
+
+ libevent
+ 2.2.1
+
+ Event notification library
+ |
+
+ libevent
+ 2.2.1
+
+ Event notification library
+ |
+
+ libevent
+ 2.2.1
+
+ Event notification library
+ |
+
+ libevent
+ 2.2.1
+
+ Event notification library
+ |
+
+ libevent
+ 2.2.1
+
+ Event notification library
+ |
+
+ libevent
+ 2.2.1
+
+ Event notification library
+ |
+
+ libevent
+ 2.2.1
+
+ Event notification library
+ |
+
+ libevent
+ 2.2.1
+
+ Event notification library
+ |
+
+ libevent
+ 2.2.1
+
+ Event notification library
+ |
+
+ libevent
+ 2.2.1
+
+ Event notification library
+ |
+
+ libevent
+ 2.2.1
+
+ Event notification library
+ |
+
+ libevent
+ 2.2.1
+
+ Event notification library
+ |
+
+ libevent
+ 2.2.1
+
+ Event notification library
+ |
+
+ libevent
+ 2.2.1
+
+ Event notification library
+ |
+
Basic support for HTTP serving. +More...
+ +Go to the source code of this file.
++Data Structures | |
struct | evhttp_ext_method |
structure that is passed to (and modified by) the extended method callback function More... | |
+Macros | |
+#define | EVHTTP_CON_LINGERING_CLOSE 0x0020 |
+#define | EVHTTP_CON_PUBLIC_FLAGS_END 0x100000 |
+#define | EVHTTP_CON_READ_ON_WRITE_ERROR 0x0010 |
+#define | EVHTTP_CON_REUSE_CONNECTED_ADDR 0x0008 |
+#define | EVHTTP_METHOD_HAS_BODY 0x0001 |
+#define | EVHTTP_REQ_MAX EVHTTP_REQ_MOVE |
+#define | EVHTTP_SERVER_LINGERING_CLOSE 0x0001 |
#define | EVHTTP_URI_HOST_STRIP_BRACKETS 0x04 |
Strip brackets from the IPv6 address and only for evhttp_uri_get_host(), evhttp_uri_join() returns the host with brackets. More... | |
#define | EVHTTP_URI_NONCONFORMANT 0x01 |
Tolerate URIs that do not conform to RFC3986. More... | |
#define | EVHTTP_URI_QUERY_LAST_VAL 0x02 |
Prefer last value over the first from query args. More... | |
#define | EVHTTP_URI_QUERY_NONCONFORMANT 0x01 |
Tolerate queries that are not standard conformant. More... | |
#define | EVHTTP_URI_UNIX_SOCKET 0x08 |
Parse unix domain socket URIs, for example: More... | |
+#define | HTTP_ACCEPTED 202 |
accepted for processing | |
+#define | HTTP_BADGATEWAY 502 |
received an invalid response from the upstream | |
+#define | HTTP_BADMETHOD 405 |
method not allowed for this uri | |
+#define | HTTP_BADREQUEST 400 |
invalid http request was made | |
+#define | HTTP_CONTINUE 100 |
client should proceed to send | |
+#define | HTTP_CREATED 201 |
new resource is created | |
+#define | HTTP_EARLYHINTS 103 |
return some response headers | |
+#define | HTTP_ENTITYTOOLARGE 413 |
request is larger than the server is able to process | |
+#define | HTTP_EXPECTATIONFAILED 417 |
we can't handle this expectation | |
+#define | HTTP_FORBIDDEN 403 |
user not having the necessary permissions | |
+#define | HTTP_INTERNAL 500 |
internal error | |
+#define | HTTP_MOVEPERM 301 |
the uri moved permanently | |
+#define | HTTP_MOVETEMP 302 |
the uri moved temporarily | |
+#define | HTTP_NOCONTENT 204 |
request does not have content | |
+#define | HTTP_NONAUTHORITATIVE 203 |
returning a modified version of the origin's response | |
+#define | HTTP_NOTFOUND 404 |
could not find content for uri | |
+#define | HTTP_NOTIMPLEMENTED 501 |
not implemented | |
+#define | HTTP_NOTMODIFIED 304 |
page was not modified from last | |
+#define | HTTP_OK 200 |
request completed ok | |
+#define | HTTP_PAYMENTREQUIRED 402 |
user exceeded limit on requests | |
+#define | HTTP_PROCESSING 102 |
processing the request, but no response is available yet | |
+#define | HTTP_SERVUNAVAIL 503 |
the server is not available | |
+#define | HTTP_SWITCH_PROTOCOLS 101 |
switching to another protocol | |
+#define | HTTP_UNAUTHORIZED 401 |
authentication is required | |
+Typedefs | |
+typedef void | evhttp_bound_socket_foreach_fn(struct evhttp_bound_socket *, void *) |
+typedef int(* | evhttp_ext_method_cb) (struct evhttp_ext_method *) |
+Enumerations | |
enum | evhttp_cmd_type { + EVHTTP_REQ_GET = 1 << 0, +EVHTTP_REQ_POST = 1 << 1, +EVHTTP_REQ_HEAD = 1 << 2, +EVHTTP_REQ_PUT = 1 << 3, + + EVHTTP_REQ_DELETE = 1 << 4, +EVHTTP_REQ_OPTIONS = 1 << 5, +EVHTTP_REQ_TRACE = 1 << 6, +EVHTTP_REQ_CONNECT = 1 << 7, + + EVHTTP_REQ_PATCH = 1 << 8, +EVHTTP_REQ_PROPFIND = 1 << 9, +EVHTTP_REQ_PROPPATCH =1 << 10, +EVHTTP_REQ_MKCOL = 1 << 11, + + EVHTTP_REQ_LOCK = 1 << 12, +EVHTTP_REQ_UNLOCK = 1 << 13, +EVHTTP_REQ_COPY = 1 << 14, +EVHTTP_REQ_MOVE = 1 << 15 + + } |
The different request types supported by evhttp. More... | |
enum | evhttp_request_error { + EVREQ_HTTP_TIMEOUT, +EVREQ_HTTP_EOF, +EVREQ_HTTP_INVALID_HEADER, +EVREQ_HTTP_BUFFER_ERROR, + + EVREQ_HTTP_REQUEST_CANCEL, +EVREQ_HTTP_DATA_TOO_LONG + + } |
The different error types supported by evhttp. More... | |
enum | evhttp_request_kind { EVHTTP_REQUEST, +EVHTTP_RESPONSE + } |
a request object can represent either a request or a reply | |
+Functions | |
EVENT2_EXPORT_SYMBOL int | evhttp_accept_socket (struct evhttp *http, evutil_socket_t fd) |
Makes an HTTP server accept connections on the specified socket. More... | |
EVENT2_EXPORT_SYMBOL struct evhttp_bound_socket * | evhttp_accept_socket_with_handle (struct evhttp *http, evutil_socket_t fd) |
Like evhttp_accept_socket(), but returns a handle for referencing the socket. More... | |
EVENT2_EXPORT_SYMBOL int | evhttp_add_header (struct evkeyvalq *headers, const char *key, const char *value) |
Adds a header to a list of existing headers. More... | |
EVENT2_EXPORT_SYMBOL int | evhttp_add_server_alias (struct evhttp *http, const char *alias) |
Add a server alias to an http object. More... | |
EVENT2_EXPORT_SYMBOL int | evhttp_add_virtual_host (struct evhttp *http, const char *pattern, struct evhttp *vhost) |
Adds a virtual host to the http server. More... | |
EVENT2_EXPORT_SYMBOL struct evhttp_bound_socket * | evhttp_bind_listener (struct evhttp *http, struct evconnlistener *listener) |
The most low-level evhttp_bind/accept method: takes an evconnlistener, and returns an evhttp_bound_socket. More... | |
EVENT2_EXPORT_SYMBOL int | evhttp_bind_socket (struct evhttp *http, const char *address, ev_uint16_t port) |
Binds an HTTP server on the specified address and port. More... | |
EVENT2_EXPORT_SYMBOL struct evhttp_bound_socket * | evhttp_bind_socket_with_handle (struct evhttp *http, const char *address, ev_uint16_t port) |
Like evhttp_bind_socket(), but returns a handle for referencing the socket. More... | |
+EVENT2_EXPORT_SYMBOL void | evhttp_bound_set_bevcb (struct evhttp_bound_socket *bound, struct bufferevent *(*cb)(struct event_base *, void *), void *cbarg) |
EVENT2_EXPORT_SYMBOL evutil_socket_t | evhttp_bound_socket_get_fd (struct evhttp_bound_socket *bound_socket) |
Get the raw file descriptor referenced by an evhttp_bound_socket. More... | |
+EVENT2_EXPORT_SYMBOL struct evconnlistener * | evhttp_bound_socket_get_listener (struct evhttp_bound_socket *bound) |
Return the listener used to implement a bound socket. | |
EVENT2_EXPORT_SYMBOL void | evhttp_cancel_request (struct evhttp_request *req) |
Cancels a pending HTTP request. More... | |
EVENT2_EXPORT_SYMBOL void | evhttp_clear_headers (struct evkeyvalq *headers) |
Removes all headers from the header list. More... | |
EVENT2_EXPORT_SYMBOL struct evhttp_connection * | evhttp_connection_base_bufferevent_new (struct event_base *base, struct evdns_base *dnsbase, struct bufferevent *bev, const char *address, ev_uint16_t port) |
Create and return a connection object that can be used to for making HTTP requests. More... | |
EVENT2_EXPORT_SYMBOL struct evhttp_connection * | evhttp_connection_base_bufferevent_unix_new (struct event_base *base, struct bufferevent *bev, const char *path) |
Create and return a connection object that can be used to for making HTTP requests over an unix domain socket. More... | |
EVENT2_EXPORT_SYMBOL struct evhttp_connection * | evhttp_connection_base_new (struct event_base *base, struct evdns_base *dnsbase, const char *address, ev_uint16_t port) |
Create and return a connection object that can be used to for making HTTP requests. More... | |
+EVENT2_EXPORT_SYMBOL void | evhttp_connection_free (struct evhttp_connection *evcon) |
Frees an http connection. | |
EVENT2_EXPORT_SYMBOL void | evhttp_connection_free_on_completion (struct evhttp_connection *evcon) |
Disowns a given connection object. More... | |
EVENT2_EXPORT_SYMBOL const struct sockaddr * | evhttp_connection_get_addr (struct evhttp_connection *evcon) |
Get the remote address associated with this connection. More... | |
+EVENT2_EXPORT_SYMBOL struct event_base * | evhttp_connection_get_base (struct evhttp_connection *req) |
Returns the underlying event_base for this connection. | |
+EVENT2_EXPORT_SYMBOL struct bufferevent * | evhttp_connection_get_bufferevent (struct evhttp_connection *evcon) |
Return the bufferevent that an evhttp_connection is using. | |
+EVENT2_EXPORT_SYMBOL void | evhttp_connection_get_peer (struct evhttp_connection *evcon, const char **address, ev_uint16_t *port) |
Get the remote address and port associated with this connection. | |
+EVENT2_EXPORT_SYMBOL struct evhttp * | evhttp_connection_get_server (struct evhttp_connection *evcon) |
Return the HTTP server associated with this connection, or NULL. | |
+EVENT2_EXPORT_SYMBOL void | evhttp_connection_set_closecb (struct evhttp_connection *evcon, void(*)(struct evhttp_connection *, void *), void *) |
Set a callback for connection close. | |
EVENT2_EXPORT_SYMBOL void | evhttp_connection_set_connect_timeout_tv (struct evhttp_connection *evcon, const struct timeval *tv) |
Sets the connect timeout for this connection. More... | |
EVENT2_EXPORT_SYMBOL void | evhttp_connection_set_ext_method_cmp (struct evhttp_connection *evcon, evhttp_ext_method_cb cmp) |
Sets extended method cmp callback for this http connection. More... | |
+EVENT2_EXPORT_SYMBOL void | evhttp_connection_set_family (struct evhttp_connection *evcon, int family) |
Set family hint for DNS requests. | |
EVENT2_EXPORT_SYMBOL int | evhttp_connection_set_flags (struct evhttp_connection *evcon, int flags) |
Set connection flags. More... | |
EVENT2_EXPORT_SYMBOL void | evhttp_connection_set_initial_retry_tv (struct evhttp_connection *evcon, const struct timeval *tv) |
Sets the delay before retrying requests on this connection. More... | |
EVENT2_EXPORT_SYMBOL void | evhttp_connection_set_local_address (struct evhttp_connection *evcon, const char *address) |
Sets the IP address from which http connections are made. More... | |
+EVENT2_EXPORT_SYMBOL void | evhttp_connection_set_local_port (struct evhttp_connection *evcon, ev_uint16_t port) |
sets the local port from which http connections are made | |
+EVENT2_EXPORT_SYMBOL void | evhttp_connection_set_max_body_size (struct evhttp_connection *evcon, ev_ssize_t new_max_body_size) |
+EVENT2_EXPORT_SYMBOL void | evhttp_connection_set_max_headers_size (struct evhttp_connection *evcon, ev_ssize_t new_max_headers_size) |
EVENT2_EXPORT_SYMBOL void | evhttp_connection_set_read_timeout_tv (struct evhttp_connection *evcon, const struct timeval *tv) |
Sets the read timeout for this connection. More... | |
+EVENT2_EXPORT_SYMBOL void | evhttp_connection_set_retries (struct evhttp_connection *evcon, int retry_max) |
Sets the retry limit for this connection - -1 repeats indefinitely. | |
EVENT2_EXPORT_SYMBOL void | evhttp_connection_set_timeout (struct evhttp_connection *evcon, int timeout) |
Sets the timeout for this connection. More... | |
EVENT2_EXPORT_SYMBOL void | evhttp_connection_set_timeout_tv (struct evhttp_connection *evcon, const struct timeval *tv) |
Sets the timeout for this connection for the following events: More... | |
EVENT2_EXPORT_SYMBOL void | evhttp_connection_set_write_timeout_tv (struct evhttp_connection *evcon, const struct timeval *tv) |
Sets the write timeout for this connection. More... | |
EVENT2_EXPORT_SYMBOL char * | evhttp_decode_uri (const char *uri) |
Helper function to sort of decode a URI-encoded string. More... | |
EVENT2_EXPORT_SYMBOL void | evhttp_del_accept_socket (struct evhttp *http, struct evhttp_bound_socket *bound_socket) |
Makes an HTTP server stop accepting connections on the specified socket. More... | |
+EVENT2_EXPORT_SYMBOL int | evhttp_del_cb (struct evhttp *, const char *) |
Removes the callback for a specified URI. | |
EVENT2_EXPORT_SYMBOL char * | evhttp_encode_uri (const char *str) |
Helper function to encode a string for inclusion in a URI. More... | |
const EVENT2_EXPORT_SYMBOL char * | evhttp_find_header (const struct evkeyvalq *headers, const char *key) |
Finds the value belonging to a header. More... | |
EVENT2_EXPORT_SYMBOL void | evhttp_foreach_bound_socket (struct evhttp *http, evhttp_bound_socket_foreach_fn *function, void *argument) |
Applies the function specified in the first argument to all evhttp_bound_sockets associated with "http". More... | |
EVENT2_EXPORT_SYMBOL void | evhttp_free (struct evhttp *http) |
Free the previously created HTTP server. More... | |
EVENT2_EXPORT_SYMBOL int | evhttp_get_connection_count (struct evhttp *http) |
Get the current number of connections. More... | |
EVENT2_EXPORT_SYMBOL char * | evhttp_htmlescape (const char *html) |
Escape HTML character entities in a string. More... | |
EVENT2_EXPORT_SYMBOL int | evhttp_make_request (struct evhttp_connection *evcon, struct evhttp_request *req, enum evhttp_cmd_type type, const char *uri) |
Make an HTTP request over the specified connection. More... | |
EVENT2_EXPORT_SYMBOL struct evhttp * | evhttp_new (struct event_base *base) |
Create a new HTTP server. More... | |
EVENT2_EXPORT_SYMBOL int | evhttp_parse_query (const char *uri, struct evkeyvalq *headers) |
Helper function to parse out arguments in a query. More... | |
EVENT2_EXPORT_SYMBOL int | evhttp_parse_query_str (const char *uri, struct evkeyvalq *headers) |
EVENT2_EXPORT_SYMBOL int | evhttp_parse_query_str_flags (const char *uri, struct evkeyvalq *headers, unsigned flags) |
Helper function to parse out arguments from the query portion of an HTTP URI. More... | |
EVENT2_EXPORT_SYMBOL int | evhttp_remove_header (struct evkeyvalq *headers, const char *key) |
Removes a header from a list of existing headers. More... | |
EVENT2_EXPORT_SYMBOL int | evhttp_remove_server_alias (struct evhttp *http, const char *alias) |
Remove a server alias from an http object. More... | |
EVENT2_EXPORT_SYMBOL int | evhttp_remove_virtual_host (struct evhttp *http, struct evhttp *vhost) |
Removes a virtual host from the http server. More... | |
+EVENT2_EXPORT_SYMBOL void | evhttp_request_free (struct evhttp_request *req) |
Frees the request object and removes associated events. | |
+EVENT2_EXPORT_SYMBOL enum evhttp_cmd_type | evhttp_request_get_command (const struct evhttp_request *req) |
Returns the request command. | |
EVENT2_EXPORT_SYMBOL struct evhttp_connection * | evhttp_request_get_connection (struct evhttp_request *req) |
Returns the connection object associated with the request or NULL. More... | |
+EVENT2_EXPORT_SYMBOL const struct evhttp_uri * | evhttp_request_get_evhttp_uri (const struct evhttp_request *req) |
Returns the request URI (parsed) | |
const EVENT2_EXPORT_SYMBOL char * | evhttp_request_get_host (struct evhttp_request *req) |
Returns the host associated with the request. More... | |
+EVENT2_EXPORT_SYMBOL struct evbuffer * | evhttp_request_get_input_buffer (struct evhttp_request *req) |
Returns the input buffer. | |
+EVENT2_EXPORT_SYMBOL struct evkeyvalq * | evhttp_request_get_input_headers (struct evhttp_request *req) |
Returns the input headers. | |
+EVENT2_EXPORT_SYMBOL struct evbuffer * | evhttp_request_get_output_buffer (struct evhttp_request *req) |
Returns the output buffer. | |
+EVENT2_EXPORT_SYMBOL struct evkeyvalq * | evhttp_request_get_output_headers (struct evhttp_request *req) |
Returns the output headers. | |
+EVENT2_EXPORT_SYMBOL int | evhttp_request_get_response_code (const struct evhttp_request *req) |
+const EVENT2_EXPORT_SYMBOL char * | evhttp_request_get_response_code_line (const struct evhttp_request *req) |
+const EVENT2_EXPORT_SYMBOL char * | evhttp_request_get_uri (const struct evhttp_request *req) |
Returns the request URI. | |
+EVENT2_EXPORT_SYMBOL int | evhttp_request_is_owned (struct evhttp_request *req) |
Returns 1 if the request is owned by the user. | |
EVENT2_EXPORT_SYMBOL struct evhttp_request * | evhttp_request_new (void(*cb)(struct evhttp_request *, void *), void *arg) |
Creates a new request object that needs to be filled in with the request parameters. More... | |
EVENT2_EXPORT_SYMBOL void | evhttp_request_own (struct evhttp_request *req) |
Takes ownership of the request object. More... | |
EVENT2_EXPORT_SYMBOL void | evhttp_request_set_chunked_cb (struct evhttp_request *, void(*cb)(struct evhttp_request *, void *)) |
Enable delivery of chunks to requestor. More... | |
EVENT2_EXPORT_SYMBOL void | evhttp_request_set_error_cb (struct evhttp_request *, void(*)(enum evhttp_request_error, void *)) |
Set a callback for errors. More... | |
EVENT2_EXPORT_SYMBOL void | evhttp_request_set_header_cb (struct evhttp_request *, int(*cb)(struct evhttp_request *, void *)) |
Register callback for additional parsing of request headers. More... | |
EVENT2_EXPORT_SYMBOL void | evhttp_request_set_on_complete_cb (struct evhttp_request *req, void(*cb)(struct evhttp_request *, void *), void *cb_arg) |
Set a callback to be called on request completion of evhttp_send_* function. More... | |
EVENT2_EXPORT_SYMBOL void | evhttp_send_error (struct evhttp_request *req, int error, const char *reason) |
Send an HTML error message to the client. More... | |
EVENT2_EXPORT_SYMBOL void | evhttp_send_reply (struct evhttp_request *req, int code, const char *reason, struct evbuffer *databuf) |
Send an HTML reply to the client. More... | |
EVENT2_EXPORT_SYMBOL void | evhttp_send_reply_chunk (struct evhttp_request *req, struct evbuffer *databuf) |
Send another data chunk as part of an ongoing chunked reply. More... | |
EVENT2_EXPORT_SYMBOL void | evhttp_send_reply_chunk_with_cb (struct evhttp_request *req, struct evbuffer *databuf, void(*cb)(struct evhttp_connection *, void *), void *arg) |
Send another data chunk as part of an ongoing chunked reply. More... | |
EVENT2_EXPORT_SYMBOL void | evhttp_send_reply_end (struct evhttp_request *req) |
Complete a chunked reply, freeing the request as appropriate. More... | |
EVENT2_EXPORT_SYMBOL void | evhttp_send_reply_start (struct evhttp_request *req, int code, const char *reason) |
Initiate a reply that uses Transfer-Encoding chunked. More... | |
EVENT2_EXPORT_SYMBOL void | evhttp_set_allowed_methods (struct evhttp *http, ev_uint32_t methods) |
Sets the what HTTP methods are supported in requests accepted by this server, and passed to user callbacks. More... | |
EVENT2_EXPORT_SYMBOL void | evhttp_set_bevcb (struct evhttp *http, struct bufferevent *(*cb)(struct event_base *, void *), void *arg) |
Set a callback used to create new bufferevents for connections to a given evhttp object. More... | |
EVENT2_EXPORT_SYMBOL int | evhttp_set_cb (struct evhttp *http, const char *path, void(*cb)(struct evhttp_request *, void *), void *cb_arg) |
Set a callback for a specified URI. More... | |
EVENT2_EXPORT_SYMBOL void | evhttp_set_default_content_type (struct evhttp *http, const char *content_type) |
Set the value to use for the Content-Type header when none was provided. More... | |
EVENT2_EXPORT_SYMBOL void | evhttp_set_errorcb (struct evhttp *http, int(*cb)(struct evhttp_request *req, struct evbuffer *buffer, int error, const char *reason, void *cbarg), void *cbarg) |
Set a callback to output for any error pages sent for requests of a given evhttp object. More... | |
EVENT2_EXPORT_SYMBOL void | evhttp_set_ext_method_cmp (struct evhttp *http, evhttp_ext_method_cb cmp) |
Sets the callback function which allows HTTP extended methods to be supported by this server. More... | |
EVENT2_EXPORT_SYMBOL int | evhttp_set_flags (struct evhttp *http, int flags) |
Set connection flags for HTTP server. More... | |
EVENT2_EXPORT_SYMBOL void | evhttp_set_gencb (struct evhttp *http, void(*cb)(struct evhttp_request *, void *), void *arg) |
Set a callback for all requests that are not caught by specific callbacks. More... | |
+EVENT2_EXPORT_SYMBOL void | evhttp_set_max_body_size (struct evhttp *http, ev_ssize_t max_body_size) |
XXX Document. | |
EVENT2_EXPORT_SYMBOL void | evhttp_set_max_connections (struct evhttp *http, int max_connections) |
Set the maximum number of simultaneous connections for this server. More... | |
+EVENT2_EXPORT_SYMBOL void | evhttp_set_max_headers_size (struct evhttp *http, ev_ssize_t max_headers_size) |
XXX Document. | |
EVENT2_EXPORT_SYMBOL void | evhttp_set_newreqcb (struct evhttp *http, int(*cb)(struct evhttp_request *, void *), void *arg) |
Set a callback which allows the user to note or throttle incoming requests. More... | |
EVENT2_EXPORT_SYMBOL void | evhttp_set_read_timeout_tv (struct evhttp *http, const struct timeval *tv) |
Set read timeout for an HTTP request. More... | |
EVENT2_EXPORT_SYMBOL void | evhttp_set_timeout (struct evhttp *http, int timeout) |
Set the timeout for an HTTP request. More... | |
EVENT2_EXPORT_SYMBOL void | evhttp_set_timeout_tv (struct evhttp *http, const struct timeval *tv) |
Set read and write timeout for an HTTP request. More... | |
EVENT2_EXPORT_SYMBOL void | evhttp_set_write_timeout_tv (struct evhttp *http, const struct timeval *tv) |
Set write timeout for an HTTP request. More... | |
EVENT2_EXPORT_SYMBOL void | evhttp_uri_free (struct evhttp_uri *uri) |
Free all memory allocated for a parsed uri. More... | |
+const EVENT2_EXPORT_SYMBOL char * | evhttp_uri_get_fragment (const struct evhttp_uri *uri) |
Return the fragment part of an evhttp_uri (excluding the leading "#"), or NULL if it has no fragment set. | |
const EVENT2_EXPORT_SYMBOL char * | evhttp_uri_get_host (const struct evhttp_uri *uri) |
Return the host part of an evhttp_uri, or NULL if it has no host set. More... | |
+const EVENT2_EXPORT_SYMBOL char * | evhttp_uri_get_path (const struct evhttp_uri *uri) |
Return the path part of an evhttp_uri, or NULL if it has no path set. | |
+EVENT2_EXPORT_SYMBOL int | evhttp_uri_get_port (const struct evhttp_uri *uri) |
Return the port part of an evhttp_uri, or -1 if there is no port set. | |
+const EVENT2_EXPORT_SYMBOL char * | evhttp_uri_get_query (const struct evhttp_uri *uri) |
Return the query part of an evhttp_uri (excluding the leading "?"), or NULL if it has no query set. | |
+const EVENT2_EXPORT_SYMBOL char * | evhttp_uri_get_scheme (const struct evhttp_uri *uri) |
Return the scheme of an evhttp_uri, or NULL if there is no scheme has been set and the evhttp_uri contains a Relative-Ref. | |
+const EVENT2_EXPORT_SYMBOL char * | evhttp_uri_get_unixsocket (const struct evhttp_uri *uri) |
Return the unix socket part of an evhttp_uri, or NULL if there is no unix socket set. | |
+const EVENT2_EXPORT_SYMBOL char * | evhttp_uri_get_userinfo (const struct evhttp_uri *uri) |
Return the userinfo part of an evhttp_uri, or NULL if it has no userinfo set. | |
EVENT2_EXPORT_SYMBOL char * | evhttp_uri_join (const struct evhttp_uri *uri, char *buf, size_t limit) |
Join together the uri parts from parsed data to form a URI-Reference. More... | |
+EVENT2_EXPORT_SYMBOL struct evhttp_uri * | evhttp_uri_new (void) |
Return a new empty evhttp_uri with no fields set. | |
+EVENT2_EXPORT_SYMBOL struct evhttp_uri * | evhttp_uri_parse (const char *source_uri) |
Alias for evhttp_uri_parse_with_flags(source_uri, 0) | |
EVENT2_EXPORT_SYMBOL struct evhttp_uri * | evhttp_uri_parse_with_flags (const char *source_uri, unsigned flags) |
Helper function to parse a URI-Reference as specified by RFC3986. More... | |
EVENT2_EXPORT_SYMBOL void | evhttp_uri_set_flags (struct evhttp_uri *uri, unsigned flags) |
Changes the flags set on a given URI. More... | |
EVENT2_EXPORT_SYMBOL int | evhttp_uri_set_fragment (struct evhttp_uri *uri, const char *fragment) |
Set the fragment of an evhttp_uri, or clear the fragment if fragment==NULL. More... | |
EVENT2_EXPORT_SYMBOL int | evhttp_uri_set_host (struct evhttp_uri *uri, const char *host) |
Set the host of an evhttp_uri, or clear the host if host==NULL. More... | |
EVENT2_EXPORT_SYMBOL int | evhttp_uri_set_path (struct evhttp_uri *uri, const char *path) |
Set the path of an evhttp_uri, or clear the path if path==NULL. More... | |
EVENT2_EXPORT_SYMBOL int | evhttp_uri_set_port (struct evhttp_uri *uri, int port) |
Set the port of an evhttp_uri, or clear the port if port==-1. More... | |
EVENT2_EXPORT_SYMBOL int | evhttp_uri_set_query (struct evhttp_uri *uri, const char *query) |
Set the query of an evhttp_uri, or clear the query if query==NULL. More... | |
EVENT2_EXPORT_SYMBOL int | evhttp_uri_set_scheme (struct evhttp_uri *uri, const char *scheme) |
Set the scheme of an evhttp_uri, or clear the scheme if scheme==NULL. More... | |
EVENT2_EXPORT_SYMBOL int | evhttp_uri_set_unixsocket (struct evhttp_uri *uri, const char *unixsocket) |
Set the unix socket of an evhttp_uri, or clear the unix socket if unixsocket==NULL. More... | |
EVENT2_EXPORT_SYMBOL int | evhttp_uri_set_userinfo (struct evhttp_uri *uri, const char *userinfo) |
Set the userinfo of an evhttp_uri, or clear the userinfo if userinfo==NULL. More... | |
EVENT2_EXPORT_SYMBOL char * | evhttp_uridecode (const char *uri, int decode_plus, size_t *size_out) |
Helper function to decode a URI-escaped string or HTTP parameter. More... | |
EVENT2_EXPORT_SYMBOL char * | evhttp_uriencode (const char *str, ev_ssize_t size, int space_to_plus) |
As evhttp_encode_uri, but if 'size' is nonnegative, treat the string as being 'size' bytes long. More... | |
Basic support for HTTP serving.
+As Libevent is a library for dealing with event notification and most interesting applications are networked today, I have often found the need to write HTTP code. The following prototypes and definitions provide an application with a minimal interface for making HTTP requests and for creating a very simple HTTP server.
+#define EVHTTP_URI_HOST_STRIP_BRACKETS 0x04 | +
Strip brackets from the IPv6 address and only for evhttp_uri_get_host(), evhttp_uri_join() returns the host with brackets.
+Thus you can use host part of the evhttp_uri for getaddrinfo().
+#define EVHTTP_URI_NONCONFORMANT 0x01 | +
Tolerate URIs that do not conform to RFC3986.
+Unfortunately, some HTTP clients generate URIs that, according to RFC3986, are not conformant URIs. If you need to support these URIs, you can do so by passing this flag to evhttp_uri_parse_with_flags.
+Currently, these changes are:
#define EVHTTP_URI_QUERY_LAST_VAL 0x02 | +
Prefer last value over the first from query args.
+Example: test=123&test=456 Without: test=123 With : test=456
+ +#define EVHTTP_URI_QUERY_NONCONFORMANT 0x01 | +
Tolerate queries that are not standard conformant.
+Here are some examples:
+#define EVHTTP_URI_UNIX_SOCKET 0x08 | +
Parse unix domain socket URIs, for example:
+ + +enum evhttp_cmd_type | +
The different request types supported by evhttp.
+These are as specified in RFC2616, except for:
By default, only some of these methods are accepted and passed to user callbacks; use evhttp_set_allowed_methods() to change which methods are allowed.
+ +enum evhttp_request_error | +
The different error types supported by evhttp.
+Enumerator | |
---|---|
EVREQ_HTTP_TIMEOUT | Timeout reached, also. +
|
EVREQ_HTTP_EOF | EOF reached. + |
EVREQ_HTTP_INVALID_HEADER | Error while reading header, or invalid header. + |
EVREQ_HTTP_BUFFER_ERROR | Error encountered while reading or writing. + |
EVREQ_HTTP_REQUEST_CANCEL | The evhttp_cancel_request() called on this request. + |
EVREQ_HTTP_DATA_TOO_LONG | Body is greater then evhttp_connection_set_max_body_size() + |
EVENT2_EXPORT_SYMBOL int evhttp_accept_socket | +( | +struct evhttp * | +http, | +
+ | + | evutil_socket_t | +fd | +
+ | ) | ++ |
Makes an HTTP server accept connections on the specified socket.
+This may be useful to create a socket and then fork multiple instances of an http server, or when a socket has been communicated via file descriptor passing in situations where an http servers does not have permissions to bind to a low-numbered port.
+Can be called multiple times to have the http server listen to multiple different sockets.
+http | a pointer to an evhttp object |
fd | a socket fd that is ready for accepting connections |
EVENT2_EXPORT_SYMBOL struct evhttp_bound_socket* evhttp_accept_socket_with_handle | +( | +struct evhttp * | +http, | +
+ | + | evutil_socket_t | +fd | +
+ | ) | ++ |
Like evhttp_accept_socket(), but returns a handle for referencing the socket.
+The returned pointer is not valid after http is freed.
+http | a pointer to an evhttp object |
fd | a socket fd that is ready for accepting connections |
EVENT2_EXPORT_SYMBOL int evhttp_add_header | +( | +struct evkeyvalq * | +headers, | +
+ | + | const char * | +key, | +
+ | + | const char * | +value | +
+ | ) | ++ |
Adds a header to a list of existing headers.
+headers | the evkeyvalq object to which to add a header. headers must not be NULL. |
key | the name of the header |
value | the value belonging to the header |
EVENT2_EXPORT_SYMBOL int evhttp_add_server_alias | +( | +struct evhttp * | +http, | +
+ | + | const char * | +alias | +
+ | ) | ++ |
Add a server alias to an http object.
+The http object can be a virtual host or the main server.
+http | the evhttp object |
alias | the alias to add |
EVENT2_EXPORT_SYMBOL int evhttp_add_virtual_host | +( | +struct evhttp * | +http, | +
+ | + | const char * | +pattern, | +
+ | + | struct evhttp * | +vhost | +
+ | ) | ++ |
Adds a virtual host to the http server.
+A virtual host is a newly initialized evhttp object that has request callbacks set on it via evhttp_set_cb() or evhttp_set_gencb(). It most not have any listing sockets associated with it.
+If the virtual host has not been removed by the time that evhttp_free() is called on the main http server, it will be automatically freed, too.
+It is possible to have hierarchical vhosts. For example: A vhost with the pattern *.example.com may have other vhosts with patterns foo.example.com and bar.example.com associated with it.
+http | the evhttp object to which to add a virtual host |
pattern | the glob pattern against which the hostname is matched. The match is case insensitive and follows otherwise regular shell matching. |
vhost | the virtual host to add the regular http server. |
EVENT2_EXPORT_SYMBOL struct evhttp_bound_socket* evhttp_bind_listener | +( | +struct evhttp * | +http, | +
+ | + | struct evconnlistener * | +listener | +
+ | ) | ++ |
The most low-level evhttp_bind/accept method: takes an evconnlistener, and returns an evhttp_bound_socket.
+The listener will be freed when the bound socket is freed.
+ +EVENT2_EXPORT_SYMBOL int evhttp_bind_socket | +( | +struct evhttp * | +http, | +
+ | + | const char * | +address, | +
+ | + | ev_uint16_t | +port | +
+ | ) | ++ |
Binds an HTTP server on the specified address and port.
+Can be called multiple times to bind the same http server to multiple different ports.
+http | a pointer to an evhttp object |
address | a string containing the IP address to listen(2) on |
port | the port number to listen on |
EVENT2_EXPORT_SYMBOL struct evhttp_bound_socket* evhttp_bind_socket_with_handle | +( | +struct evhttp * | +http, | +
+ | + | const char * | +address, | +
+ | + | ev_uint16_t | +port | +
+ | ) | ++ |
Like evhttp_bind_socket(), but returns a handle for referencing the socket.
+The returned pointer is not valid after http is freed.
+http | a pointer to an evhttp object |
address | a string containing the IP address to listen(2) on |
port | the port number to listen on |
EVENT2_EXPORT_SYMBOL evutil_socket_t evhttp_bound_socket_get_fd | +( | +struct evhttp_bound_socket * | +bound_socket | ) | ++ |
Get the raw file descriptor referenced by an evhttp_bound_socket.
+bound_socket | a handle returned by evhttp_{bind,accept}_socket_with_handle |
EVENT2_EXPORT_SYMBOL void evhttp_cancel_request | +( | +struct evhttp_request * | +req | ) | ++ |
Cancels a pending HTTP request.
+Cancels an ongoing HTTP request. The callback associated with this request is not executed and the request object is freed. If the request is currently being processed, e.g. it is ongoing, the corresponding evhttp_connection object is going to get reset.
+A request cannot be canceled if its callback has executed already. A request may be canceled reentrantly from its chunked callback.
+req | the evhttp_request to cancel; req becomes invalid after this call. |
EVENT2_EXPORT_SYMBOL void evhttp_clear_headers | +( | +struct evkeyvalq * | +headers | ) | ++ |
Removes all headers from the header list.
+headers | the evkeyvalq object from which to remove all headers |
EVENT2_EXPORT_SYMBOL struct evhttp_connection* evhttp_connection_base_bufferevent_new | +( | +struct event_base * | +base, | +
+ | + | struct evdns_base * | +dnsbase, | +
+ | + | struct bufferevent * | +bev, | +
+ | + | const char * | +address, | +
+ | + | ev_uint16_t | +port | +
+ | ) | ++ |
Create and return a connection object that can be used to for making HTTP requests.
+The connection object tries to resolve address and establish the connection when it is given an http request object.
+Connection also has default timeouts for the following events:
base | the event_base to use for handling the connection |
dnsbase | the dns_base to use for resolving host names; if not specified host name resolution will block. |
bev | a bufferevent to use for connecting to the server; if NULL, a socket-based bufferevent will be created. This bufferevent will be freed when the connection closes. It must have no fd set on it. |
address | the address to which to connect |
port | the port to connect to |
EVENT2_EXPORT_SYMBOL struct evhttp_connection* evhttp_connection_base_bufferevent_unix_new | +( | +struct event_base * | +base, | +
+ | + | struct bufferevent * | +bev, | +
+ | + | const char * | +path | +
+ | ) | ++ |
Create and return a connection object that can be used to for making HTTP requests over an unix domain socket.
+base | the event_base to use for handling the connection |
bev | a bufferevent to use for connecting to the server; if NULL, a socket-based bufferevent will be created. This bufferevent will be freed when the connection closes. It must have no fd set on it. |
path | path of unix domain socket |
EVENT2_EXPORT_SYMBOL struct evhttp_connection* evhttp_connection_base_new | +( | +struct event_base * | +base, | +
+ | + | struct evdns_base * | +dnsbase, | +
+ | + | const char * | +address, | +
+ | + | ev_uint16_t | +port | +
+ | ) | ++ |
Create and return a connection object that can be used to for making HTTP requests.
+The connection object tries to resolve address and establish the connection when it is given an http request object.
+base | the event_base to use for handling the connection |
dnsbase | the dns_base to use for resolving host names; if not specified host name resolution will block. |
address | the address to which to connect |
port | the port to connect to |
EVENT2_EXPORT_SYMBOL void evhttp_connection_free_on_completion | +( | +struct evhttp_connection * | +evcon | ) | ++ |
Disowns a given connection object.
+Can be used to tell libevent to free the connection object after the last request has completed or failed.
+ +EVENT2_EXPORT_SYMBOL const struct sockaddr* evhttp_connection_get_addr | +( | +struct evhttp_connection * | +evcon | ) | ++ |
Get the remote address associated with this connection.
+extracted from getpeername() OR from nameserver.
+EVENT2_EXPORT_SYMBOL void evhttp_connection_set_connect_timeout_tv | +( | +struct evhttp_connection * | +evcon, | +
+ | + | const struct timeval * | +tv | +
+ | ) | ++ |
Sets the connect timeout for this connection.
+tv | the timeout, or NULL |
EVENT2_EXPORT_SYMBOL void evhttp_connection_set_ext_method_cmp | +( | +struct evhttp_connection * | +evcon, | +
+ | + | evhttp_ext_method_cb | +cmp | +
+ | ) | ++ |
Sets extended method cmp callback for this http connection.
+EVENT2_EXPORT_SYMBOL int evhttp_connection_set_flags | +( | +struct evhttp_connection * | +evcon, | +
+ | + | int | +flags | +
+ | ) | ++ |
Set connection flags.
+EVENT2_EXPORT_SYMBOL void evhttp_connection_set_initial_retry_tv | +( | +struct evhttp_connection * | +evcon, | +
+ | + | const struct timeval * | +tv | +
+ | ) | ++ |
Sets the delay before retrying requests on this connection.
+This is only used if evhttp_connection_set_retries is used to make the number of retries at least one. Each retry after the first is twice as long as the one before it.
+Default delay is HTTP_INITIAL_RETRY_TIMEOUT, which is 2 seconds.
+ +EVENT2_EXPORT_SYMBOL void evhttp_connection_set_local_address | +( | +struct evhttp_connection * | +evcon, | +
+ | + | const char * | +address | +
+ | ) | ++ |
Sets the IP address from which http connections are made.
+Note this resets internal bufferevent fd, so any options that had been installed will be flushed.
+ +EVENT2_EXPORT_SYMBOL void evhttp_connection_set_read_timeout_tv | +( | +struct evhttp_connection * | +evcon, | +
+ | + | const struct timeval * | +tv | +
+ | ) | ++ |
Sets the read timeout for this connection.
+tv | the timeout, or NULL |
EVENT2_EXPORT_SYMBOL void evhttp_connection_set_timeout | +( | +struct evhttp_connection * | +evcon, | +
+ | + | int | +timeout | +
+ | ) | ++ |
Sets the timeout for this connection.
+evcon must not be NULL.
+ + +EVENT2_EXPORT_SYMBOL void evhttp_connection_set_timeout_tv | +( | +struct evhttp_connection * | +evcon, | +
+ | + | const struct timeval * | +tv | +
+ | ) | ++ |
Sets the timeout for this connection for the following events:
+But it does not adjust timeout for the "connect" (for historical reasons).
+tv | the timeout, or NULL |
For more precise control:
+ +EVENT2_EXPORT_SYMBOL void evhttp_connection_set_write_timeout_tv | +( | +struct evhttp_connection * | +evcon, | +
+ | + | const struct timeval * | +tv | +
+ | ) | ++ |
Sets the write timeout for this connection.
+tv | the timeout, or NULL |
EVENT2_EXPORT_SYMBOL char* evhttp_decode_uri | +( | +const char * | +uri | ) | ++ |
Helper function to sort of decode a URI-encoded string.
+Unlike evhttp_uridecode, it decodes all plus characters that appear after the first question mark character, but no plusses that occur before. This is not a good way to decode URIs in whole or in part.
+The returned string must be freed by the caller
+uri | an encoded URI |
EVENT2_EXPORT_SYMBOL void evhttp_del_accept_socket | +( | +struct evhttp * | +http, | +
+ | + | struct evhttp_bound_socket * | +bound_socket | +
+ | ) | ++ |
Makes an HTTP server stop accepting connections on the specified socket.
+This may be useful when a socket has been sent via file descriptor passing and is no longer needed by the current process.
+If you created this bound socket with evhttp_bind_socket_with_handle or evhttp_accept_socket_with_handle, this function closes the fd you provided. If you created this bound socket with evhttp_bind_listener, this function frees the listener you provided.
+bound_socket is an invalid pointer after this call returns.
+http | a pointer to an evhttp object |
bound_socket | a handle returned by evhttp_{bind,accept}_socket_with_handle |
EVENT2_EXPORT_SYMBOL char* evhttp_encode_uri | +( | +const char * | +str | ) | ++ |
Helper function to encode a string for inclusion in a URI.
+All characters are replaced by their hex-escaped (%22) equivalents, except for characters explicitly unreserved by RFC3986 – that is, ASCII alphanumeric characters, hyphen, dot, underscore, and tilde.
+The returned string must be freed by the caller.
+str | an unencoded string |
const EVENT2_EXPORT_SYMBOL char* evhttp_find_header | +( | +const struct evkeyvalq * | +headers, | +
+ | + | const char * | +key | +
+ | ) | ++ |
Finds the value belonging to a header.
+headers | the evkeyvalq object in which to find the header |
key | the name of the header to find |
EVENT2_EXPORT_SYMBOL void evhttp_foreach_bound_socket | +( | +struct evhttp * | +http, | +
+ | + | evhttp_bound_socket_foreach_fn * | +function, | +
+ | + | void * | +argument | +
+ | ) | ++ |
Applies the function specified in the first argument to all evhttp_bound_sockets associated with "http".
+The user must not attempt to free or remove any connections, sockets or listeners in the callback "function".
+http | pointer to an evhttp object |
function | function to apply to every bound socket |
argument | pointer value passed to function for every socket iterated |
EVENT2_EXPORT_SYMBOL void evhttp_free | +( | +struct evhttp * | +http | ) | ++ |
Free the previously created HTTP server.
+Works only if no requests are currently being served.
+http | the evhttp server object to be freed. http must not be NULL. |
EVENT2_EXPORT_SYMBOL int evhttp_get_connection_count | +( | +struct evhttp * | +http | ) | ++ |
Get the current number of connections.
+EVENT2_EXPORT_SYMBOL char* evhttp_htmlescape | +( | +const char * | +html | ) | ++ |
Escape HTML character entities in a string.
+Replaces <, >, ", ' and & with <, >, ", ' and & correspondingly.
+The returned string needs to be freed by the caller.
+html | an unescaped HTML string |
EVENT2_EXPORT_SYMBOL int evhttp_make_request | +( | +struct evhttp_connection * | +evcon, | +
+ | + | struct evhttp_request * | +req, | +
+ | + | enum evhttp_cmd_type | +type, | +
+ | + | const char * | +uri | +
+ | ) | ++ |
Make an HTTP request over the specified connection.
+The connection gets ownership of the request. On failure, the request object is no longer valid as it has been freed.
+evcon | the evhttp_connection object over which to send the request |
req | the previously created and configured request object |
type | the request type EVHTTP_REQ_GET, EVHTTP_REQ_POST, etc. |
uri | the URI associated with the request |
EVENT2_EXPORT_SYMBOL struct evhttp* evhttp_new | +( | +struct event_base * | +base | ) | ++ |
Create a new HTTP server.
+base | (optional) the event base to receive the HTTP events |
EVENT2_EXPORT_SYMBOL int evhttp_parse_query | +( | +const char * | +uri, | +
+ | + | struct evkeyvalq * | +headers | +
+ | ) | ++ |
Helper function to parse out arguments in a query.
+Parsing a URI like
+http://foo.com/?q=test&s=some+thing
+will result in two entries in the key value queue.
+The first entry is: key="q", value="test" The second entry is: key="s", value="some thing"
+uri | the request URI |
headers | the head of the evkeyval queue |
EVENT2_EXPORT_SYMBOL int evhttp_parse_query_str | +( | +const char * | +uri, | +
+ | + | struct evkeyvalq * | +headers | +
+ | ) | ++ |
EVENT2_EXPORT_SYMBOL int evhttp_parse_query_str_flags | +( | +const char * | +uri, | +
+ | + | struct evkeyvalq * | +headers, | +
+ | + | unsigned | +flags | +
+ | ) | ++ |
Helper function to parse out arguments from the query portion of an HTTP URI.
+Parsing a query string like
+q=test&s=some+thing
+will result in two entries in the key value queue.
+The first entry is: key="q", value="test" The second entry is: key="s", value="some thing"
+uri | the query portion of the URI |
headers | the head of the evkeyval queue |
flags | one or more of EVHTTP_URI_QUERY_* |
EVENT2_EXPORT_SYMBOL int evhttp_remove_header | +( | +struct evkeyvalq * | +headers, | +
+ | + | const char * | +key | +
+ | ) | ++ |
Removes a header from a list of existing headers.
+headers | the evkeyvalq object from which to remove a header |
key | the name of the header to remove |
EVENT2_EXPORT_SYMBOL int evhttp_remove_server_alias | +( | +struct evhttp * | +http, | +
+ | + | const char * | +alias | +
+ | ) | ++ |
Remove a server alias from an http object.
+http | the evhttp object |
alias | the alias to remove |
EVENT2_EXPORT_SYMBOL int evhttp_remove_virtual_host | +( | +struct evhttp * | +http, | +
+ | + | struct evhttp * | +vhost | +
+ | ) | ++ |
Removes a virtual host from the http server.
+http | the evhttp object from which to remove the virtual host |
vhost | the virtual host to remove from the regular http server. |
EVENT2_EXPORT_SYMBOL struct evhttp_connection* evhttp_request_get_connection | +( | +struct evhttp_request * | +req | ) | ++ |
Returns the connection object associated with the request or NULL.
+req must not be NULL.
+The user needs to either free the request explicitly or call evhttp_send_reply_end().
+ +const EVENT2_EXPORT_SYMBOL char* evhttp_request_get_host | +( | +struct evhttp_request * | +req | ) | ++ |
Returns the host associated with the request.
+If a client sends an absolute URI, the host part of that is preferred. Otherwise, the input headers are searched for a Host: header. NULL is returned if no absolute URI or Host: header is provided.
+ +EVENT2_EXPORT_SYMBOL struct evhttp_request* evhttp_request_new | +( | +void(*)(struct evhttp_request *, void *) | +cb, | +
+ | + | void * | +arg | +
+ | ) | ++ |
Creates a new request object that needs to be filled in with the request parameters.
+The callback is executed when the request completed or an error occurred.
+ +EVENT2_EXPORT_SYMBOL void evhttp_request_own | +( | +struct evhttp_request * | +req | ) | ++ |
Takes ownership of the request object.
+Can be used in a request callback to keep onto the request until evhttp_request_free() is explicitly called by the user.
+ +EVENT2_EXPORT_SYMBOL void evhttp_request_set_chunked_cb | +( | +struct evhttp_request * | +, | +
+ | + | void(*)(struct evhttp_request *, void *) | +cb | +
+ | ) | ++ |
Enable delivery of chunks to requestor.
+cb | will be called after every read of data with the same argument as the completion callback. Will never be called on an empty response. May drain the input buffer; it will be drained automatically on return. |
EVENT2_EXPORT_SYMBOL void evhttp_request_set_error_cb | +( | +struct evhttp_request * | +, | +
+ | + | void(*)(enum evhttp_request_error, void *) | ++ |
+ | ) | ++ |
Set a callback for errors.
+On error, both the error callback and the regular callback will be called, error callback is called before the regular callback.
+ +EVENT2_EXPORT_SYMBOL void evhttp_request_set_header_cb | +( | +struct evhttp_request * | +, | +
+ | + | int(*)(struct evhttp_request *, void *) | +cb | +
+ | ) | ++ |
Register callback for additional parsing of request headers.
+cb | will be called after receiving and parsing the full header. It allows analyzing the header and possibly closing the connection by returning a value < 0. |
EVENT2_EXPORT_SYMBOL void evhttp_request_set_on_complete_cb | +( | +struct evhttp_request * | +req, | +
+ | + | void(*)(struct evhttp_request *, void *) | +cb, | +
+ | + | void * | +cb_arg | +
+ | ) | ++ |
Set a callback to be called on request completion of evhttp_send_* function.
+The callback function will be called on the completion of the request after the output data has been written and before the evhttp_request object is destroyed. This can be useful for tracking resources associated with a request (ex: timing metrics).
+req | a request object |
cb | callback function that will be called on request completion |
cb_arg | an additional context argument for the callback |
EVENT2_EXPORT_SYMBOL void evhttp_send_error | +( | +struct evhttp_request * | +req, | +
+ | + | int | +error, | +
+ | + | const char * | +reason | +
+ | ) | ++ |
Send an HTML error message to the client.
+req | a request object |
error | the HTTP error code |
reason | a brief explanation of the error. If this is NULL, we'll just use the standard meaning of the error code. |
EVENT2_EXPORT_SYMBOL void evhttp_send_reply | +( | +struct evhttp_request * | +req, | +
+ | + | int | +code, | +
+ | + | const char * | +reason, | +
+ | + | struct evbuffer * | +databuf | +
+ | ) | ++ |
Send an HTML reply to the client.
+The body of the reply consists of the data in databuf. After calling evhttp_send_reply() databuf will be empty, but the buffer is still owned by the caller and needs to be deallocated by the caller if necessary.
+req | a request object |
code | the HTTP response code to send |
reason | a brief message to send with the response code |
databuf | the body of the response |
EVENT2_EXPORT_SYMBOL void evhttp_send_reply_chunk | +( | +struct evhttp_request * | +req, | +
+ | + | struct evbuffer * | +databuf | +
+ | ) | ++ |
Send another data chunk as part of an ongoing chunked reply.
+The reply chunk consists of the data in databuf. After calling evhttp_send_reply_chunk() databuf will be empty, but the buffer is still owned by the caller and needs to be deallocated by the caller if necessary.
+req | a request object |
databuf | the data chunk to send as part of the reply. |
EVENT2_EXPORT_SYMBOL void evhttp_send_reply_chunk_with_cb | +( | +struct evhttp_request * | +req, | +
+ | + | struct evbuffer * | +databuf, | +
+ | + | void(*)(struct evhttp_connection *, void *) | +cb, | +
+ | + | void * | +arg | +
+ | ) | ++ |
Send another data chunk as part of an ongoing chunked reply.
+The reply chunk consists of the data in databuf. After calling evhttp_send_reply_chunk() databuf will be empty, but the buffer is still owned by the caller and needs to be deallocated by the caller if necessary.
+req | a request object |
databuf | the data chunk to send as part of the reply. |
cb | callback funcion |
arg | call back's argument. |
EVENT2_EXPORT_SYMBOL void evhttp_send_reply_end | +( | +struct evhttp_request * | +req | ) | ++ |
Complete a chunked reply, freeing the request as appropriate.
+req | a request object |
EVENT2_EXPORT_SYMBOL void evhttp_send_reply_start | +( | +struct evhttp_request * | +req, | +
+ | + | int | +code, | +
+ | + | const char * | +reason | +
+ | ) | ++ |
Initiate a reply that uses Transfer-Encoding chunked.
+This allows the caller to stream the reply back to the client and is useful when either not all of the reply data is immediately available or when sending very large replies.
+The caller needs to supply data chunks with evhttp_send_reply_chunk() and complete the reply by calling evhttp_send_reply_end().
+req | a request object |
code | the HTTP response code to send |
reason | a brief message to send with the response code |
EVENT2_EXPORT_SYMBOL void evhttp_set_allowed_methods | +( | +struct evhttp * | +http, | +
+ | + | ev_uint32_t | +methods | +
+ | ) | ++ |
Sets the what HTTP methods are supported in requests accepted by this server, and passed to user callbacks.
+If not supported they will generate a "405 Method not allowed" response.
+By default this includes the following methods: GET, POST, HEAD, PUT, DELETE
+http | the http server on which to set the methods |
methods | bit mask constructed from evhttp_cmd_type values |
EVENT2_EXPORT_SYMBOL void evhttp_set_bevcb | +( | +struct evhttp * | +http, | +
+ | + | struct bufferevent *(*)(struct event_base *, void *) | +cb, | +
+ | + | void * | +arg | +
+ | ) | ++ |
Set a callback used to create new bufferevents for connections to a given evhttp object.
+cb is not called if a non-NULL bufferevent was supplied by evhttp_bound_set_bevcb.
+You can use this to override the default bufferevent type – for example, to make this evhttp object use SSL bufferevents rather than unencrypted ones.
+New bufferevents must be allocated with no fd set on them.
+http | the evhttp server object for which to set the callback |
cb | the callback to invoke for incoming connections |
arg | an additional context argument for the callback |
EVENT2_EXPORT_SYMBOL int evhttp_set_cb | +( | +struct evhttp * | +http, | +
+ | + | const char * | +path, | +
+ | + | void(*)(struct evhttp_request *, void *) | +cb, | +
+ | + | void * | +cb_arg | +
+ | ) | ++ |
Set a callback for a specified URI.
+http | the http sever on which to set the callback |
path | the path for which to invoke the callback |
cb | the callback function that gets invoked on requesting path |
cb_arg | an additional context argument for the callback |
EVENT2_EXPORT_SYMBOL void evhttp_set_default_content_type | +( | +struct evhttp * | +http, | +
+ | + | const char * | +content_type | +
+ | ) | ++ |
Set the value to use for the Content-Type header when none was provided.
+If the content type string is NULL, the Content-Type header will not be automatically added.
+http | the http server on which to set the default content type |
content_type | the value for the Content-Type header |
EVENT2_EXPORT_SYMBOL void evhttp_set_errorcb | +( | +struct evhttp * | +http, | +
+ | + | int(*)(struct evhttp_request *req, struct evbuffer *buffer, int error, const char *reason, void *cbarg) | +cb, | +
+ | + | void * | +cbarg | +
+ | ) | ++ |
Set a callback to output for any error pages sent for requests of a given evhttp object.
+You can use this to override the default error pages sent, allowing such things as multi-lingual support or customization to match other pages.
+The callback should use the supplied buffer to output the text for an error page. If the callback returns a negative value or doesn't output anything to the buffer, the default error page will be sent instead. The buffer will be automatically be sent when the callback returns, so the callback shouldn't do so itself.
+Microsoft Internet Explorer may display its own error pages if ones sent by an HTTP server are smaller than certain sizes, depending on the status code. To reliably suppress this feature an error page should be at least 512 bytes in size.
+http | the evhttp server object for which to set the callback |
cb | the callback to invoke to format error pages |
arg | an additional context argument for the callback |
EVENT2_EXPORT_SYMBOL void evhttp_set_ext_method_cmp | +( | +struct evhttp * | +http, | +
+ | + | evhttp_ext_method_cb | +cmp | +
+ | ) | ++ |
Sets the callback function which allows HTTP extended methods to be supported by this server.
+The callback should :
evhttp_set_allowed_methods still needs to be called.
+http | the http server on which to add support to the methods |
cmp | the extended method callback |
EVENT2_EXPORT_SYMBOL int evhttp_set_flags | +( | +struct evhttp * | +http, | +
+ | + | int | +flags | +
+ | ) | ++ |
Set connection flags for HTTP server.
+EVENT2_EXPORT_SYMBOL void evhttp_set_gencb | +( | +struct evhttp * | +http, | +
+ | + | void(*)(struct evhttp_request *, void *) | +cb, | +
+ | + | void * | +arg | +
+ | ) | ++ |
Set a callback for all requests that are not caught by specific callbacks.
+Invokes the specified callback for all requests that do not match any of the previously specified request paths. This is catchall for requests not specifically configured with evhttp_set_cb().
+http | the evhttp server object for which to set the callback |
cb | the callback to invoke for any unmatched requests |
arg | an additional context argument for the callback |
EVENT2_EXPORT_SYMBOL void evhttp_set_max_connections | +( | +struct evhttp * | +http, | +
+ | + | int | +max_connections | +
+ | ) | ++ |
Set the maximum number of simultaneous connections for this server.
+A value of zero or less disables the limit.
+http | the http server on which to set the max connection limit |
max_connections | the maximum number of simultaneous connections or 0 |
EVENT2_EXPORT_SYMBOL void evhttp_set_newreqcb | +( | +struct evhttp * | +http, | +
+ | + | int(*)(struct evhttp_request *, void *) | +cb, | +
+ | + | void * | +arg | +
+ | ) | ++ |
Set a callback which allows the user to note or throttle incoming requests.
+The requests are not populated with HTTP level information. They are just associated to a connection.
+If the callback returns -1, the associated connection is terminated and the request is closed.
+http | the evhttp server object for which to set the callback |
cb | the callback to invoke for incoming connections |
arg | an additional context argument for the callback |
EVENT2_EXPORT_SYMBOL void evhttp_set_read_timeout_tv | +( | +struct evhttp * | +http, | +
+ | + | const struct timeval * | +tv | +
+ | ) | ++ |
Set read timeout for an HTTP request.
+http | an evhttp object |
tv | the timeout, or NULL |
EVENT2_EXPORT_SYMBOL void evhttp_set_timeout | +( | +struct evhttp * | +http, | +
+ | + | int | +timeout | +
+ | ) | ++ |
Set the timeout for an HTTP request.
+http | an evhttp object |
timeout | the timeout, in seconds |
EVENT2_EXPORT_SYMBOL void evhttp_set_timeout_tv | +( | +struct evhttp * | +http, | +
+ | + | const struct timeval * | +tv | +
+ | ) | ++ |
Set read and write timeout for an HTTP request.
+http | an evhttp object |
tv | the timeout, or NULL |
For more precise control:
+ +EVENT2_EXPORT_SYMBOL void evhttp_set_write_timeout_tv | +( | +struct evhttp * | +http, | +
+ | + | const struct timeval * | +tv | +
+ | ) | ++ |
Set write timeout for an HTTP request.
+http | an evhttp object |
tv | the timeout, or NULL |
EVENT2_EXPORT_SYMBOL void evhttp_uri_free | +( | +struct evhttp_uri * | +uri | ) | ++ |
Free all memory allocated for a parsed uri.
+Only use this for URIs generated by evhttp_uri_parse.
+uri | container with parsed data. uri must not be NULL. |
const EVENT2_EXPORT_SYMBOL char* evhttp_uri_get_host | +( | +const struct evhttp_uri * | +uri | ) | ++ |
Return the host part of an evhttp_uri, or NULL if it has no host set.
+The host may either be a regular hostname (conforming to the RFC 3986 "regname" production), or an IPv4 address, or the empty string, or a bracketed IPv6 address, or a bracketed 'IP-Future' address.
+Note that having a NULL host means that the URI has no authority section, but having an empty-string host means that the URI has an authority section with no host part. For example, "mailto:user@example.com" has a host of NULL, but "file:///etc/motd" has a host of "".
+ +EVENT2_EXPORT_SYMBOL char* evhttp_uri_join | +( | +const struct evhttp_uri * | +uri, | +
+ | + | char * | +buf, | +
+ | + | size_t | +limit | +
+ | ) | ++ |
Join together the uri parts from parsed data to form a URI-Reference.
+Note that no escaping of reserved characters is done on the members of the evhttp_uri, so the generated string might not be a valid URI unless the members of evhttp_uri are themselves valid.
+uri | container with parsed data |
buf | destination buffer |
limit | destination buffer size |
EVENT2_EXPORT_SYMBOL struct evhttp_uri* evhttp_uri_parse_with_flags | +( | +const char * | +source_uri, | +
+ | + | unsigned | +flags | +
+ | ) | ++ |
Helper function to parse a URI-Reference as specified by RFC3986.
+This function matches the URI-Reference production from RFC3986, which includes both URIs like
+scheme://[[userinfo]@]foo.com[:port]]/[path][?query][#fragment]
+and relative-refs like
+[path][?query][#fragment]
+Any optional elements portions not present in the original URI are left set to NULL in the resulting evhttp_uri. If no port is specified, the port is set to -1.
+Note that no decoding is performed on percent-escaped characters in the string; if you want to parse them, use evhttp_uridecode or evhttp_parse_query_str as appropriate.
+Note also that most URI schemes will have additional constraints that this function does not know about, and cannot check. For example, mailto://www.example.com/cgi-bin/fortune.pl is not a reasonable mailto url, http://www.example.com:99999/ is not a reasonable HTTP URL, and ftp:username@example.com is not a reasonable FTP URL. Nevertheless, all of these URLs conform to RFC3986, and this function accepts all of them as valid.
+source_uri | the request URI |
flags | Zero or more EVHTTP_URI_* flags to affect the behavior of the parser. |
EVENT2_EXPORT_SYMBOL void evhttp_uri_set_flags | +( | +struct evhttp_uri * | +uri, | +
+ | + | unsigned | +flags | +
+ | ) | ++ |
Changes the flags set on a given URI.
+See EVHTTP_URI_* for a list of flags.
+ +EVENT2_EXPORT_SYMBOL int evhttp_uri_set_fragment | +( | +struct evhttp_uri * | +uri, | +
+ | + | const char * | +fragment | +
+ | ) | ++ |
Set the fragment of an evhttp_uri, or clear the fragment if fragment==NULL.
+The fragment should not include a leading "#". Returns 0 on success, -1 if fragment is not well-formed.
+ +EVENT2_EXPORT_SYMBOL int evhttp_uri_set_host | +( | +struct evhttp_uri * | +uri, | +
+ | + | const char * | +host | +
+ | ) | ++ |
Set the host of an evhttp_uri, or clear the host if host==NULL.
+Returns 0 on success, -1 if host is not well-formed.
+ +EVENT2_EXPORT_SYMBOL int evhttp_uri_set_path | +( | +struct evhttp_uri * | +uri, | +
+ | + | const char * | +path | +
+ | ) | ++ |
Set the path of an evhttp_uri, or clear the path if path==NULL.
+Returns 0 on success, -1 if path is not well-formed.
+ +EVENT2_EXPORT_SYMBOL int evhttp_uri_set_port | +( | +struct evhttp_uri * | +uri, | +
+ | + | int | +port | +
+ | ) | ++ |
Set the port of an evhttp_uri, or clear the port if port==-1.
+Returns 0 on success, -1 if port is not well-formed.
+ +EVENT2_EXPORT_SYMBOL int evhttp_uri_set_query | +( | +struct evhttp_uri * | +uri, | +
+ | + | const char * | +query | +
+ | ) | ++ |
Set the query of an evhttp_uri, or clear the query if query==NULL.
+The query should not include a leading "?". Returns 0 on success, -1 if query is not well-formed.
+ +EVENT2_EXPORT_SYMBOL int evhttp_uri_set_scheme | +( | +struct evhttp_uri * | +uri, | +
+ | + | const char * | +scheme | +
+ | ) | ++ |
Set the scheme of an evhttp_uri, or clear the scheme if scheme==NULL.
+Returns 0 on success, -1 if scheme is not well-formed.
+ +EVENT2_EXPORT_SYMBOL int evhttp_uri_set_unixsocket | +( | +struct evhttp_uri * | +uri, | +
+ | + | const char * | +unixsocket | +
+ | ) | ++ |
Set the unix socket of an evhttp_uri, or clear the unix socket if unixsocket==NULL.
+Returns 0 on success, -1 if unixsocket is not well-formed
+ +EVENT2_EXPORT_SYMBOL int evhttp_uri_set_userinfo | +( | +struct evhttp_uri * | +uri, | +
+ | + | const char * | +userinfo | +
+ | ) | ++ |
Set the userinfo of an evhttp_uri, or clear the userinfo if userinfo==NULL.
+Returns 0 on success, -1 if userinfo is not well-formed.
+ +EVENT2_EXPORT_SYMBOL char* evhttp_uridecode | +( | +const char * | +uri, | +
+ | + | int | +decode_plus, | +
+ | + | size_t * | +size_out | +
+ | ) | ++ |
Helper function to decode a URI-escaped string or HTTP parameter.
+If 'decode_plus' is 1, then we decode the string as an HTTP parameter value, and convert all plus ('+') characters to spaces. If 'decode_plus' is 0, we leave all plus characters unchanged.
+The returned string must be freed by the caller.
+uri | a URI-encode encoded URI |
decode_plus | determines whether we convert '+' to space. |
size_out | if size_out is not NULL, *size_out is set to the size of the returned string |
EVENT2_EXPORT_SYMBOL char* evhttp_uriencode | +( | +const char * | +str, | +
+ | + | ev_ssize_t | +size, | +
+ | + | int | +space_to_plus | +
+ | ) | ++ |
As evhttp_encode_uri, but if 'size' is nonnegative, treat the string as being 'size' bytes long.
+This allows you to encode strings that may contain 0-valued bytes.
+The returned string must be freed by the caller.
+str | an unencoded string |
size | the length of the string to encode, or -1 if the string is NUL-terminated |
space_to_plus | if true, space characters in 'str' are encoded as +, not %20. |
+ libevent
+ 2.2.1
+
+ Event notification library
+ |
+
+ libevent
+ 2.2.1
+
+ Event notification library
+ |
+
Potentially non-threadsafe versions of the functions in http.h: provided only for backwards compatibility. +More...
+ +Go to the source code of this file.
++Macros | |
+#define | evhttp_request_uri evhttp_request_get_uri |
Returns the request URI. | |
+Functions | |
EVENT2_EXPORT_SYMBOL struct evhttp_connection * | evhttp_connection_new (const char *address, ev_uint16_t port) |
A connection object that can be used to for making HTTP requests. More... | |
EVENT2_EXPORT_SYMBOL void | evhttp_connection_set_base (struct evhttp_connection *evcon, struct event_base *base) |
Associates an event base with the connection - can only be called on a freshly created connection object that has not been used yet. More... | |
EVENT2_EXPORT_SYMBOL struct evhttp * | evhttp_start (const char *address, ev_uint16_t port) |
Start an HTTP server on the specified address and port. More... | |
Potentially non-threadsafe versions of the functions in http.h: provided only for backwards compatibility.
+EVENT2_EXPORT_SYMBOL struct evhttp_connection* evhttp_connection_new | +( | +const char * | +address, | +
+ | + | ev_uint16_t | +port | +
+ | ) | ++ |
A connection object that can be used to for making HTTP requests.
+The connection object tries to establish the connection when it is given an http request object.
+EVENT2_EXPORT_SYMBOL void evhttp_connection_set_base | +( | +struct evhttp_connection * | +evcon, | +
+ | + | struct event_base * | +base | +
+ | ) | ++ |
Associates an event base with the connection - can only be called on a freshly created connection object that has not been used yet.
+EVENT2_EXPORT_SYMBOL struct evhttp* evhttp_start | +( | +const char * | +address, | +
+ | + | ev_uint16_t | +port | +
+ | ) | ++ |
Start an HTTP server on the specified address and port.
+address | the address to which the HTTP server should be bound |
port | the port number on which the HTTP server should listen |
+ libevent
+ 2.2.1
+
+ Event notification library
+ |
+
+ libevent
+ 2.2.1
+
+ Event notification library
+ |
+
Libevent is an event notification library for developing scalable network servers. The Libevent API provides a mechanism to execute a callback function when a specific event occurs on a file descriptor or after a timeout has been reached. Furthermore, Libevent also support callbacks due to signals or regular timeouts.
+Libevent is meant to replace the event loop found in event driven network servers. An application just needs to call event_base_dispatch() and then add or remove events dynamically without having to change the event loop.
+Currently, Libevent supports /dev/poll, kqueue(2), select(2), poll(2), epoll(4), and evports. The internal event mechanism is completely independent of the exposed event API, and a simple update of Libevent can provide new functionality without having to redesign the applications. As a result, Libevent allows for portable application development and provides the most scalable event notification mechanism available on an operating system. Libevent can also be used for multithreaded programs. Libevent should compile on Linux, *BSD, Mac OS X, Solaris and, Windows.
+Every program that uses Libevent must include the <event2/event.h> header, and pass the -levent flag to the linker. (You can instead link -levent_core if you only want the main event and buffered IO-based code, and don't want to link any protocol code.)
+Before you call any other Libevent functions, you need to set up the library. If you're going to use Libevent from multiple threads in a multithreaded application, you need to initialize thread support – typically by using evthread_use_pthreads() or evthread_use_windows_threads(). See <event2/thread.h> for more information.
+This is also the point where you can replace Libevent's memory management functions with event_set_mem_functions, and enable debug mode with event_enable_debug_mode().
+Next, you need to create an event_base structure, using event_base_new() or event_base_new_with_config(). The event_base is responsible for keeping track of which events are "pending" (that is to say, being watched to see if they become active) and which events are "active". Every event is associated with a single event_base.
+For each file descriptor that you wish to monitor, you must create an event structure with event_new(). (You may also declare an event structure and call event_assign() to initialize the members of the structure.) To enable notification, you add the structure to the list of monitored events by calling event_add(). The event structure must remain allocated as long as it is active, so it should generally be allocated on the heap.
+Finally, you call event_base_dispatch() to loop and dispatch events. You can also use event_base_loop() for more fine-grained control.
+Currently, only one thread can be dispatching a given event_base at a time. If you want to run events in multiple threads at once, you can either have a single event_base whose events add work to a work queue, or you can create multiple event_base objects.
+Libevent provides a buffered I/O abstraction on top of the regular event callbacks. This abstraction is called a bufferevent. A bufferevent provides input and output buffers that get filled and drained automatically. The user of a buffered event no longer deals directly with the I/O, but instead is reading from input and writing to output buffers.
+Once initialized via bufferevent_socket_new(), the bufferevent structure can be used repeatedly with bufferevent_enable() and bufferevent_disable(). Instead of reading and writing directly to a socket, you would call bufferevent_read() and bufferevent_write().
+When read enabled the bufferevent will try to read from the file descriptor and call the read callback. The write callback is executed whenever the output buffer is drained below the write low watermark, which is 0 by default.
+See <event2/bufferevent*.h> for more information.
+Libevent can also be used to create timers that invoke a callback after a certain amount of time has expired. The evtimer_new() macro returns an event struct to use as a timer. To activate the timer, call evtimer_add(). Timers can be deactivated by calling evtimer_del(). (These macros are thin wrappers around event_new(), event_add(), and event_del(); you can also use those instead.)
+Libevent provides an asynchronous DNS resolver that should be used instead of the standard DNS resolver functions. See the <event2/dns.h> functions for more detail.
+Libevent provides a very simple event-driven HTTP server that can be embedded in your program and used to service HTTP requests.
+To use this capability, you need to include the <event2/http.h> header in your program. See that header for more information.
+Libevent provides a framework for creating RPC servers and clients. It takes care of marshaling and unmarshaling all data structures.
+To browse the complete documentation of the libevent API, click on any of the following links.
+event2/event.h The primary libevent header
+event2/thread.h Functions for use by multithreaded programs
+event2/buffer.h and event2/bufferevent.h Buffer management for network reading and writing
+event2/util.h Utility functions for portable nonblocking network code
+event2/dns.h Asynchronous DNS resolution
+event2/http.h An embedded libevent-based HTTP server
+event2/rpc.h A framework for creating RPC servers and clients
+event2/watch.h "Prepare" and "check" watchers.
+
+ libevent
+ 2.2.1
+
+ Event notification library
+ |
+
A callback that we invoke when a listener has a new connection. +More...
+ +Go to the source code of this file.
++Macros | |
#define | LEV_OPT_BIND_IPV4_AND_IPV6 (1u<<9) |
Flag: Indicates that the listener wants to work only in both IPv4 and IPv6 socket. More... | |
#define | LEV_OPT_BIND_IPV6ONLY (1u<<8) |
Flag: Indicates that the listener wants to work only in IPv6 socket. More... | |
+#define | LEV_OPT_CLOSE_ON_EXEC (1u<<2) |
Flag: Indicates that we should set the close-on-exec flag, if possible. | |
+#define | LEV_OPT_CLOSE_ON_FREE (1u<<1) |
Flag: Indicates that freeing the listener should close the underlying socket. | |
#define | LEV_OPT_DEFERRED_ACCEPT (1u<<6) |
Flag: Indicates that the listener should defer accept() until data is available, if possible. More... | |
#define | LEV_OPT_DISABLED (1u<<5) |
Flag: Indicates that the listener should be created in disabled state. More... | |
+#define | LEV_OPT_LEAVE_SOCKETS_BLOCKING (1u<<0) |
Flag: Indicates that we should not make incoming sockets nonblocking before passing them to the callback. | |
+#define | LEV_OPT_REUSEABLE (1u<<3) |
Flag: Indicates that we should disable the timeout (if any) between when this socket is closed and when we can listen again on the same port. | |
#define | LEV_OPT_REUSEABLE_PORT (1u<<7) |
Flag: Indicates that we ask to allow multiple servers (processes or threads) to bind to the same port if they each set the option for incoming connections/datagrams to be distributed evenly across all of the threads (or processes). More... | |
+#define | LEV_OPT_THREADSAFE (1u<<4) |
Flag: Indicates that the listener should be locked so it's safe to use from multiple threadcs at once. | |
+Typedefs | |
+typedef void(* | evconnlistener_cb) (struct evconnlistener *, evutil_socket_t, struct sockaddr *, int socklen, void *) |
typedef void(* | evconnlistener_errorcb) (struct evconnlistener *, void *) |
A callback that we invoke when a listener encounters a non-retriable error. More... | |
+Functions | |
+EVENT2_EXPORT_SYMBOL int | evconnlistener_disable (struct evconnlistener *lev) |
Stop listening for connections on an evconnlistener. | |
+EVENT2_EXPORT_SYMBOL int | evconnlistener_enable (struct evconnlistener *lev) |
Re-enable an evconnlistener that has been disabled. | |
+EVENT2_EXPORT_SYMBOL void | evconnlistener_free (struct evconnlistener *lev) |
Disable and deallocate an evconnlistener. | |
+EVENT2_EXPORT_SYMBOL struct event_base * | evconnlistener_get_base (struct evconnlistener *lev) |
Return an evconnlistener's associated event_base. | |
+EVENT2_EXPORT_SYMBOL evutil_socket_t | evconnlistener_get_fd (struct evconnlistener *lev) |
Return the socket that an evconnlistner is listening on. | |
EVENT2_EXPORT_SYMBOL struct evconnlistener * | evconnlistener_new (struct event_base *base, evconnlistener_cb cb, void *ptr, unsigned flags, int backlog, evutil_socket_t fd) |
Allocate a new evconnlistener object to listen for incoming TCP connections on a given file descriptor. More... | |
EVENT2_EXPORT_SYMBOL struct evconnlistener * | evconnlistener_new_bind (struct event_base *base, evconnlistener_cb cb, void *ptr, unsigned flags, int backlog, const struct sockaddr *sa, int socklen) |
Allocate a new evconnlistener object to listen for incoming TCP connections on a given address. More... | |
+EVENT2_EXPORT_SYMBOL void | evconnlistener_set_cb (struct evconnlistener *lev, evconnlistener_cb cb, void *arg) |
Change the callback on the listener to cb and its user_data to arg. | |
+EVENT2_EXPORT_SYMBOL void | evconnlistener_set_error_cb (struct evconnlistener *lev, evconnlistener_errorcb errorcb) |
Set an evconnlistener's error callback. | |
A callback that we invoke when a listener has a new connection.
+listener | The evconnlistener |
fd | The new file descriptor |
addr | The source address of the connection |
socklen | The length of addr |
user_arg | the pointer passed to evconnlistener_new() |
#define LEV_OPT_BIND_IPV4_AND_IPV6 (1u<<9) | +
Flag: Indicates that the listener wants to work only in both IPv4 and IPv6 socket.
+This flag exists as complement to LEV_OPT_BIND_IPV6ONLY to account for the different default behaviour on Windows so that the code can explicitly request the socket to support both modes without having to rely on the default option.
+ +#define LEV_OPT_BIND_IPV6ONLY (1u<<8) | +
Flag: Indicates that the listener wants to work only in IPv6 socket.
+According to RFC3493 and most Linux distributions, default value is to work in IPv4-mapped mode. If there is a requirement to bind same port on same ip addresses but different handlers for both IPv4 and IPv6, it is required to set IPV6_V6ONLY socket option to be sure that the code works as expected without affected by bindv6only sysctl setting in system.
+This socket option on Windows is instead enabled by default.
+ +#define LEV_OPT_DEFERRED_ACCEPT (1u<<6) | +
Flag: Indicates that the listener should defer accept() until data is available, if possible.
+Ignored on platforms that do not support this.
+This option can help performance for protocols where the client transmits immediately after connecting. Do not use this option if your protocol doesn't start out with the client transmitting data, since in that case this option will sometimes cause the kernel to never tell you about the connection.
+This option is only supported by evconnlistener_new_bind(): it can't work with evconnlistener_new_fd(), since the listener needs to be told to use the option before it is actually bound.
+ +#define LEV_OPT_DISABLED (1u<<5) | +
Flag: Indicates that the listener should be created in disabled state.
+Use evconnlistener_enable() to enable it later.
+ +#define LEV_OPT_REUSEABLE_PORT (1u<<7) | +
Flag: Indicates that we ask to allow multiple servers (processes or threads) to bind to the same port if they each set the option for incoming connections/datagrams to be distributed evenly across all of the threads (or processes).
+SO_REUSEPORT is what most people would expect SO_REUSEADDR to be, however SO_REUSEPORT does not imply SO_REUSEADDR.
+This feature is available only on Linux 3.9+, DragonFlyBSD 3.6+, FreeBSD 12.0+, Solaris 11.4, AIX 7.2.5 for now.
+ +typedef void(* evconnlistener_errorcb) (struct evconnlistener *, void *) | +
A callback that we invoke when a listener encounters a non-retriable error.
+listener | The evconnlistener |
user_arg | the pointer passed to evconnlistener_new() |
EVENT2_EXPORT_SYMBOL struct evconnlistener* evconnlistener_new | +( | +struct event_base * | +base, | +
+ | + | evconnlistener_cb | +cb, | +
+ | + | void * | +ptr, | +
+ | + | unsigned | +flags, | +
+ | + | int | +backlog, | +
+ | + | evutil_socket_t | +fd | +
+ | ) | ++ |
Allocate a new evconnlistener object to listen for incoming TCP connections on a given file descriptor.
+base | The event base to associate the listener with. |
cb | A callback to be invoked when a new connection arrives. If the callback is NULL, the listener will be treated as disabled until the callback is set. |
ptr | A user-supplied pointer to give to the callback. |
flags | Any number of LEV_OPT_* flags |
backlog | Passed to the listen() call to determine the length of the acceptable connection backlog. Set to -1 for a reasonable default. Set to 0 if the socket is already listening. |
fd | The file descriptor to listen on. It must be a nonblocking file descriptor, and it should already be bound to an appropriate port and address. |
EVENT2_EXPORT_SYMBOL struct evconnlistener* evconnlistener_new_bind | +( | +struct event_base * | +base, | +
+ | + | evconnlistener_cb | +cb, | +
+ | + | void * | +ptr, | +
+ | + | unsigned | +flags, | +
+ | + | int | +backlog, | +
+ | + | const struct sockaddr * | +sa, | +
+ | + | int | +socklen | +
+ | ) | ++ |
Allocate a new evconnlistener object to listen for incoming TCP connections on a given address.
+base | The event base to associate the listener with. |
cb | A callback to be invoked when a new connection arrives. If the callback is NULL, the listener will be treated as disabled until the callback is set. |
ptr | A user-supplied pointer to give to the callback. |
flags | Any number of LEV_OPT_* flags |
backlog | Passed to the listen() call to determine the length of the acceptable connection backlog. Set to -1 for a reasonable default. |
sa | The address to listen for connections on. |
socklen | The length of the address. |