#include <stdarg.h>
Go to the source code of this file.
Data Structures | |
| struct | bufferevent |
| struct | evbuffer |
| struct | event |
| struct | event_watermark |
| struct | eventop |
| 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 | EVLOOP_NONBLOCK 0x02 |
| A flag for event_loop() to indicate . | |
| #define | EVLOOP_ONCE 0x01 |
| A flag for event_loop() to indicate . | |
| #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_DEFAULT {5, 0} |
| #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 *) |
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_settimeout (struct bufferevent *bufev, int timeout_read, int timeout_write) |
| Set the read and write timeout for a buffered event. | |
| int | bufferevent_write (struct bufferevent *bufev, 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, u_int32_t number) |
| Encode an integer and store it in an evbuffer. | |
| int | evbuffer_add (struct evbuffer *buf, const void *data, size_t datlen) |
| Append data to the end of an evbuffer. | |
| int | evbuffer_add_buffer (struct evbuffer *outbuf, struct evbuffer *inbuf) |
| Move data from one evbuffer into another evbuffer. | |
| int | evbuffer_add_printf (struct evbuffer *buf, 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 *buf, size_t len) |
| Remove a specified number of bytes data from the beginning of an evbuffer. | |
| int | evbuffer_expand (struct evbuffer *buf, size_t datlen) |
| Expands the available space in an event buffer. | |
| u_char * | evbuffer_find (struct evbuffer *buffer, const u_char *what, size_t len) |
| Find a string within an evbuffer. | |
| void | evbuffer_free (struct evbuffer *buffer) |
| Deallocate storage for an evbuffer. | |
| evbuffer * | evbuffer_new (void) |
| Allocate storage for a new evbuffer. | |
| int | evbuffer_read (struct evbuffer *buf, int fd, int howmuch) |
| 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. | |
| int | evbuffer_remove (struct evbuffer *buf, void *data, size_t datlen) |
| Read data from an event buffer and drain the bytes read. | |
| void | evbuffer_setcb (struct evbuffer *buffer, void(*cb)(struct evbuffer *, size_t, size_t, void *), void *cbarg) |
| Set a callback to invoke when the evbuffer is modified. | |
| int | evbuffer_write (struct evbuffer *buffer, int fd) |
| Write the contents of an evbuffer to a file descriptor. | |
| void | event_active (struct event *, int, short) |
| int | event_add (struct event *ev, struct timeval *tv) |
| 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 *eb) |
| Deallocate all memory associated with an event_base. | |
| int | event_base_loop (struct event_base *eb, int flags) |
| Execute a single event (threadsafe variant). | |
| int | event_base_loopexit (struct event_base *eb, struct timeval *tv) |
| Execute a single event, with a timeout (threadsafe variant). | |
| int | event_base_once (struct event_base *base, int fd, short events, void(*callback)(int, short, void *), void *arg, struct timeval *tv) |
| Schedule a one-time event (threadsafe variant). | |
| int | event_base_priority_init (struct event_base *eb, int npriorities) |
| Set the number of different event priorities (threadsafe variant). | |
| int | event_base_set (struct event_base *eb, struct event *ev) |
| Associate a different event base with an event. | |
| int | event_del (struct event *ev) |
| 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. | |
| void * | event_init (void) |
| Initialize the event API. | |
| int | event_loop (int flags) |
| Execute a single event. | |
| int | event_loopexit (struct timeval *tv) |
| Execute a single event, with a timeout. | |
| int | event_once (int fd, short events, void(*callback)(int, short, void *), void *arg, struct timeval *tv) |
| 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 npriorities) |
| Set the number of different event priorities. | |
| int | event_priority_set (struct event *ev, int priority) |
| Assign a priority to an event. | |
| 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) |
| int | evtag_consume (struct evbuffer *evbuf) |
| void | evtag_init (void) |
| void | evtag_marshal (struct evbuffer *evbuf, u_int8_t tag, const void *data, u_int32_t len) |
| void | evtag_marshal_int (struct evbuffer *evbuf, u_int8_t tag, u_int32_t integer) |
| void | evtag_marshal_string (struct evbuffer *buf, u_int8_t tag, const char *string) |
| void | evtag_marshal_timeval (struct evbuffer *evbuf, u_int8_t tag, struct timeval *tv) |
| int | evtag_payload_length (struct evbuffer *evbuf, u_int32_t *plength) |
| int | evtag_peek (struct evbuffer *evbuf, u_int8_t *ptag) |
| int | evtag_peek_length (struct evbuffer *evbuf, u_int32_t *plength) |
| void | evtag_test (void) |
| int | evtag_unmarshal (struct evbuffer *src, u_int8_t *ptag, struct evbuffer *dst) |
| int | evtag_unmarshal_fixed (struct evbuffer *src, u_int8_t need_tag, void *data, size_t len) |
| int | evtag_unmarshal_int (struct evbuffer *evbuf, u_int8_t need_tag, u_int32_t *pinteger) |
| int | evtag_unmarshal_string (struct evbuffer *evbuf, u_int8_t need_tag, char **pstring) |
| int | evtag_unmarshal_timeval (struct evbuffer *evbuf, u_int8_t need_tag, struct timeval *ptv) |
| #define event_initialized | ( | ev | ) | ((ev)->ev_flags & EVLIST_INIT) |
Test if an event structure has been initialized.
The event_initialized() macro can be used to check if an event has been initialized.
| ev | an event structure to be tested |
| #define EVLOOP_NONBLOCK 0x02 |
A flag for event_loop() to indicate .
.. (FIXME)
| #define EVLOOP_ONCE 0x01 |
A flag for event_loop() to indicate .
.. (FIXME)
| #define evtimer_add | ( | ev, | |||
| tv | ) | event_add(ev, tv) |
Add a timer event.
| ev | the event struct | |
| tv | timeval struct |
| #define evtimer_del | ( | ev | ) | event_del(ev) |
Delete a timer event.
| ev | the event struct to be disabled |
| #define evtimer_set | ( | ev, | |||
| cb, | |||||
| arg | ) | event_set(ev, -1, 0, cb, arg) |
Define a timer event.
| ev | event struct to be modified | |
| cb | callback function | |
| arg | argument that will be passed to the callback function |
| #define timeout_add | ( | ev, | |||
| tv | ) | event_add(ev, tv) |
Add a timeout event.
| ev | the event struct to be disabled | |
| tv | the timeout value, in seconds |
| #define timeout_del | ( | ev | ) | event_del(ev) |
Disable a timeout event.
| ev | the timeout event to be disabled |
| #define timeout_set | ( | ev, | |||
| cb, | |||||
| arg | ) | event_set(ev, -1, 0, cb, arg) |
Define a timeout event.
| ev | the event struct to be defined | |
| cb | the callback to be invoked when the timeout expires | |
| arg | the argument to be passed to the callback |
| int bufferevent_base_set | ( | struct event_base * | base, | |
| struct bufferevent * | bufev | |||
| ) |
Assign a bufferevent to a specific event_base.
| base | an event_base returned by event_init() | |
| bufev | a bufferevent struct returned by bufferevent_new() |
| int bufferevent_disable | ( | struct bufferevent * | bufev, | |
| short | event | |||
| ) |
Disable a bufferevent.
| bufev | the bufferevent to be disabled | |
| event | any combination of EV_READ | EV_WRITE. |
| int bufferevent_enable | ( | struct bufferevent * | bufev, | |
| short | event | |||
| ) |
Enable a bufferevent.
| bufev | the bufferevent to be enabled | |
| event | any combination of EV_READ | EV_WRITE. |
| void bufferevent_free | ( | struct bufferevent * | bufev | ) |
Deallocate the storage associated with a bufferevent structure.
| bufev | the bufferevent structure to be freed. |
| struct bufferevent* bufferevent_new | ( | int | fd, | |
| evbuffercb | readcb, | |||
| evbuffercb | writecb, | |||
| everrorcb | errorcb, | |||
| void * | cbarg | |||
| ) |
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.
| 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) |
| int bufferevent_priority_set | ( | struct bufferevent * | bufev, | |
| int | pri | |||
| ) |
Assign a priority to a bufferevent.
| bufev | a bufferevent struct | |
| pri | the priority to be assigned |
| 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 |
| 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 |
| int bufferevent_write | ( | struct bufferevent * | bufev, | |
| 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 |
| int bufferevent_write_buffer | ( | struct bufferevent * | bufev, | |
| struct evbuffer * | buf | |||
| ) |
Write data from an evbuffer to a bufferevent buffer.
| bufev | the bufferevent to be written to | |
| buf | the evbuffer to be written |
| void encode_int | ( | struct evbuffer * | evbuf, | |
| u_int32_t | number | |||
| ) |
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.
| evbuf | evbuffer to store the encoded number | |
| number | a 32-bit integer |
| int evbuffer_add | ( | struct evbuffer * | buf, | |
| const void * | data, | |||
| size_t | datlen | |||
| ) |
Append data to the end of an evbuffer.
| buf | the event buffer 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 |
| int evbuffer_add_buffer | ( | struct evbuffer * | outbuf, | |
| struct evbuffer * | inbuf | |||
| ) |
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.
| outbuf | the output buffer | |
| inbuf | the input buffer |
| int evbuffer_add_printf | ( | struct evbuffer * | buf, | |
| const char * | fmt, | |||
| ... | ||||
| ) |
Append a formatted string to the end of an evbuffer.
| buf | the evbuffer that will be appended to | |
| fmt | a format string | |
| ... | arguments that will be passed to printf(3) |
| int evbuffer_add_vprintf | ( | struct evbuffer * | , | |
| 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) |
| void 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 |
| int evbuffer_expand | ( | struct evbuffer * | buf, | |
| size_t | datlen | |||
| ) |
Expands the available space in an event buffer.
Expands the available space in the event buffer to at least datlen
| buf | the event buffer to be expanded | |
| datlen | the new minimum length requirement |
| u_char* evbuffer_find | ( | struct evbuffer * | buffer, | |
| const u_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 |
| void evbuffer_free | ( | struct evbuffer * | buffer | ) |
Deallocate storage for an evbuffer.
| pointer | to the evbuffer to be freed |
| struct evbuffer* evbuffer_new | ( | void | ) |
Allocate storage for a new evbuffer.
| int evbuffer_read | ( | struct evbuffer * | buf, | |
| int | fd, | |||
| int | howmuch | |||
| ) |
Read from a file descriptor and store the result in an evbuffer.
| buf | the evbuffer to store the result | |
| fd | the file descriptor to read from | |
| howmuch | the number of bytes to be read |
| char* evbuffer_readline | ( | struct evbuffer * | ) |
Read a single line from an event buffer.
Reads a line terminated by either '
', '
' or '' or '
'. The returned buffer needs to be freed by the caller.
| buffer | the evbuffer to read from |
| int evbuffer_remove | ( | struct evbuffer * | buf, | |
| void * | data, | |||
| size_t | datlen | |||
| ) |
Read data from an event buffer and drain the bytes read.
| buf | the event buffer to be read from | |
| data | the destination buffer to store the result | |
| datlen | the maximum size of the destination buffer |
| void evbuffer_setcb | ( | struct evbuffer * | buffer, | |
| void(*)(struct evbuffer *, size_t, size_t, void *) | cb, | |||
| void * | cbarg | |||
| ) |
Set a callback to invoke when the evbuffer is modified.
| buffer | the evbuffer to be monitored | |
| cb | the callback function to invoke when the evbuffer is modified | |
| cbarg | an argument to be provided to the callback function |
| int evbuffer_write | ( | struct evbuffer * | buffer, | |
| int | 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 |
| int event_add | ( | struct event * | ev, | |
| struct timeval * | tv | |||
| ) |
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.
| ev | an event struct initialized via event_set() | |
| timeout | the maximum amount of time to wait for the event, or NULL to wait forever |
| int event_base_dispatch | ( | struct event_base * | ) |
Threadsafe event dispatching loop.
| eb | the event_base structure returned by event_init() |
| void event_base_free | ( | struct event_base * | eb | ) |
Deallocate all memory associated with an event_base.
| eb | an event_base to be freed |
| int event_base_loop | ( | struct event_base * | eb, | |
| int | flags | |||
| ) |
Execute a single event (threadsafe variant).
The event_base_loop() function provides an interface for single pass execution of pending events.
| eb | the event_base structure returned by event_init() | |
| flags | any combination of EVLOOP_ONCE | EVLOOP_NONBLOCK |
| int event_base_loopexit | ( | struct event_base * | eb, | |
| struct timeval * | tv | |||
| ) |
Execute a single event, with a timeout (threadsafe variant).
| eb | the event_base structure returned by event_init() | |
| tv | the amount of time after which the loop should terminate. |
| int event_base_once | ( | struct event_base * | base, | |
| int | fd, | |||
| short | events, | |||
| void(*)(int, short, void *) | callback, | |||
| void * | arg, | |||
| struct timeval * | tv | |||
| ) |
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.
| base | an event_base returned by event_init() | |
| fd | a file descriptor to monitor | |
| events | event(s) to monitor; can be any of EV_TIMEOUT | EV_READ | EV_WRITE | |
| 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, or NULL to wait forever |
| int event_base_priority_init | ( | struct event_base * | eb, | |
| int | npriorities | |||
| ) |
Set the number of different event priorities (threadsafe variant).
See the description of event_priority_init() for more information.
| eb | the event_base structure returned by event_init() | |
| npriorities | the maximum number of priorities |
| int event_base_set | ( | struct event_base * | eb, | |
| struct event * | ev | |||
| ) |
Associate a different event base with an event.
| eb | the event base | |
| ev | the event |
| 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 |
| int event_dispatch | ( | void | ) |
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.
| 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.
| void* event_init | ( | void | ) |
Initialize the event API.
The event API needs to be initialized with event_init() before it can be used.
| int event_loop | ( | int | flags | ) |
Execute a single event.
The event_loop() function provides an interface for single pass execution of pending events.
| flags | any combination of EVLOOP_ONCE | EVLOOP_NONBLOCK |
| int event_loopexit | ( | struct timeval * | tv | ) |
Execute a single event, with a timeout.
The event_loopexit() function is similar to event_loop(), but allows the loop to be terminated after some amount of time has passed.
| tv | the amount of time after which the loop should terminate. |
| int event_once | ( | int | fd, | |
| short | events, | |||
| void(*)(int, short, void *) | callback, | |||
| void * | arg, | |||
| struct timeval * | tv | |||
| ) |
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.
| fd | a file descriptor to monitor | |
| events | event(s) to monitor; can be any of EV_TIMEOUT | EV_READ | EV_WRITE | |
| 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, or NULL to wait forever |
| int event_pending | ( | struct event * | ev, | |
| short | event, | |||
| struct timeval * | tv | |||
| ) |
Checks if a specific event is pending or scheduled.
| ev | an event struct previously passed to event_add() | |
| event | the requested event type; any of EV_TIMEOUT|EV_READ|EV_WRITE|EV_SIGNAL | |
| tv | an alternate timeout (FIXME - is this true?) |
| int event_priority_init | ( | 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_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.
| npriorities | the maximum number of priorities |
| 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 |
| void event_set | ( | struct event * | , | |
| int | , | |||
| short | , | |||
| void(*)(int, short, void *) | , | |||
| void * | ||||
| ) |
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.
| ev | an event struct to be modified | |
| fd | the file descriptor to be monitored | |
| event | desired events to monitor; can be |