MySQL 5.6.14 Source Code Document
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
event.h File Reference
#include <config.h>
#include <stdarg.h>
#include <evutil.h>
Include dependency graph for event.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  event
struct  evkeyval
struct  evbuffer
struct  event_watermark
struct  bufferevent

Macros

#define EVLIST_TIMEOUT   0x01
#define EVLIST_INSERTED   0x02
#define EVLIST_SIGNAL   0x04
#define EVLIST_ACTIVE   0x08
#define EVLIST_INTERNAL   0x10
#define EVLIST_INIT   0x80
#define EVLIST_ALL   (0xf000 | 0x9f)
#define EV_TIMEOUT   0x01
#define EV_READ   0x02
#define EV_WRITE   0x04
#define EV_SIGNAL   0x08
#define EV_PERSIST   0x10 /* Persistant event */
#define _EVENT_DEFINED_TQENTRY
#define TAILQ_ENTRY(type)
#define EVENT_SIGNAL(ev)   (int)(ev)->ev_fd
#define EVENT_FD(ev)   (int)(ev)->ev_fd
#define _EVENT_LOG_DEBUG   0
#define _EVENT_LOG_MSG   1
#define _EVENT_LOG_WARN   2
#define _EVENT_LOG_ERR   3
#define evtimer_add(ev, tv)   event_add(ev, tv)
#define evtimer_set(ev, cb, arg)   event_set(ev, -1, 0, cb, arg)
#define evtimer_del(ev)   event_del(ev)
#define evtimer_pending(ev, tv)   event_pending(ev, EV_TIMEOUT, tv)
#define evtimer_initialized(ev)   ((ev)->ev_flags & EVLIST_INIT)
#define timeout_add(ev, tv)   event_add(ev, tv)
#define timeout_set(ev, cb, arg)   event_set(ev, -1, 0, cb, arg)
#define timeout_del(ev)   event_del(ev)
#define timeout_pending(ev, tv)   event_pending(ev, EV_TIMEOUT, tv)
#define timeout_initialized(ev)   ((ev)->ev_flags & EVLIST_INIT)
#define signal_add(ev, tv)   event_add(ev, tv)
#define signal_set(ev, x, cb, arg)   event_set(ev, x, EV_SIGNAL|EV_PERSIST, cb, arg)
#define signal_del(ev)   event_del(ev)
#define signal_pending(ev, tv)   event_pending(ev, EV_SIGNAL, tv)
#define signal_initialized(ev)   ((ev)->ev_flags & EVLIST_INIT)
#define event_initialized(ev)   ((ev)->ev_flags & EVLIST_INIT)
#define EVBUFFER_READ   0x01
#define EVBUFFER_WRITE   0x02
#define EVBUFFER_EOF   0x10
#define EVBUFFER_ERROR   0x20
#define EVBUFFER_TIMEOUT   0x40
#define EVBUFFER_LENGTH(x)   (x)->off
#define EVBUFFER_DATA(x)   (x)->buffer
#define EVBUFFER_INPUT(x)   (x)->input
#define EVBUFFER_OUTPUT(x)   (x)->output
#define EVLOOP_ONCE   0x01
#define EVLOOP_NONBLOCK   0x02

Typedefs

typedef void(* event_log_cb )(int severity, const char *msg)
typedef void(* evbuffercb )(struct bufferevent *, void *)
typedef void(* everrorcb )(struct bufferevent *, short what, void *)

Functions

struct event_baseevent_base_new (void)
struct event_baseevent_init (void)
int event_reinit (struct event_base *base)
int event_dispatch (void)
int event_base_dispatch (struct event_base *)
const char * event_base_get_method (struct event_base *)
void event_base_free (struct event_base *)
void event_set_log_callback (event_log_cb cb)
int event_base_set (struct event_base *, struct event *)
int event_loop (int)
int event_base_loop (struct event_base *, int)
int event_loopexit (const struct timeval *)
int event_base_loopexit (struct event_base *, const struct timeval *)
int event_loopbreak (void)
int event_base_loopbreak (struct event_base *)
void event_set (struct event *, int, short, void(*)(int, short, void *), void *)
int event_once (int, short, void(*)(int, short, void *), void *, const struct timeval *)
int event_base_once (struct event_base *base, int fd, short events, void(*callback)(int, short, void *), void *arg, const struct timeval *timeout)
int event_add (struct event *ev, const struct timeval *timeout)
int event_del (struct event *)
void event_active (struct event *, int, short)
int event_pending (struct event *ev, short event, struct timeval *tv)
const char * event_get_version (void)
const char * event_get_method (void)
int event_priority_init (int)
int event_base_priority_init (struct event_base *, int)
int event_priority_set (struct event *, int)
struct buffereventbufferevent_new (int fd, evbuffercb readcb, evbuffercb writecb, everrorcb errorcb, void *cbarg)
int bufferevent_base_set (struct event_base *base, struct bufferevent *bufev)
int bufferevent_priority_set (struct bufferevent *bufev, int pri)
void bufferevent_free (struct bufferevent *bufev)
void bufferevent_setcb (struct bufferevent *bufev, evbuffercb readcb, evbuffercb writecb, everrorcb errorcb, void *cbarg)
void bufferevent_setfd (struct bufferevent *bufev, int fd)
int bufferevent_write (struct bufferevent *bufev, const void *data, size_t size)
int bufferevent_write_buffer (struct bufferevent *bufev, struct evbuffer *buf)
size_t bufferevent_read (struct bufferevent *bufev, void *data, size_t size)
int bufferevent_enable (struct bufferevent *bufev, short event)
int bufferevent_disable (struct bufferevent *bufev, short event)
void bufferevent_settimeout (struct bufferevent *bufev, int timeout_read, int timeout_write)
void bufferevent_setwatermark (struct bufferevent *bufev, short events, size_t lowmark, size_t highmark)
struct evbufferevbuffer_new (void)
void evbuffer_free (struct evbuffer *)
int evbuffer_expand (struct evbuffer *, size_t)
int evbuffer_add (struct evbuffer *, const void *, size_t)
int evbuffer_remove (struct evbuffer *, void *, size_t)
char * evbuffer_readline (struct evbuffer *)
int evbuffer_add_buffer (struct evbuffer *, struct evbuffer *)
int evbuffer_add_printf (struct evbuffer *, const char *fmt,...)
int evbuffer_add_vprintf (struct evbuffer *, const char *fmt, va_list ap)
void evbuffer_drain (struct evbuffer *, size_t)
int evbuffer_write (struct evbuffer *, int)
int evbuffer_read (struct evbuffer *, int, int)
u_char * evbuffer_find (struct evbuffer *, const u_char *, size_t)
void evbuffer_setcb (struct evbuffer *, void(*)(struct evbuffer *, size_t, size_t, void *), void *)
void evtag_init (void)
void evtag_marshal (struct evbuffer *evbuf, ev_uint32_t tag, const void *data, ev_uint32_t len)
void encode_int (struct evbuffer *evbuf, ev_uint32_t number)
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_unmarshal (struct evbuffer *src, ev_uint32_t *ptag, struct evbuffer *dst)
int evtag_peek (struct evbuffer *evbuf, ev_uint32_t *ptag)
int evtag_peek_length (struct evbuffer *evbuf, ev_uint32_t *plength)
int evtag_payload_length (struct evbuffer *evbuf, ev_uint32_t *plength)
int evtag_consume (struct evbuffer *evbuf)
int evtag_unmarshal_int (struct evbuffer *evbuf, ev_uint32_t need_tag, ev_uint32_t *pinteger)
int evtag_unmarshal_fixed (struct evbuffer *src, ev_uint32_t need_tag, void *data, size_t len)
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)

Detailed Description

A library for writing event-driven network servers

Definition in file event.h.

Macro Definition Documentation

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

Parameters
evan event structure to be tested
Returns
1 if the structure has been initialized, or 0 if it has not been initialized

Definition at line 653 of file event.h.

#define EVLOOP_NONBLOCK   0x02

Do not block.

Definition at line 362 of file event.h.

#define EVLOOP_ONCE   0x01

event_loop() flagsBlock at most once.

Definition at line 361 of file event.h.

#define evtimer_add (   ev,
  tv 
)    event_add(ev, tv)

Add a timer event.

Parameters
evthe event struct
tvtimeval struct

Definition at line 458 of file event.h.

#define evtimer_del (   ev)    event_del(ev)

Delete a timer event.

Parameters
evthe event struct to be disabled

Definition at line 476 of file event.h.

#define evtimer_set (   ev,
  cb,
  arg 
)    event_set(ev, -1, 0, cb, arg)

Define a timer event.

Parameters
evevent struct to be modified
cbcallback function
argargument that will be passed to the callback function

Definition at line 468 of file event.h.

#define TAILQ_ENTRY (   type)
Value:
struct { \
struct type *tqe_next; /* next element */ \
struct type **tqe_prev; /* address of previous next element */ \
}

Definition at line 204 of file event.h.

#define timeout_add (   ev,
  tv 
)    event_add(ev, tv)

Add a timeout event.

Parameters
evthe event struct to be disabled
tvthe timeout value, in seconds

Definition at line 486 of file event.h.

#define timeout_del (   ev)    event_del(ev)

Disable a timeout event.

Parameters
evthe timeout event to be disabled

Definition at line 504 of file event.h.

#define timeout_set (   ev,
  cb,
  arg 
)    event_set(ev, -1, 0, cb, arg)

Define a timeout event.

Parameters
evthe event struct to be defined
cbthe callback to be invoked when the timeout expires
argthe argument to be passed to the callback

Definition at line 496 of file event.h.

Function Documentation

int bufferevent_base_set ( struct event_base base,
struct bufferevent bufev 
)

Assign a bufferevent to a specific event_base.

Parameters
basean event_base returned by event_init()
bufeva bufferevent struct returned by bufferevent_new()
Returns
0 if successful, or -1 if an error occurred
See Also
bufferevent_new()

Definition at line 443 of file evbuffer.c.

int bufferevent_disable ( struct bufferevent bufev,
short  event 
)

Disable a bufferevent.

Parameters
bufevthe bufferevent to be disabled
eventany combination of EV_READ | EV_WRITE.
Returns
0 if successful, or -1 if an error occurred
See Also
bufferevent_enable()

Definition at line 388 of file evbuffer.c.

int bufferevent_enable ( struct bufferevent bufev,
short  event 
)

Enable a bufferevent.

Parameters
bufevthe bufferevent to be enabled
eventany combination of EV_READ | EV_WRITE.
Returns
0 if successful, or -1 if an error occurred
See Also
bufferevent_disable()

Definition at line 372 of file evbuffer.c.

void bufferevent_free ( struct bufferevent bufev)

Deallocate the storage associated with a bufferevent structure.

Parameters
bufevthe bufferevent structure to be freed.

Definition at line 309 of file evbuffer.c.

struct bufferevent* bufferevent_new ( int  fd,
evbuffercb  readcb,
evbuffercb  writecb,
everrorcb  errorcb,
void *  cbarg 
)
read

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.

Parameters
fdthe file descriptor from which data is read and written to. This file descriptor is not allowed to be a pipe(2).
readcbcallback to invoke when there is data to be read, or NULL if no callback is desired
writecbcallback to invoke when the file descriptor is ready for writing, or NULL if no callback is desired
errorcbcallback to invoke when there is an error on the file descriptor
cbargan argument that will be supplied to each of the callbacks (readcb, writecb, and errorcb)
Returns
a pointer to a newly allocated bufferevent struct, or NULL if an error occurred
See Also
bufferevent_base_set(), bufferevent_free()

Definition at line 234 of file evbuffer.c.

int bufferevent_priority_set ( struct bufferevent bufev,
int  pri 
)

Assign a priority to a bufferevent.

Parameters
bufeva bufferevent struct
prithe priority to be assigned
Returns
0 if successful, or -1 if an error occurred

Definition at line 296 of file evbuffer.c.

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.

Parameters
bufevthe bufferevent to be read from
datapointer to a buffer that will store the data
sizethe size of the data buffer, in bytes
Returns
the amount of data read, in bytes.

Definition at line 355 of file evbuffer.c.

void bufferevent_setcb ( struct bufferevent bufev,
evbuffercb  readcb,
evbuffercb  writecb,
everrorcb  errorcb,
void *  cbarg 
)

Changes the callbacks for a bufferevent.

Parameters
bufevthe bufferevent object for which to change callbacks
readcbcallback to invoke when there is data to be read, or NULL if no callback is desired
writecbcallback to invoke when the file descriptor is ready for writing, or NULL if no callback is desired
errorcbcallback to invoke when there is an error on the file descriptor
cbargan argument that will be supplied to each of the callbacks (readcb, writecb, and errorcb)
See Also
bufferevent_new()

Definition at line 269 of file evbuffer.c.

void bufferevent_setfd ( struct bufferevent bufev,
int  fd 
)

Changes the file descriptor on which the bufferevent operates.

Parameters
bufevthe bufferevent object for which to change the file descriptor
fdthe file descriptor to operate on

Definition at line 280 of file evbuffer.c.

void bufferevent_settimeout ( struct bufferevent bufev,
int  timeout_read,
int  timeout_write 
)

Set the read and write timeout for a buffered event.

Parameters
bufevthe bufferevent to be modified
timeout_readthe read timeout
timeout_writethe write timeout

Definition at line 408 of file evbuffer.c.

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 buffevent stops reading from the network.

On output, the user write callback is invoked whenever the buffered data falls below the low watermark.

Parameters
bufevthe bufferevent to be modified
eventsEV_READ, EV_WRITE or both
lowmarkthe lower watermark to set
highmarkthe high watermark to set

Definition at line 424 of file evbuffer.c.

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.

Parameters
bufevthe bufferevent to be written to
dataa pointer to the data to be written
sizethe length of the data, in bytes
Returns
0 if successful, or -1 if an error occurred
See Also
bufferevent_write_buffer()

Definition at line 326 of file evbuffer.c.

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.

Parameters
bufevthe bufferevent to be written to
bufthe evbuffer to be written
Returns
0 if successful, or -1 if an error occurred
See Also
bufferevent_write()

Definition at line 343 of file evbuffer.c.

void encode_int ( struct evbuffer evbuf,
ev_uint32_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.

Parameters
evbufevbuffer to store the encoded number
numbera 32-bit integer

Definition at line 91 of file event_tagging.c.

Here is the call graph for this function:

Here is the caller graph for this function:

int evbuffer_add ( struct evbuffer ,
const void *  ,
size_t   
)

Append data to the end of an evbuffer.

Parameters
bufthe event buffer to be appended to
datapointer to the beginning of the data buffer
datlenthe number of bytes to be copied from the data buffer

Definition at line 301 of file buffer.c.

int evbuffer_add_buffer ( struct evbuffer ,
struct 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.

Parameters
outbufthe output buffer
inbufthe input buffer
Returns
0 if successful, or -1 if an error occurred

Definition at line 100 of file buffer.c.

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

Append a formatted string to the end of an evbuffer.

Parameters
bufthe evbuffer that will be appended to
fmta format string
...arguments that will be passed to printf(3)
Returns
The number of bytes added if successful, or -1 if an error occurred.

Definition at line 178 of file buffer.c.

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

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

Parameters
bufthe evbuffer that will be appended to
fmta format string
apa varargs va_list argument array that will be passed to vprintf(3)
Returns
The number of bytes added if successful, or -1 if an error occurred.

Definition at line 137 of file buffer.c.

void evbuffer_drain ( struct evbuffer ,
size_t   
)

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

Parameters
bufthe evbuffer to be drained
lenthe number of bytes to drain from the beginning of the buffer

Definition at line 321 of file buffer.c.

int evbuffer_expand ( struct evbuffer ,
size_t   
)

Expands the available space in an event buffer.

Expands the available space in the event buffer to at least datlen

Parameters
bufthe event buffer to be expanded
datlenthe new minimum length requirement
Returns
0 if successful, or -1 if an error occurred

Definition at line 265 of file buffer.c.

u_char* evbuffer_find ( struct evbuffer ,
const u_char *  ,
size_t   
)

Find a string within an evbuffer.

Parameters
bufferthe evbuffer to be searched
whatthe string to be searched for
lenthe length of the search string
Returns
a pointer to the beginning of the search string, or NULL if the search failed.

Definition at line 428 of file buffer.c.

void evbuffer_free ( struct evbuffer )

Deallocate storage for an evbuffer.

Parameters
pointerto the evbuffer to be freed

Definition at line 79 of file buffer.c.

struct evbuffer* evbuffer_new ( void  )
read

Allocate storage for a new evbuffer.

Returns
a pointer to a newly allocated evbuffer struct, or NULL if an error occurred

Definition at line 69 of file buffer.c.

int evbuffer_read ( struct evbuffer ,
int  ,
int   
)

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

Parameters
bufthe evbuffer to store the result
fdthe file descriptor to read from
howmuchthe number of bytes to be read
Returns
the number of bytes read, or -1 if an error occurred
See Also
evbuffer_write()

Definition at line 351 of file buffer.c.

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.

Parameters
bufferthe evbuffer to read from
Returns
pointer to a single line, or NULL if an error occurred

Definition at line 211 of file buffer.c.

int evbuffer_remove ( struct evbuffer ,
void *  ,
size_t   
)

Read data from an event buffer and drain the bytes read.

Parameters
bufthe event buffer to be read from
datathe destination buffer to store the result
datlenthe maximum size of the destination buffer
Returns
the number of bytes read

Definition at line 193 of file buffer.c.

void evbuffer_setcb ( struct evbuffer ,
void(*)(struct evbuffer *, size_t, size_t, void *)  ,
void *   
)

Set a callback to invoke when the evbuffer is modified.

Parameters
bufferthe evbuffer to be monitored
cbthe callback function to invoke when the evbuffer is modified
cbargan argument to be provided to the callback function

Definition at line 445 of file buffer.c.

int evbuffer_write ( struct evbuffer ,
int   
)

Write the contents of an evbuffer to a file descriptor.

The evbuffer will be drained after the bytes have been successfully written.

Parameters
bufferthe evbuffer to be written and drained
fdthe file descriptor to be written to
Returns
the number of bytes written, or -1 if an error occurred
See Also
evbuffer_read()

Definition at line 409 of file buffer.c.

int event_add ( struct event ev,
const struct timeval timeout 
)

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.

Parameters
evan event struct initialized via event_set()
timeoutthe maximum amount of time to wait for the event, or NULL to wait forever
Returns
0 if successful, or -1 if an error occurred
See Also
event_del(), event_set()

Definition at line 719 of file event.c.

int event_base_dispatch ( struct event_base )

Threadsafe event dispatching loop.

Parameters
ebthe event_base structure returned by event_init()
See Also
event_init(), event_dispatch()

Definition at line 410 of file event.c.

void event_base_free ( struct event_base )

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.

Parameters
eban event_base to be freed

Definition at line 214 of file event.c.

const char* event_base_get_method ( struct event_base )

Get the kernel event notification mechanism used by libevent.

Parameters
ebthe event_base structure returned by event_base_new()
Returns
a string identifying the kernel event mechanism (kqueue, epoll, etc.)

Definition at line 416 of file event.c.

int event_base_loop ( struct event_base ,
int   
)

Handle events (threadsafe version).

This is a more flexible version of event_base_dispatch().

Parameters
ebthe event_base structure returned by event_init()
flagsany combination of EVLOOP_ONCE | EVLOOP_NONBLOCK
Returns
0 if successful, -1 if an error occurred, or 1 if no events were registered.
See Also
event_loopexit(), event_base_loop()

Definition at line 472 of file event.c.

int event_base_loopbreak ( struct event_base )

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.

Parameters
ebthe event_base structure returned by event_init()
Returns
0 if successful, or -1 if an error occurred
See Also
event_base_loopexit

Definition at line 452 of file event.c.

int event_base_loopexit ( struct event_base ,
const struct timeval  
)

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.

Parameters
ebthe event_base structure returned by event_init()
tvthe amount of time after which the loop should terminate.
Returns
0 if successful, or -1 if an error occurred
See Also
event_loopexit()

Definition at line 438 of file event.c.

struct event_base* event_base_new ( void  )
read

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

See Also
event_base_set(), event_base_free(), event_init()

Definition at line 174 of file event.c.

int event_base_once ( struct event_base base,
int  fd,
short  events,
void(*)(int, short, void *)  callback,
void *  arg,
const struct timeval timeout 
)

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.

Parameters
basean event_base returned by event_init()
fda file descriptor to monitor
eventsevent(s) to monitor; can be any of EV_TIMEOUT | EV_READ | EV_WRITE
callbackcallback function to be invoked when the event occurs
argan argument to be passed to the callback function
timeoutthe maximum amount of time to wait for the event, or NULL to wait forever
Returns
0 if successful, or -1 if an error occurred
See Also
event_once()

Definition at line 588 of file event.c.

int event_base_priority_init ( struct event_base ,
int   
)

Set the number of different event priorities (threadsafe variant).

See the description of event_priority_init() for more information.

Parameters
ebthe event_base structure returned by event_init()
nprioritiesthe maximum number of priorities
Returns
0 if successful, or -1 if an error occurred
See Also
event_priority_init(), event_priority_set()

Definition at line 320 of file event.c.

int event_base_set ( struct event_base ,
struct event  
)

Associate a different event base with an event.

Parameters
ebthe event base
evthe event

Definition at line 657 of file event.c.

int event_del ( struct 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.

Parameters
evan event struct to be removed from the working set
Returns
0 if successful, or -1 if an error occurred
See Also
event_add()

Definition at line 797 of file event.c.

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.

See Also
event_base_dispatch()

Definition at line 404 of file event.c.

const char* event_get_method ( void  )

Get the kernel event notification mechanism used by libevent.

Returns
a string identifying the kernel event mechanism (kqueue, epoll, etc.)

Definition at line 1022 of file event.c.

const char* event_get_version ( void  )

Get the libevent version number.

Returns
a string containing the version number of libevent

Definition at line 1011 of file event.c.

struct event_base* event_init ( void  )
read

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.

See Also
event_base_set(), event_base_new()

Definition at line 163 of file event.c.

int event_loop ( int  )

Handle events.

This is a more flexible version of event_dispatch().

Parameters
flagsany combination of EVLOOP_ONCE | EVLOOP_NONBLOCK
Returns
0 if successful, -1 if an error occurred, or 1 if no events were registered.
See Also
event_loopexit(), event_base_loop()

Definition at line 466 of file event.c.

int event_loopbreak ( void  )

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.

Returns
0 if successful, or -1 if an error occurred
See Also
event_base_loopbreak(), event_loopexit()

Definition at line 446 of file event.c.

int event_loopexit ( const struct timeval )

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.

Parameters
tvthe amount of time after which the loop should terminate.
Returns
0 if successful, or -1 if an error occurred
See Also
event_loop(), event_base_loop(), event_base_loopexit()

Definition at line 431 of file event.c.

int event_once ( int  ,
short  ,
void(*)(int, short, void *)  ,
void *  ,
const struct timeval  
)

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.

Parameters
fda file descriptor to monitor
eventsevent(s) to monitor; can be any of EV_TIMEOUT | EV_READ | EV_WRITE
callbackcallback function to be invoked when the event occurs
argan argument to be passed to the callback function
timeoutthe maximum amount of time to wait for the event, or NULL to wait forever
Returns
0 if successful, or -1 if an error occurred
See Also
event_set()

Definition at line 580 of file event.c.

int event_pending ( struct event ev,
short  event,
struct timeval tv 
)

Checks if a specific event is pending or scheduled.

Parameters
evan event struct previously passed to event_add()
eventthe requested event type; any of EV_TIMEOUT|EV_READ| EV_WRITE|EV_SIGNAL
tvan alternate timeout (FIXME - is this true?)
Returns
1 if the event is pending, or 0 if the event has not occurred

Definition at line 692 of file event.c.

int event_priority_init ( int  )

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.

Parameters
nprioritiesthe maximum number of priorities
Returns
0 if successful, or -1 if an error occurred
See Also
event_base_priority_init(), event_priority_set()

Definition at line 314 of file event.c.

int event_priority_set ( struct event ,
int   
)

Assign a priority to an event.

Parameters
evan event struct
prioritythe new priority to be assigned
Returns
0 if successful, or -1 if an error occurred
See Also
event_priority_init()

Definition at line 675 of file event.c.

int event_reinit ( struct event_base base)

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.

Parameters
basethe event base that needs to be re-initialized
Returns
0 if successful, or -1 if some events could not be re-added.
See Also
event_base_new(), event_init()

Definition at line 275 of file event.c.

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.

Parameters
evan event struct to be modified
fdthe file descriptor to be monitored
eventdesired events to monitor; can be EV_READ and/or EV_WRITE
fncallback function to be invoked when the event occurs
argan argument to be passed to the callback function
See Also
event_add(), event_del(), event_once()

Definition at line 634 of file event.c.

void event_set_log_callback ( event_log_cb  cb)

Redirect libevent's log messages.

Parameters
cba 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.

Definition at line 156 of file log.c.

Here is the call graph for this function:

Here is the caller graph for this function: