#include <event-config.h>
#include <sys/types.h>
#include <sys/time.h>
#include <stdint.h>
#include <stdarg.h>
#include <evutil.h>
Go to the source code of this file.
Data Structures | |
struct | bufferevent |
struct | evbuffer |
struct | event |
struct | event_watermark |
struct | evkeyval |
Defines | |
#define | _EVENT_LOG_DEBUG 0 |
#define | _EVENT_LOG_ERR 3 |
#define | _EVENT_LOG_MSG 1 |
#define | _EVENT_LOG_WARN 2 |
#define | EV_PERSIST 0x10 |
#define | EV_READ 0x02 |
#define | EV_SIGNAL 0x08 |
#define | EV_TIMEOUT 0x01 |
#define | EV_WRITE 0x04 |
#define | EVBUFFER_DATA(x) (x)->buffer |
#define | EVBUFFER_EOF 0x10 |
#define | EVBUFFER_ERROR 0x20 |
#define | EVBUFFER_INPUT(x) (x)->input |
#define | EVBUFFER_LENGTH(x) (x)->off |
#define | EVBUFFER_OUTPUT(x) (x)->output |
#define | EVBUFFER_READ 0x01 |
#define | EVBUFFER_TIMEOUT 0x40 |
#define | EVBUFFER_WRITE 0x02 |
#define | EVENT_FD(ev) (int)(ev)->ev_fd |
#define | event_initialized(ev) ((ev)->ev_flags & EVLIST_INIT) |
Test if an event structure has been initialized. | |
#define | EVENT_SIGNAL(ev) (int)(ev)->ev_fd |
#define | EVLIST_ACTIVE 0x08 |
#define | EVLIST_ALL (0xf000 | 0x9f) |
#define | EVLIST_INIT 0x80 |
#define | EVLIST_INSERTED 0x02 |
#define | EVLIST_INTERNAL 0x10 |
#define | EVLIST_SIGNAL 0x04 |
#define | EVLIST_TIMEOUT 0x01 |
#define | evtimer_add(ev, tv) event_add(ev, tv) |
Add a timer event. | |
#define | evtimer_del(ev) event_del(ev) |
Delete a timer event. | |
#define | evtimer_initialized(ev) ((ev)->ev_flags & EVLIST_INIT) |
#define | evtimer_pending(ev, tv) event_pending(ev, EV_TIMEOUT, tv) |
#define | evtimer_set(ev, cb, arg) event_set(ev, -1, 0, cb, arg) |
Define a timer event. | |
#define | signal_add(ev, tv) event_add(ev, tv) |
#define | signal_del(ev) event_del(ev) |
#define | signal_initialized(ev) ((ev)->ev_flags & EVLIST_INIT) |
#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) |
#define | timeout_add(ev, tv) event_add(ev, tv) |
Add a timeout event. | |
#define | timeout_del(ev) event_del(ev) |
Disable a timeout event. | |
#define | timeout_initialized(ev) ((ev)->ev_flags & EVLIST_INIT) |
#define | timeout_pending(ev, tv) event_pending(ev, EV_TIMEOUT, tv) |
#define | timeout_set(ev, cb, arg) event_set(ev, -1, 0, cb, arg) |
Define a timeout event. | |
Typedefs | |
typedef void(* | evbuffercb )(struct bufferevent *, void *) |
typedef void(* | event_log_cb )(int severity, const char *msg) |
typedef void(* | everrorcb )(struct bufferevent *, short what, void *) |
Enumerations | |
enum | evbuffer_eol_style { EVBUFFER_EOL_ANY, EVBUFFER_EOL_CRLF, EVBUFFER_EOL_CRLF_STRICT, EVBUFFER_EOL_LF } |
Used to tell evbuffer_readln what kind of line-ending to look for. More... | |
Functions | |
int | bufferevent_base_set (struct event_base *base, struct bufferevent *bufev) |
Assign a bufferevent to a specific event_base. | |
int | bufferevent_disable (struct bufferevent *bufev, short event) |
Disable a bufferevent. | |
int | bufferevent_enable (struct bufferevent *bufev, short event) |
Enable a bufferevent. | |
void | bufferevent_free (struct bufferevent *bufev) |
Deallocate the storage associated with a bufferevent structure. | |
bufferevent * | bufferevent_new (int fd, evbuffercb readcb, evbuffercb writecb, everrorcb errorcb, void *cbarg) |
Create a new bufferevent. | |
int | bufferevent_priority_set (struct bufferevent *bufev, int pri) |
Assign a priority to a bufferevent. | |
size_t | bufferevent_read (struct bufferevent *bufev, void *data, size_t size) |
Read data from a bufferevent buffer. | |
void | bufferevent_setcb (struct bufferevent *bufev, evbuffercb readcb, evbuffercb writecb, everrorcb errorcb, void *cbarg) |
Changes the callbacks for a bufferevent. | |
void | bufferevent_setfd (struct bufferevent *bufev, int fd) |
Changes the file descriptor on which the bufferevent operates. | |
void | bufferevent_settimeout (struct bufferevent *bufev, int timeout_read, int timeout_write) |
Set the read and write timeout for a buffered event. | |
void | bufferevent_setwatermark (struct bufferevent *bufev, short events, size_t lowmark, size_t highmark) |
Sets the watermarks for read and write events. | |
int | bufferevent_write (struct bufferevent *bufev, const void *data, size_t size) |
Write data to a bufferevent buffer. | |
int | bufferevent_write_buffer (struct bufferevent *bufev, struct evbuffer *buf) |
Write data from an evbuffer to a bufferevent buffer. | |
void | encode_int (struct evbuffer *evbuf, ev_uint32_t number) |
Encode an integer and store it in an evbuffer. | |
int | evbuffer_add (struct evbuffer *, const void *, size_t) |
Append data to the end of an evbuffer. | |
int | evbuffer_add_buffer (struct evbuffer *, struct evbuffer *) |
Move data from one evbuffer into another evbuffer. | |
int | evbuffer_add_printf (struct evbuffer *, const char *fmt,...) |
Append a formatted string to the end of an evbuffer. | |
int | evbuffer_add_vprintf (struct evbuffer *, const char *fmt, va_list ap) |
Append a va_list formatted string to the end of an evbuffer. | |
void | evbuffer_drain (struct evbuffer *, size_t) |
Remove a specified number of bytes data from the beginning of an evbuffer. | |
int | evbuffer_expand (struct evbuffer *, size_t) |
Expands the available space in an event buffer. | |
u_char * | evbuffer_find (struct evbuffer *, const u_char *, size_t) |
Find a string within an evbuffer. | |
void | evbuffer_free (struct evbuffer *) |
Deallocate storage for an evbuffer. | |
evbuffer * | evbuffer_new (void) |
Allocate storage for a new evbuffer. | |
int | evbuffer_read (struct evbuffer *, int, int) |
Read from a file descriptor and store the result in an evbuffer. | |
char * | evbuffer_readline (struct evbuffer *) |
Read a single line from an event buffer. | |
char * | evbuffer_readln (struct evbuffer *buffer, size_t *n_read_out, enum evbuffer_eol_style eol_style) |
Read a single line from an event buffer. | |
int | evbuffer_remove (struct evbuffer *, void *, size_t) |
Read data from an event buffer and drain the bytes read. | |
void | evbuffer_setcb (struct evbuffer *, void(*)(struct evbuffer *, size_t, size_t, void *), void *) |
Set a callback to invoke when the evbuffer is modified. | |
int | evbuffer_write (struct evbuffer *, int) |
Write the contents of an evbuffer to a file descriptor. | |
void | event_active (struct event *, int, short) |
int | event_add (struct event *ev, const struct timeval *timeout) |
Add an event to the set of monitored events. | |
int | event_base_dispatch (struct event_base *) |
Threadsafe event dispatching loop. | |
void | event_base_free (struct event_base *) |
Deallocate all memory associated with an event_base, and free the base. | |
const char * | event_base_get_method (struct event_base *) |
Get the kernel event notification mechanism used by libevent. | |
int | event_base_loop (struct event_base *, int) |
Handle events (threadsafe version). | |
int | event_base_loopbreak (struct event_base *) |
Abort the active event_base_loop() immediately. | |
int | event_base_loopexit (struct event_base *, const struct timeval *) |
Exit the event loop after the specified time (threadsafe variant). | |
event_base * | event_base_new (void) |
Initialize the event API. | |
int | event_base_once (struct event_base *base, int fd, short events, void(*callback)(int, short, void *), void *arg, const struct timeval *timeout) |
Schedule a one-time event (threadsafe variant). | |
int | event_base_priority_init (struct event_base *, int) |
Set the number of different event priorities (threadsafe variant). | |
int | event_base_set (struct event_base *, struct event *) |
Associate a different event base with an event. | |
int | event_del (struct event *) |
Remove an event from the set of monitored events. | |
int | event_dispatch (void) |
Loop to process events. | |
const char * | event_get_method (void) |
Get the kernel event notification mechanism used by libevent. | |
const char * | event_get_version (void) |
Get the libevent version number. | |
event_base * | event_init (void) |
Initialize the event API. | |
int | event_loop (int) |
Handle events. | |
int | event_loopbreak (void) |
Abort the active event_loop() immediately. | |
int | event_loopexit (const struct timeval *) |
Exit the event loop after the specified time. | |
int | event_once (int, short, void(*)(int, short, void *), void *, const struct timeval *) |
Schedule a one-time event to occur. | |
int | event_pending (struct event *ev, short event, struct timeval *tv) |
Checks if a specific event is pending or scheduled. | |
int | event_priority_init (int) |
Set the number of different event priorities. | |
int | event_priority_set (struct event *, int) |
Assign a priority to an event. | |
int | event_reinit (struct event_base *base) |
Reinitialized the event base after a fork. | |
void | event_set (struct event *, int, short, void(*)(int, short, void *), void *) |
Prepare an event structure to be added. | |
void | event_set_log_callback (event_log_cb cb) |
Redirect libevent's log messages. | |
int | evtag_consume (struct evbuffer *evbuf) |
void | evtag_init (void) |
void | evtag_marshal (struct evbuffer *evbuf, ev_uint32_t tag, const void *data, ev_uint32_t len) |
void | evtag_marshal_int (struct evbuffer *evbuf, ev_uint32_t tag, ev_uint32_t integer) |
void | evtag_marshal_string (struct evbuffer *buf, ev_uint32_t tag, const char *string) |
void | evtag_marshal_timeval (struct evbuffer *evbuf, ev_uint32_t tag, struct timeval *tv) |
int | evtag_payload_length (struct evbuffer *evbuf, ev_uint32_t *plength) |
int | evtag_peek (struct evbuffer *evbuf, ev_uint32_t *ptag) |
int | evtag_peek_length (struct evbuffer *evbuf, ev_uint32_t *plength) |
int | evtag_unmarshal (struct evbuffer *src, ev_uint32_t *ptag, struct evbuffer *dst) |
int | evtag_unmarshal_fixed (struct evbuffer *src, ev_uint32_t need_tag, void *data, size_t len) |
int | evtag_unmarshal_int (struct evbuffer *evbuf, ev_uint32_t need_tag, ev_uint32_t *pinteger) |
int | evtag_unmarshal_string (struct evbuffer *evbuf, ev_uint32_t need_tag, char **pstring) |
int | evtag_unmarshal_timeval (struct evbuffer *evbuf, ev_uint32_t need_tag, struct timeval *ptv) |
|
Test if an event structure has been initialized. The event_initialized() macro can be used to check if an event has been initialized.
|
|
Add a timer event.
|
|
Delete a timer event.
|
|
Define a timer event.
|
|
Add a timeout event.
|
|
Disable a timeout event.
|
|
Define a timeout event.
|
|
|
Assign a bufferevent to a specific event_base.
|
|
Disable a bufferevent.
|
|
Enable a bufferevent.
|
|
Deallocate the storage associated with a bufferevent structure.
|
|
Create a new bufferevent. 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.
|
|
Assign a priority to a bufferevent.
|
|
Read data from a bufferevent buffer. The bufferevent_read() function is used to read data from the input buffer.
|
|
Changes the callbacks for a bufferevent.
|
|
Changes the file descriptor on which the bufferevent operates.
|
|
Set the read and write timeout for a buffered event.
|
|
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 buffevent stops reading from the network. On output, the user write callback is invoked whenever the buffered data falls below the low watermark.
|
|
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.
|
|
Write data from an evbuffer to a bufferevent buffer. The evbuffer is being drained as a result.
|
|
Encode an integer and store it in an evbuffer. We encode integer's by nibbles; the first nibble contains the number of significant nibbles - 1; this allows us to encode up to 64-bit integers. This function is byte-order independent.
|
|
Append data to the end of an evbuffer.
|
|
Move data from one evbuffer into another evbuffer. This is a destructive add. The data from one buffer moves into the other buffer. The destination buffer is expanded as needed.
|
|
Append a formatted string to the end of an evbuffer.
|
|
Append a va_list formatted string to the end of an evbuffer.
|
|
Remove a specified number of bytes data from the beginning of an evbuffer.
|
|
Expands the available space in an event buffer. Expands the available space in the event buffer to at least datlen
|
|
Find a string within an evbuffer.
|
|
Deallocate storage for an evbuffer.
|
|
Allocate storage for a new evbuffer.
|
|
Read from a file descriptor and store the result in an evbuffer.
|
|
Read a single line from an event buffer.
Reads a line terminated by either '
|
|
Read a single line from an event buffer. 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.
|
|
Read data from an event buffer and drain the bytes read.
|
|
Set a callback to invoke when the evbuffer is modified.
|
|
Write the contents of an evbuffer to a file descriptor. The evbuffer will be drained after the bytes have been successfully written.
|
|
Add an event to the set of monitored events. The function event_add() schedules the execution of the ev event when the event specified in event_set() occurs or in at least the time specified in the tv. If tv is NULL, no timeout occurs and the function will only be called if a matching event occurs on the file descriptor. The event in the ev argument must be already initialized by event_set() and may not be used in calls to event_set() until it has timed out or been removed with event_del(). If the event in the ev argument already has a scheduled timeout, the old timeout will be replaced by the new one.
|
|
Threadsafe event dispatching loop.
|
|
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_set as the argument to callback.
|
|
Get the kernel event notification mechanism used by libevent.
|
|
Handle events (threadsafe version). This is a more flexible version of event_base_dispatch().
|
|
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_loop() will proceed normally.
|
|
Exit the event loop after the specified time (threadsafe variant). 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.
|
|
Initialize the event API. Use event_base_new() to initialize a new event base, but does not set the current_base global. If using only event_base_new(), each event added must have an event base set with event_base_set()
|
|
Schedule a one-time event (threadsafe variant). The function event_base_once() is similar to event_set(). However, it schedules a callback to be called exactly once and does not require the caller to prepare an event structure.
|
|
Set the number of different event priorities (threadsafe variant). See the description of event_priority_init() for more information.
|
|
Associate a different event base with an event.
|
|
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.
|
|
Loop to process events. In order to process events, an application needs to call event_dispatch(). This function only returns on error, and should replace the event core of the application program.
|
|
Get the kernel event notification mechanism used by libevent.
|
|
Get the libevent version number.
|
|
Initialize the event API. The event API needs to be initialized with event_init() before it can be used. Sets the current_base global representing the default base for events that have no base associated with them.
|
|
Handle events. This is a more flexible version of event_dispatch().
|
|
Abort the active event_loop() immediately. event_loop() will abort the loop after the next event is completed; event_loopbreak() is typically invoked from this event's callback. This behavior is analogous to the "break;" statement. Subsequent invocations of event_loop() will proceed normally.
|
|
Exit the event loop after the specified time. The next event_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_loop() will proceed normally.
|
|
Schedule a one-time event to occur. The function event_once() is similar to event_set(). However, it schedules a callback to be called exactly once and does not require the caller to prepare an event structure.
|
|
Checks if a specific event is pending or scheduled.
|
|
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_priority_init() function. This function should be called before the first call to event_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.
|
|
Assign a priority to an event.
|
|
Reinitialized 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.
|
|
Prepare an event structure to be added. The function event_set() prepares the event structure ev to be used in future calls to event_add() and event_del(). The event will be prepared to call the function specified by the fn argument with an int argument indicating the file descriptor, a short argument indicating the type of event, and a void * argument given in the arg argument. The fd indicates the file descriptor that should be monitored for events. The events can be either EV_READ, EV_WRITE, or both. Indicating that an application can read or write from the file descriptor respectively without blocking. The function fn will be called with the file descriptor that triggered the event and the type of event which will be either EV_TIMEOUT, EV_SIGNAL, EV_READ, or EV_WRITE. The additional flag EV_PERSIST makes an event_add() persistent until event_del() has been called.
|
|
Redirect libevent's log messages.
|