event.h File Reference

A library for writing event-driven network servers. More...

#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.
#define EVLOOP_NONBLOCK   0x02
 Do not block.
#define EVLOOP_ONCE   0x01
 event_loop() flags

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.
struct 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, 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.
struct 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.
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 *, struct timeval *)
 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 *, struct timeval *)
 Exit the event loop after the specified time (threadsafe variant).
struct event_base * event_base_new (void)
 Initialize the event API.
int event_base_once (struct event_base *, int, short, void(*)(int, short, void *), void *, struct timeval *)
 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.
struct 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 (struct timeval *)
 Exit the event loop after the specified time.
int event_once (int, short, void(*)(int, short, void *), void *, struct timeval *)
 Schedule a one-time event to occur.
int event_pending (struct event *, short, struct timeval *)
 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)


Detailed Description

A library for writing event-driven network servers.


Define 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:
ev an event structure to be tested
Returns:
1 if the structure has been initialized, or 0 if it has not been initialized

#define EVLOOP_NONBLOCK   0x02

Do not block.

#define EVLOOP_ONCE   0x01

event_loop() flags

Block at most once.

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

Add a timer event.

Parameters:
ev the event struct
tv timeval struct

#define evtimer_del ( ev   )     event_del(ev)

Delete a timer event.

Parameters:
ev the event struct to be disabled

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

Define a timer event.

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

Parameters:
ev the event struct to be disabled
tv the timeout value, in seconds

#define timeout_del ( ev   )     event_del(ev)

Disable a timeout event.

Parameters:
ev the timeout event to be disabled

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

Define a timeout event.

Parameters:
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


Function Documentation

int bufferevent_base_set ( struct event_base *  base,
struct bufferevent *  bufev 
)

Assign a bufferevent to a specific event_base.

Parameters:
base an event_base returned by event_init()
bufev a bufferevent struct returned by bufferevent_new()
Returns:
0 if successful, or -1 if an error occurred
See also:
bufferevent_new()

int bufferevent_disable ( struct bufferevent *  bufev,
short  event 
)

Disable a bufferevent.

Parameters:
bufev the bufferevent to be disabled
event any combination of EV_READ | EV_WRITE.
Returns:
0 if successful, or -1 if an error occurred
See also:
bufferevent_enable()

int bufferevent_enable ( struct bufferevent *  bufev,
short  event 
)

Enable a bufferevent.

Parameters:
bufev the bufferevent to be enabled
event any combination of EV_READ | EV_WRITE.
Returns:
0 if successful, or -1 if an error occurred
See also:
bufferevent_disable()

void bufferevent_free ( struct bufferevent *  bufev  ) 

Deallocate the storage associated with a bufferevent structure.

Parameters:
bufev the bufferevent structure to be freed.

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:
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)
Returns:
a pointer to a newly allocated bufferevent struct, or NULL if an error occurred
See also:
bufferevent_base_set(), bufferevent_free()

int bufferevent_priority_set ( struct bufferevent *  bufev,
int  pri 
)

Assign a priority to a bufferevent.

Parameters:
bufev a bufferevent struct
pri the priority to be assigned
Returns:
0 if successful, or -1 if an error occurred

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:
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
Returns:
the amount of data read, in bytes.

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

Set the read and write timeout for a buffered event.

Parameters:
bufev the bufferevent to be modified
timeout_read the read timeout
timeout_write the write timeout

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:
bufev the bufferevent to be written to
data a pointer to the data to be written
size the length of the data, in bytes
Returns:
0 if successful, or -1 if an error occurred
See also:
bufferevent_write_buffer()

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:
bufev the bufferevent to be written to
buf the evbuffer to be written
Returns:
0 if successful, or -1 if an error occurred
See also:
bufferevent_write()

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:
evbuf evbuffer to store the encoded number
number a 32-bit integer

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

Append data to the end of an evbuffer.

Parameters:
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 *  ,
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:
outbuf the output buffer
inbuf the input buffer
Returns:
0 if successful, or -1 if an error occurred

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

Append a formatted string to the end of an evbuffer.

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

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:
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)
Returns:
The number of bytes added if successful, or -1 if an error occurred.

void evbuffer_drain ( struct evbuffer *  ,
size_t   
)

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

Parameters:
buf the evbuffer to be drained
len the number of bytes to drain from the beginning of the buffer
Returns:
0 if successful, or -1 if an error occurred

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:
buf the event buffer to be expanded
datlen the new minimum length requirement
Returns:
0 if successful, or -1 if an error occurred

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

Find a string within an evbuffer.

Parameters:
buffer the evbuffer to be searched
what the string to be searched for
len the length of the search string
Returns:
a pointer to the beginning of the search string, or NULL if the search failed.

void evbuffer_free ( struct evbuffer *   ) 

Deallocate storage for an evbuffer.

Parameters:
pointer to the evbuffer to be freed

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

int evbuffer_read ( struct evbuffer *  ,
int  ,
int   
)

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

Parameters:
buf the evbuffer to store the result
fd the file descriptor to read from
howmuch the number of bytes to be read
Returns:
the number of bytes read, or -1 if an error occurred
See also:
evbuffer_write()

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:
buffer the evbuffer to read from
Returns:
pointer to a single line, or NULL if an error occurred

int evbuffer_remove ( struct evbuffer *  ,
void *  ,
size_t   
)

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

Parameters:
buf the event buffer to be read from
data the destination buffer to store the result
datlen the maximum size of the destination buffer
Returns:
the number of 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.

Parameters:
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 *  ,
int   
)

Write the contents of an evbuffer to a file descriptor.

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

Parameters:
buffer the evbuffer to be written and drained
fd the file descriptor to be written to
Returns:
the number of bytes written, or -1 if an error occurred
See also:
evbuffer_read()

int event_add ( struct event *  ,
struct timeval *   
)

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:
ev an event struct initialized via event_set()
timeout the 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()

int event_base_dispatch ( struct event_base *   ) 

Threadsafe event dispatching loop.

Parameters:
eb the event_base structure returned by event_init()
See also:
event_init(), event_dispatch()

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:
eb an event_base to be freed

const char* event_base_get_method ( struct event_base *   ) 

Get the kernel event notification mechanism used by libevent.

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

int event_base_loop ( struct event_base *  ,
int   
)

Handle events (threadsafe version).

This is a more flexible version of event_base_dispatch().

Parameters:
eb the event_base structure returned by event_init()
flags any 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()

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:
eb the event_base structure returned by event_init()
Returns:
0 if successful, or -1 if an error occurred
See also:
event_base_loopexit

int event_base_loopexit ( struct event_base *  ,
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:
eb the event_base structure returned by event_init()
tv the amount of time after which the loop should terminate.
Returns:
0 if successful, or -1 if an error occurred
See also:
event_loopexit()

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

int event_base_once ( struct event_base *  ,
int  ,
short  ,
void(*)(int, short, void *)  ,
void *  ,
struct timeval *   
)

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:
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
Returns:
0 if successful, or -1 if an error occurred
See also:
event_once()

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:
eb the event_base structure returned by event_init()
npriorities the maximum number of priorities
Returns:
0 if successful, or -1 if an error occurred
See also:
event_priority_init(), event_priority_set()

int event_base_set ( struct event_base *  ,
struct event *   
)

Associate a different event base with an event.

Parameters:
eb the event base
ev the event

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:
ev an event struct to be removed from the working set
Returns:
0 if successful, or -1 if an error occurred
See also:
event_add()

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

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

const char* event_get_version ( void   ) 

Get the libevent version number.

Returns:
a string containing the version number of libevent

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

int event_loop ( int   ) 

Handle events.

This is a more flexible version of event_dispatch().

Parameters:
flags any 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()

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

int event_loopexit ( 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:
tv the 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()

int event_once ( int  ,
short  ,
void(*)(int, short, void *)  ,
void *  ,
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:
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
Returns:
0 if successful, or -1 if an error occurred
See also:
event_set()

int event_pending ( struct event *  ,
short  ,
struct timeval *   
)

Checks if a specific event is pending or scheduled.

Parameters:
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?)
Returns:
1 if the event is pending, or 0 if the event has not occurred

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:
npriorities the maximum number of priorities
Returns:
0 if successful, or -1 if an error occurred
See also:
event_base_priority_init(), event_priority_set()

int event_priority_set ( struct event *  ,
int   
)

Assign a priority to an event.

Parameters:
ev an event struct
priority the new priority to be assigned
Returns:
0 if successful, or -1 if an error occurred
See also:
event_priority_init()

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:
base the 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()

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:
ev an event struct to be modified
fd the file descriptor to be monitored
event desired events to monitor; can be EV_READ and/or EV_WRITE
fn callback function to be invoked when the event occurs
arg an argument to be passed to the callback function
See also:
event_add(), event_del(), event_once()

void event_set_log_callback ( event_log_cb  cb  ) 

Redirect libevent's log messages.

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


Generated on Fri Apr 11 08:26:23 2008 for libevent by  doxygen 1.5.3