NAME
SYNOPSIS
DESCRIPTION
The
API provides a mechanism to execute a function when a specific event
on a file descriptor occurs or after a given time has passed.
The
API needs to be initialized with
before it can be used.
In order to process events, an application needs to call
This function only returns on error, and should replace the event core
of the application program.
In order to avoid races in signal handlers, the
API provides two variables:
and
A signal handler
sets
to indicate that a signal has been received.
The application sets
to a callback function.
After the signal handler sets
will execute the callback function to process received signals.
The callback returns 1 when no events are registered any more.
It can return -1 to indicate an error to the
library, causing
to terminate with
set to
The
function provides an interface for single pass execution of pending
events.
The flags
and
are recognized.
The
function allows the loop to be terminated after some amount of time
has passed.
The parameter indicates the time after which the loop should terminate.
It is the responsibility of the caller to provide these functions with
pre-allocated event structures.
The function
prepares the event structure
to be used in future calls to
and
The event will be prepared to call the function specified by the
argument with an
argument indicating the file descriptor, a
argument indicating the type of event, and a
argument given in the
argument.
The
indicates the file descriptor that should be monitored for events.
The events can be either
or both,
indicating that an application can read or write from the file descriptor
respectively without blocking.
The function
will be called with the file descriptor that triggered the event and
the type of event which will be either
or
The additional flag
makes an
persistent until
has been called.
Once initialized, the
structure can be used repeatedly with
and
and does not need to be reinitialized unless the function called and/or
the argument to it are to be changed.
However, when an
structure has been added to libevent using
the structure must persist until the event occurs (assuming
is not set) or is removed
using
You may not reuse the same
structure for multiple monitored descriptors; each descriptor
needs its own
The function
schedules the execution of the
event when the event specified in
occurs or in at least the time specified in the
If
is
no timeout occurs and the function will only be called
if a matching event occurs on the file descriptor.
The event in the
argument must be already initialized by
and may not be used in calls to
until it has timed out or been removed with
If the event in the
argument already has a scheduled timeout, the old timeout will be
replaced by the new one.
The function
will cancel the event in the argument
If the event has already executed or has never been added
the call will have no effect.
The function
is similar to
However, it schedules a callback to be called exactly once and does not
require the caller to prepare an
structure.
This function supports
and
The
function can be used to check if the event specified by
is pending to run.
If
was specified and
is not
the expiration time of the event will be returned in
The
macro can be used to check if an event has been initialized.
The functions
and
are abbreviations for common situations where only a timeout is required.
The file descriptor passed will be -1, and the event type will be
The functions
and
are abbreviations.
The event type will be a persistent
That means
adds
It is possible to disable support for
or
by setting the environment variable
or
respectively.
By setting the environment variable
displays the kernel notification method that it uses.
EVENT PRIORITIES
By default
schedules all active events with the same priority.
However, sometimes it is desirable to process some events with a higher
priority than others.
For that reason,
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
function.
This function should be called before the first call to
The
function can be used to assign a priority to an event.
By default,
assigns the middle priority to all events unless their priority
is explicitly set.
THREAD SAFE EVENTS
has experimental support for thread-safe events.
When initializing the library via
an event base is returned.
This event base can be used in conjunction with calls to
and
should be called after preparing an event with
as
assigns the provided event to the most recently created event base.
should be called after preparing a bufferevent with
BUFFERED EVENTS
provides an abstraction on top of the regular event callbacks.
This abstraction is called a
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 IO,
but instead is reading from input and writing to output buffers.
A new bufferevent is created by
The parameter
specifies the file descriptor from which data is read and written to.
This file descriptor is not allowed to be a
pipe(2)
The next three parameters are callbacks.
The read and write callback have the following form:
The error callback has the following form:
The argument is specified by the fourth parameter
A
pointer is returned on success, NULL on error.
Both the read and the write callback may be NULL.
The error callback has to be always provided.
Once initialized, the bufferevent structure can be used repeatedly with
bufferevent_enable() and bufferevent_disable(). The flags parameter can
be a combination of
and
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
by default.
The
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.
The
function is used to read data from the input buffer.
Both functions return the amount of data written or read.
If multiple bases are in use, bufferevent_base_set() must be called before
enabling the bufferevent for the first time.
NON-BLOCKING HTTP SUPPORT
provides a very thin HTTP layer that can be used both to host an HTTP
server and also to make HTTP requests.
An HTTP server can be created by calling
When the HTTP server is no longer used, it can be freed via
To be notified of HTTP requests, a user needs to register callbacks with the
HTTP server.
This can be done by calling
The second argument is the URI for which a callback is being registered.
The corresponding callback will receive an
object that contains all information about the request.
This section does not document all the possible function calls, please
check
for the public interfaces.
RETURN VALUES
Upon successful completion
and
return 0.
Otherwise, -1 is returned and the global variable errno is
set to indicate the error.
SEE ALSO
HISTORY
The
API manpage is based on the
timeout(9)
manpage by Artur Grabowski.
The port of
to Windows is due to Michael A. Davis.
Support for real-time signals is due to Taral.
AUTHORS
The
library was written by Niels Provos.
BUGS
This documentation is neither complete nor authoritative.
If you are in doubt about the usage of this API then
check the source code to find out how it works, write
up the missing piece of documentation and send it to
me for inclusion in this man page.