libevent is meant to replace the event loop found in event driven network servers. An application just needs to call event_dispatch() and then add or remove events dynamically without having to change the event loop.
Currently, libevent supports /dev/poll, kqueue(2), select(2), poll(2) and epoll(4). It also has experimental support for real-time signals. The internal event mechanism is completely independent of the exposed event API, and a simple update of libevent can provide new functionality without having to redesign the applications. As a result, Libevent allows for portable application development and provides the most scalable event notification mechanism available on an operating system. Libevent can also be used for multi-threaded aplications; see Steven Grimm's explanation. Libevent should compile on Linux, *BSD, Mac OS X, Solaris and Windows.event_init() or event_base_new() to perform one-time initialization of the libevent library.event_set() to initialize the members of the structure. To enable notification, you add the structure to the list of monitored events by calling event_add(). The event structure must remain allocated as long as it is active, so it should be allocated on the heap. Finally, you call event_dispatch() to loop and dispatch events.
Once initialized via bufferevent_new(), the bufferevent structure can be used repeatedly with bufferevent_enable() and bufferevent_disable(). Instead of reading and writing directly to a socket, you would call bufferevent_read() and bufferevent_write().
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.evtimer_set() function prepares an event struct to be used as a timer. To activate the timer, call evtimer_add(). Timers can be deactivated by calling evtimer_del().timeout_set() function initializes an event struct for use as a timeout. Once initialized, the event must be activated by using timeout_add(). To cancel the timeout, call timeout_del().evdns.h> header in your program. Before using any of the resolver functions, you must call evdns_init() to initialize the library. To convert a hostname to an IP address, you call the evdns_resolve_ipv4() function. To perform a reverse lookup, you would call the evdns_resolve_reverse() function. All of these functions use callbacks to avoid blocking while the lookup is performed.
To use this capability, you need to include the <evhttp.h> header in your program. You create the server by calling evhttp_new(). Add addresses and ports to listen on with evhttp_bind_socket(). You then register one or more callbacks to handle incoming requests. Each URI can be assigned a callback via the evhttp_set_cb() function. A generic callback function can also be registered via evhttp_set_gencb(); this callback will be invoked if no other callbacks have been registered for a given URI.
event2/event.h The primary libevent header
event2/buffer.h Buffer management for network reading and writing
event2/dns.h Asynchronous DNS resolution
event2/http.h An embedded libevent-based HTTP server
evrpc.h A framework for creating RPC servers and clients