libevent – an event notification library

The libevent API provides a mechanism to execute a callback function when a specific event occurs on a file descriptor or after a timeout has been reached. Furthermore, libevent also support callbacks due to signals or regular timeouts.

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), event ports, POSIX select(2), Windows select(), poll(2), and epoll(4). 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 applications, either by isolating each event_base so that only a single thread accesses it, or by locked access to a single shared event_base. Libevent should compile on Linux, *BSD, Mac OS X, Solaris, Windows, and more.

Libevent additionally provides a sophisticated framework for buffered network IO, with support for sockets, filters, rate-limiting, SSL, zero-copy file transmission, and IOCP. Libevent includes support for several useful protocols, including DNS, HTTP, and a minimal RPC framework.

More information about event notification mechanisms for network servers can be found on Dan Kegel's "The C10K problem" web page. liboop.-->

A mailing list for libevent is now available. Libevent is maintained by Nick Mathewson and Niels Provos.

Documentation

Book: Programming with Libevent.
Reference: 1.4.x-stable 2.0.x-stable 2.1.x-alpha.
What's new in: 2.0.x-stable 2.1.x-alpha. event-test.c -->

Download–Stable releases

These are the ones you probably want for software development, unless you like to track the latest development versions and report bugs in them.

  • libevent-2.0.18-stable.tar.gz [GPG Sig] ChangeLog
    Released 2012-03-22
    • Fix a crash bug in evdns.
    • Fix a class of confusing, hard-to-diagnose kqueue errors.
    • and more...
  • libevent-2.0.17-stable.tar.gz [GPG Sig] ChangeLog
    Released 2012-02-10
    • Fix some subtle crash bugs in signals, win64.
    • Avoid spurious EV_READ events from nonexistent fds when using kqueue.
    • Fix a nasty list-corruption bug in event_reinit().
    • Prevent stalls in filtering SSL connections (Maseeb Abdul Qadir and Mark Ellzey)
    • and more...
  • libevent-2.0.16-stable.tar.gz [GPG Sig] ChangeLog
    Released 2011-11-18
    • Construct an event_base more reliably on Windows when threading is disabled.
    • Fix for a crash in evbuffer_remove_buffer() by Greg Hazel
    • Fixes for CPU-spinning problems during SSL reads by Mark Ellzey
    • and more...
  • libevent-2.0.15-stable.tar.gz [GPG Sig] ChangeLog
    Released 2011-10-12
    • evbuffer_add_file now works with SSL bufferevents
    • DNS fixes from Leonid Evdokimov
    • An evbuffer callback bugfix from Alex
    • Correct behavior for event_base_loop() from a signal event's callback
    • and more...
  • libevent-2.0.14-stable.tar.gz [GPG Sig] ChangeLog
    Released 2011-08-31
    • Several SSL bufferevent fixes from Joachim Bauch
    • A Solaris sendfile bugfix from Michael Herf
    • A few other IOCP and rate-limiting bufferevent fixes
    • Memory leak fixes from Leonid Evdokimov
    • Coverity fixes from Harlan Stenn
    • Portability and build fixes from Dave Hart and Mitchell Livingston
    • and more...
  • libevent-1.4.14b-stable.tar.gz [GPG Sig] ChangeLog
    Released 2010-06-07
    • Backport evbuffer_readln()
    • Fix a crash when reading badly formatted resolve.conf (Yasuoka Masahiko)
    • Make evutil_make_socket_nonblocking() leave any other flags alone (Jardel Weyrich)
    • Adjusted fcntl() retval comparison on evutil_make_socket_nonblocking() (Jardel Weyrich)
    • Re-add event_siglcb; some old code _was_ still using it. :(
    • Make Libevent 1.4 build on win32 with Unicode enabled. (Brodie Thiesfield)
    • Distribute nmake makefile for 1.4
    • Define _REENTRANT as needed on Solaris, elsewhere (6cbea13)
    • Other bugfixes for http, memory management, and cleanup.
  • libevent-1.4.13-stable.tar.gz [GPG Sig] ChangeLog
    Released 2009-11-17
    • If the kernel tells us that there are a negative number of bytes to read from a socket, do not believe it (Alexander Pronchenkov)
    • Use less memory in epoll backend and priority system
    • Do not drop data from evbuffer when out of memory
    • Fix compilation on Android, HPUX, GNU/kFreeBSD
    • When running set[ug]id, don't check the environment
    • and more...

Download–Alpha releases

This is alpha code. If you find any bugs, please let us know!

  • libevent-2.1.1-alpha.tar.gz [GPG Sig] ChangeLog
    Released 2012-04-03
    • First alpha release in the 2.1.x series.
    • Useful features for controlling the event loop and avoiding priority inversion
    • New debugging features.
    • New evbuffer functionality, including an improved sendfile/mmap wrapper, the ability to add one evbuffer to another, and more ways to avoid needless copies.
    • Numerous small performance improvements and data structure tweaks throughout the codebase.
    • and much more...

Older Releases

Libevent has been released under a 3-clause BSD license. Information on public git access.

Benchmark

Performance comparison using different event notification mechansims in Libevent. We declare interest in a large number of connections of which most are cold and only a few are active.
spacer   spacer
The benchmark measures how long it takes to serve one active connection and exposes scalability issues of traditional interfaces like select or poll.   The benchmark measures how long it takes to serve one hundred active connections that chain writes to new connections until thousand writes and reads have happened. It exercises the event loop several times.

Programs using libevent

The usefulness of libevent API is demonstrated by the following applications:
  • Chromium – Google's open-source web browser (uses Libevent on Mac and Linux)
  • Memcached – a high-performance, distributed memory object caching system
  • Transmission – a fast, easy, and free BitTorrent client
  • NTP – the network time protocol that makes your clock right (uses Libevent in SNTP)
  • tmux – A clean, modern, BSD-licensed terminal multiplexer, similar to GNU screen
  • Tor – an anonymous Internet communication system.
  • libevhtp – A fast and flexible replacement for libevent's httpd API
  • Prosody – A Jabber/XMPP server written in Lua
  • PgBouncer – Lightweight connection pooler for PostgreSQL
  • redsocks – a simple transparent TCP -> Socks5/HTTPS proxy daemon.
  • Vomit – Voice Over Misconfigured Internet Telephones
  • Crawl – A Small and Efficient HTTP Crawler
  • Libio – an input/output abstraction library
  • Honeyd – a virtual honeynet daemon – can be used to fight Internet worms.
  • Fragroute – an IDS testing tool
  • Nylon – nested proxy server
  • Disconcert – a Distributed Computing Framework for Loosely-Coupled Workstations.
  • Trickle – a lightweight userspace bandwidth shaper.
  • watchcatd – software watchdog designed to take actions not as drastic as the usual solutions, which reset the machine.
  • ScanSSH – a fast SSH server and open proxy scanner.
  • Nttlscan – a network topology scanner for Honeyd.
  • NetChat – a combination of netcat and ppp's chat.
  • Io – a small programming language; uses libevent for network communication.
  • Systrace – a system call sandbox.
  • SpyBye – detect malware on web pages.
  • GreenSQL – an SQL database firewall.
  • dnsscan – a fast scanner for identifying open recursive dns resolvers
  • Kargo Event – a PHP extension for libevent.
  • wlmproxy – a transparent proxy server for the MSN Messenger protocol

Nick Mathewson
Niels Provos
(Please do not mail us directly for technical support. Instead, please use the mailing list or the IRC channel.)
Last modified: 19 Oct 2011
gipoco.com is neither affiliated with the authors of this page nor responsible for its contents. This is a safe-cache copy of the original web site.