]> git.ipfire.org Git - thirdparty/ntp.git/commitdiff
Update to libevent HEAD as of 20110723, 77a4d7f406be9d78876ba8a1b7c7d834d8998479
authorDave Hart <hart@ntp.org>
Sun, 24 Jul 2011 00:59:52 +0000 (00:59 +0000)
committerDave Hart <hart@ntp.org>
Sun, 24 Jul 2011 00:59:52 +0000 (00:59 +0000)
Snapshot of libevent 2.1, as of 2.0.13-stable-dev release.

bk: 4e2b6e88G7Hnw6zoW3cCmYTp9ZCVjg

55 files changed:
sntp/libevent/ChangeLog
sntp/libevent/Doxyfile
sntp/libevent/Makefile.am
sntp/libevent/README
sntp/libevent/buffer.c
sntp/libevent/buffer_iocp.c
sntp/libevent/bufferevent_openssl.c
sntp/libevent/bufferevent_pair.c
sntp/libevent/evdns.h
sntp/libevent/event-internal.h
sntp/libevent/event.c
sntp/libevent/event.h
sntp/libevent/evhttp.h
sntp/libevent/evmap.c
sntp/libevent/evrpc.h
sntp/libevent/evthread-internal.h
sntp/libevent/evthread.c
sntp/libevent/evutil.c
sntp/libevent/evutil.h
sntp/libevent/evutil_rand.c
sntp/libevent/ht-internal.h
sntp/libevent/http.c
sntp/libevent/include/event2/buffer.h
sntp/libevent/include/event2/buffer_compat.h
sntp/libevent/include/event2/bufferevent.h
sntp/libevent/include/event2/bufferevent_compat.h
sntp/libevent/include/event2/bufferevent_ssl.h
sntp/libevent/include/event2/bufferevent_struct.h
sntp/libevent/include/event2/dns.h
sntp/libevent/include/event2/dns_compat.h
sntp/libevent/include/event2/dns_struct.h
sntp/libevent/include/event2/event.h
sntp/libevent/include/event2/event_compat.h
sntp/libevent/include/event2/event_struct.h
sntp/libevent/include/event2/http.h
sntp/libevent/include/event2/http_compat.h
sntp/libevent/include/event2/http_struct.h
sntp/libevent/include/event2/rpc_compat.h
sntp/libevent/include/event2/rpc_struct.h
sntp/libevent/include/event2/tag.h
sntp/libevent/include/event2/tag_compat.h
sntp/libevent/include/event2/thread.h
sntp/libevent/include/event2/util.h
sntp/libevent/kqueue.c
sntp/libevent/sample/Makefile.am
sntp/libevent/select.c
sntp/libevent/signal.c
sntp/libevent/test/Makefile.am
sntp/libevent/test/Makefile.nmake
sntp/libevent/test/regress_buffer.c
sntp/libevent/test/regress_rpc.c
sntp/libevent/test/regress_util.c
sntp/libevent/test/test.sh
sntp/libevent/test/tinytest.c
sntp/libevent/util-internal.h

index 87f8db9531f6ddbb335e6baaeee59c7f8f594edc..dea8ccda260c90d13e1a181f9b5ff7d41aa7937c 100644 (file)
@@ -1,5 +1,32 @@
-Changes in version 2.0.13-stable (?? Jul 2011)
+Changes in version 2.0.13-stable (18 Jul 2011)
+BUGFIXES
+ o Avoid race-condition when initializing global locks (b683cae)
+ o Fix bug in SSL bufferevents backed by a bev with a write high-watermarks (e050703 Joachim Bauch)
+ o Speed up invoke_callbacks on evbuffers when there are no callbacks (f87f568 Mark Ellzey)
+ o Avoid a segfault when all methods are disabled or broken (27ce38b)
+ o Fix incorrect results from evbuffer_search_eol(EOL_LF) (4461f1a)
+ o Add some missing checks for mm_calloc failures (89d5e09)
+ o Replace an assertion for event_base_free(NULL) with a check-and-warn (09fe97d)
+ o Report kqueue ebadf, epipe, and eperm as EV_READ events (1fd34ab)
+ o Check if the `evhttp_new_object' function in `http.c' returns NULL. (446cc7a Mansour Moufid)
+ o Use the correct printf args when formatting size_t (3203f88)
+ o Complain if the caller tries to change threading cbs after setting them (cb6ecee)
+
+DOCUMENTATION FIXES AND IMPROVEMENTS
+ o Revise the event/evbuffer/bufferevent doxygen for clarity and accuracy (2888fac)
+ o Update Doxyfile to produce more useful output (aea0555)
+
+TEST FIXES
+ o Fix up test_evutil_snprintf (caf695a)
+ o Fix tinytest invocation from windows shell (57def34 Ed Day)
 
+BUILD FIXES
+ o Use AM_CPPFLAGS in sample/Makefile.am, not AM_CFLAGS (4a5c82d)
+ o Fix select.c compilation on systems with no NFDBITS (49d1136)
+ o Fix a few warnings on OpenBSD (8ee9f9c Nicholas Marriott)
+ o Don't break when building tests from git without python installed (b031adf)
+ o Don't install event_rpcgen.py when --disable-libevent-install is used (e23cda3 Harlan Stenn)
+ o Fix AIX build issue with TAILQ_FOREACH definition (e934096)
 
 
 Changes in version 2.0.12-stable (4 Jun 2011)
index 3fc853e5db1910f1a8b12f13ea0e3177d1f7c29b..5d3865e7e793cf298a86fd11494bfff6b6be2131 100644 (file)
@@ -45,6 +45,15 @@ OPTIMIZE_OUTPUT_FOR_C  = YES
 
 SORT_BRIEF_DOCS        = YES
 
+# If the FULL_PATH_NAMES tag is set to YES then the STRIP_FROM_PATH tag 
+# can be used to strip a user-defined part of the path. Stripping is 
+# only done if one of the specified strings matches the left-hand part of 
+# the path. The tag can be used to show relative paths in the file list. 
+# If left blank the directory from which doxygen is run is used as the 
+# path to strip.
+
+STRIP_FROM_PATH        = include/
+
 #---------------------------------------------------------------------------
 # configuration options related to the input files
 #---------------------------------------------------------------------------
@@ -54,21 +63,25 @@ SORT_BRIEF_DOCS        = YES
 # directories like "/usr/src/myproject". Separate the files or directories 
 # with spaces.
 
-INPUT                  = event.h evdns.h evhttp.h evrpc.h \
-                      include/event2/event.h include/event2/event_struct.h \
-                      include/event2/event_compat.h \
-                      include/event2/buffer_compat.h \
-                      include/event2/buffer.h include/event2/thread.h \
-                      include/event2/tag.h include/event2/bufferevent.h \
-                      include/event2/bufferevent_struct.h \
-                      include/event2/bufferevent_compat.h \
-                      include/event2/util.h \
-                      include/event2/rpc.h include/event2/rpc_struct.h \
-                      include/event2/rpc_compat.h \
-                      include/event2/dns.h include/event2/dns_struct.h \
-                      include/event2/dns_compat.h \
-                      include/event2/http.h include/event2/http_struct.h \
-                      include/event2/http_compat.h
+INPUT                  = \
+        include/event2/buffer.h \
+        include/event2/buffer_compat.h \
+        include/event2/bufferevent.h \
+        include/event2/bufferevent_compat.h \
+        include/event2/bufferevent_ssl.h \
+        include/event2/dns.h \
+        include/event2/dns_compat.h \
+        include/event2/event.h \
+        include/event2/event_compat.h \
+        include/event2/http.h \
+        include/event2/http_compat.h \
+        include/event2/listener.h \
+        include/event2/rpc.h \
+        include/event2/rpc_compat.h \
+        include/event2/tag.h \
+        include/event2/tag_compat.h \
+        include/event2/thread.h \
+        include/event2/util.h
 
 #---------------------------------------------------------------------------
 # configuration options related to the HTML output
@@ -140,7 +153,7 @@ PDF_HYPERLINKS         = NO
 # plain latex in the generated Makefile. Set this option to YES to get a 
 # higher quality PDF documentation.
 
-USE_PDFLATEX           = NO
+USE_PDFLATEX           = YES
 
 # If the LATEX_BATCHMODE tag is set to YES, doxygen will add the \\batchmode. 
 # command to the generated LaTeX files. This will instruct LaTeX to keep 
@@ -162,7 +175,7 @@ LATEX_HIDE_INDICES     = NO
 # If the GENERATE_MAN tag is set to YES (the default) Doxygen will 
 # generate man pages
 
-GENERATE_MAN           = YES
+GENERATE_MAN           = NO
 
 # The MAN_EXTENSION tag determines the extension that is added to 
 # the generated man pages (default is the subroutine's section .3)
@@ -226,7 +239,7 @@ INCLUDE_FILE_PATTERNS  =
 # undefined via #undef or recursively expanded use the := operator 
 # instead of the = operator.
 
-PREDEFINED             = TAILQ_ENTRY RB_ENTRY _EVENT_DEFINED_TQENTRY
+PREDEFINED             = TAILQ_ENTRY RB_ENTRY _EVENT_DEFINED_TQENTRY _EVENT_IN_DOXYGEN
 
 # If the MACRO_EXPANSION and EXPAND_ONLY_PREDEF tags are set to YES then 
 # this tag can be used to specify a list of macro names that should be expanded. 
index dae46c247ca48c1c012616e174dc54d8638a4ca3..7847112730ba3dcb51051757d569d601ee1f85a5 100644 (file)
@@ -70,7 +70,9 @@ VERSION_INFO = 1:0:0
 # is user-visible, and so we can pretty much guarantee that release
 # series won't be binary-compatible.
 
+if INSTALL_LIBEVENT
 dist_bin_SCRIPTS = event_rpcgen.py
+endif
 
 pkgconfigdir=$(libdir)/pkgconfig
 LIBEVENT_PKGCONFIG=libevent.pc
@@ -84,6 +86,7 @@ PLATFORM_DEPENDENT_SRC = \
 EXTRA_DIST = \
        LICENSE \
        autogen.sh \
+       event_rpcgen.py \
        libevent.pc.in \
        Doxyfile \
        whatsnew-2.0.txt \
index bed2121a307818ca41642a1ba00113567f3d58ff..1ca99906df0b4c3262308ccb38b9357bfbad78da 100644 (file)
@@ -85,9 +85,11 @@ fixing bugs:
   Tomash Brechko
   Kelly Brock
   Ralph Castain
+  Lawnstein Chan
   Shuo Chen
   Ka-Hing Cheung
   Andrew Danforth
+  Ed Day
   Christopher Davis
   Mike Davis
   Mihai Draghicioiu
index 0a0be15b62582ce16d5b9bdd3d087397aec1adb9..df6402e858d10a29f8011a60a3b27e973f97f29a 100644 (file)
 #define CHAIN_PINNED(ch)  (((ch)->flags & EVBUFFER_MEM_PINNED_ANY) != 0)
 #define CHAIN_PINNED_R(ch)  (((ch)->flags & EVBUFFER_MEM_PINNED_R) != 0)
 
+/* evbuffer_ptr support */
+#define PTR_NOT_FOUND(ptr) do {                        \
+       (ptr)->pos = -1;                                        \
+       (ptr)->_internal.chain = NULL;          \
+       (ptr)->_internal.pos_in_chain = 0;      \
+} while (0)
+
 static void evbuffer_chain_align(struct evbuffer_chain *chain);
 static int evbuffer_chain_should_realign(struct evbuffer_chain *chain,
     size_t datalen);
@@ -428,6 +435,11 @@ evbuffer_run_callbacks(struct evbuffer *buffer, int running_deferred)
 static inline void
 evbuffer_invoke_callbacks(struct evbuffer *buffer)
 {
+       if (TAILQ_EMPTY(&buffer->callbacks)) {
+               buffer->n_add_for_cb = buffer->n_del_for_cb = 0;
+               return;
+       }
+
        if (buffer->deferred_cbs) {
                if (buffer->deferred.queued)
                        return;
@@ -934,10 +946,8 @@ evbuffer_drain(struct evbuffer *buf, size_t len)
                }
 
                buf->first = chain;
-               if (chain) {
-                       chain->misalign += remaining;
-                       chain->off -= remaining;
-               }
+               chain->misalign += remaining;
+               chain->off -= remaining;
        }
 
        buf->n_del_for_cb += len;
@@ -1230,7 +1240,7 @@ evbuffer_strchr(struct evbuffer_ptr *it, const char chr)
                if (cp) {
                        it->_internal.chain = chain;
                        it->_internal.pos_in_chain = cp - buffer;
-                       it->pos += (cp - buffer);
+                       it->pos += (cp - buffer - i);
                        return it->pos;
                }
                it->pos += chain->off - i;
@@ -1299,7 +1309,7 @@ evbuffer_strspn(
        size_t i = ptr->_internal.pos_in_chain;
 
        if (!chain)
-               return -1;
+               return 0;
 
        while (1) {
                char *buffer = (char *)chain->buffer + chain->misalign;
@@ -1330,13 +1340,16 @@ evbuffer_strspn(
 }
 
 
-static inline char
+static inline int
 evbuffer_getchr(struct evbuffer_ptr *it)
 {
        struct evbuffer_chain *chain = it->_internal.chain;
        size_t off = it->_internal.pos_in_chain;
 
-       return chain->buffer[chain->misalign + off];
+       if (chain == NULL)
+               return -1;
+
+       return (unsigned char)chain->buffer[chain->misalign + off];
 }
 
 struct evbuffer_ptr
@@ -1348,6 +1361,14 @@ evbuffer_search_eol(struct evbuffer *buffer,
        size_t extra_drain = 0;
        int ok = 0;
 
+       /* Avoid locking in trivial edge cases */
+       if (start && start->_internal.chain == NULL) {
+               PTR_NOT_FOUND(&it);
+               if (eol_len_out)
+                       *eol_len_out = extra_drain;
+               return it;
+       }
+
        EVBUFFER_LOCK(buffer);
 
        if (start) {
@@ -1374,13 +1395,15 @@ evbuffer_search_eol(struct evbuffer *buffer,
                extra_drain = 2;
                break;
        }
-       case EVBUFFER_EOL_CRLF:
+       case EVBUFFER_EOL_CRLF: {
+               ev_ssize_t start_pos = it.pos;
                /* Look for a LF ... */
                if (evbuffer_strchr(&it, '\n') < 0)
                        goto done;
                extra_drain = 1;
                /* ... optionally preceeded by a CR. */
-               if (it.pos < 1) break;
+               if (it.pos == start_pos)
+                       break; /* If the first character is \n, don't back up */
                /* This potentially does an extra linear walk over the first
                 * few chains.  Probably, that's not too expensive unless you
                 * have a really pathological setup. */
@@ -1392,6 +1415,7 @@ evbuffer_search_eol(struct evbuffer *buffer,
                        extra_drain = 2;
                }
                break;
+       }
        case EVBUFFER_EOL_LF:
                if (evbuffer_strchr(&it, '\n') < 0)
                        goto done;
@@ -1405,9 +1429,8 @@ evbuffer_search_eol(struct evbuffer *buffer,
 done:
        EVBUFFER_UNLOCK(buffer);
 
-       if (!ok) {
-               it.pos = -1;
-       }
+       if (!ok)
+               PTR_NOT_FOUND(&it);
        if (eol_len_out)
                *eol_len_out = extra_drain;
 
@@ -2288,7 +2311,7 @@ evbuffer_ptr_subtract(struct evbuffer *buf, struct evbuffer_ptr *pos,
 {
        if (howfar > (size_t)pos->pos)
                return -1;
-       if (howfar <= pos->_internal.pos_in_chain) {
+       if (pos->_internal.chain && howfar <= pos->_internal.pos_in_chain) {
                pos->_internal.pos_in_chain -= howfar;
                pos->pos -= howfar;
                return 0;
@@ -2306,6 +2329,7 @@ evbuffer_ptr_set(struct evbuffer *buf, struct evbuffer_ptr *pos,
 {
        size_t left = position;
        struct evbuffer_chain *chain = NULL;
+       int result = 0;
 
        EVBUFFER_LOCK(buf);
 
@@ -2332,14 +2356,18 @@ evbuffer_ptr_set(struct evbuffer *buf, struct evbuffer_ptr *pos,
        if (chain) {
                pos->_internal.chain = chain;
                pos->_internal.pos_in_chain = position + left;
-       } else {
+       } else if (left == 0) {
+               /* The first byte in the (nonexistent) chain after the last chain */
                pos->_internal.chain = NULL;
-               pos->pos = -1;
+               pos->_internal.pos_in_chain = 0;
+       } else {
+               PTR_NOT_FOUND(pos);
+               result = -1;
        }
 
        EVBUFFER_UNLOCK(buf);
 
-       return chain != NULL ? 0 : -1;
+       return result;
 }
 
 /**
@@ -2444,8 +2472,7 @@ evbuffer_search_range(struct evbuffer *buffer, const char *what, size_t len, con
        }
 
 not_found:
-       pos.pos = -1;
-       pos._internal.chain = NULL;
+       PTR_NOT_FOUND(&pos);
 done:
        EVBUFFER_UNLOCK(buffer);
        return pos;
@@ -2460,6 +2487,10 @@ evbuffer_peek(struct evbuffer *buffer, ev_ssize_t len,
        int idx = 0;
        ev_ssize_t len_so_far = 0;
 
+       /* Avoid locking in trivial edge cases */
+       if (start_at && start_at->_internal.chain == NULL)
+               return 0;
+
        EVBUFFER_LOCK(buffer);
 
        if (start_at) {
index 54289879bfaf59c5fc413e62cf601f297106dbf0..f59b42a3e0ba4f363da4f2a9eb313d3aa11e05b5 100644 (file)
@@ -151,6 +151,8 @@ evbuffer_overlapped_new(evutil_socket_t fd)
        struct evbuffer_overlapped *evo;
 
        evo = mm_calloc(1, sizeof(struct evbuffer_overlapped));
+       if (!evo)
+               return NULL;
 
        TAILQ_INIT(&evo->buffer.callbacks);
        evo->buffer.refcnt = 1;
index fcc733bf8a74162b376551a9625852d55c44c943..2a448cdc3d040d6192b75f6bd5314f360dc140b4 100644 (file)
@@ -171,8 +171,8 @@ bio_bufferevent_write(BIO *b, const char *in, int inlen)
 
        /* Copy only as much data onto the output buffer as can fit under the
         * high-water mark. */
-       if (bufev->wm_write.high && bufev->wm_write.high >= (outlen+inlen)) {
-               if (bufev->wm_write.high >= outlen) {
+       if (bufev->wm_write.high && bufev->wm_write.high <= (outlen+inlen)) {
+               if (bufev->wm_write.high <= outlen) {
                        /* If no data can fit, we'll need to retry later. */
                        BIO_set_retry_write(b);
                        return -1;
index 40fee940d59aa288d21899b0be4861377c329cce..33f85e7e47ddb19b03eacd3238b0e9b54522a6c8 100644 (file)
@@ -158,7 +158,7 @@ be_pair_transfer(struct bufferevent *src, struct bufferevent *dst,
        evbuffer_unfreeze(dst->input, 0);
 
        if (dst->wm_read.high) {
-               size_t dst_size = evbuffer_get_length(dst->input);
+               dst_size = evbuffer_get_length(dst->input);
                if (dst_size < dst->wm_read.high) {
                        n = dst->wm_read.high - dst_size;
                        evbuffer_remove_buffer(src->output, dst->input, n);
index 0f50c4adb5816fb54c476aca92612bbc0b8e7309..f5aa91c40e549b7084e396e5a50dc8985e03b6ed 100644 (file)
 #ifndef _EVDNS_H_
 #define _EVDNS_H_
 
+/** @file evdns.h
+
+  A dns subsystem for Libevent.
+
+  The <evdns.h> header is deprecated in Libevent 2.0 and later; please
+  use <event2/evdns.h> instead.  Depending on what functionality you
+  need, you may also want to include more of the other event2/*.h
+  headers.
+ */
+
 #include <event.h>
 #include <event2/dns.h>
 #include <event2/dns_compat.h>
index 386333dad98512eb9ac83ab529b94aca1bec2fc1..0fc3216bf9bd0fe5170e46330acaa971cf83b928 100644 (file)
@@ -315,10 +315,12 @@ struct event_config {
 #define        TAILQ_NEXT(elm, field)          ((elm)->field.tqe_next)
 #endif
 
+#ifndef TAILQ_FOREACH
 #define TAILQ_FOREACH(var, head, field)                                        \
        for ((var) = TAILQ_FIRST(head);                                 \
             (var) != TAILQ_END(head);                                  \
             (var) = TAILQ_NEXT(var, field))
+#endif
 
 #ifndef TAILQ_INSERT_BEFORE
 #define        TAILQ_INSERT_BEFORE(listelm, elm, field) do {                   \
@@ -337,6 +339,7 @@ int _evsig_set_handler(struct event_base *base, int evsignal,
                          void (*fn)(int));
 int _evsig_restore_handler(struct event_base *base, int evsignal);
 
+
 void event_active_nolock(struct event *ev, int res, short count);
 
 /* FIXME document. */
index 62ec7f546044e81a827c4a01152b4ddc1f09091d..4cc97e4b68038c6fa1d44035c854fa80c3b08d91 100644 (file)
@@ -183,7 +183,9 @@ eq_debug_entry(const struct event_debug_entry *a,
 int _event_debug_mode_on = 0;
 /* Set if it's too late to enable event_debug_mode. */
 static int event_debug_mode_too_late = 0;
+#ifndef _EVENT_DISABLE_THREAD_SUPPORT
 static void *_event_debug_map_lock = NULL;
+#endif
 static HT_HEAD(event_debug_map, event_debug_entry) global_debug_map =
        HT_INITIALIZER();
 
@@ -515,8 +517,6 @@ event_enable_debug_mode(void)
        _event_debug_mode_on = 1;
 
        HT_INIT(event_debug_map, &global_debug_map);
-
-       EVTHREAD_ALLOC_LOCK(_event_debug_map_lock, 0);
 #endif
 }
 
@@ -546,9 +546,6 @@ event_base_new_with_config(const struct event_config *cfg)
 
 #ifndef _EVENT_DISABLE_DEBUG_MODE
        event_debug_mode_too_late = 1;
-       if (_event_debug_mode_on && !_event_debug_map_lock) {
-               EVTHREAD_ALLOC_LOCK(_event_debug_map_lock, 0);
-       }
 #endif
 
        if ((base = mm_calloc(1, sizeof(struct event_base))) == NULL) {
@@ -682,13 +679,19 @@ event_base_free(struct event_base *base)
        /* XXXX grab the lock? If there is contention when one thread frees
         * the base, then the contending thread will be very sad soon. */
 
+       /* event_base_free(NULL) is how to free the current_base if we
+        * made it with event_init and forgot to hold a reference to it. */
        if (base == NULL && current_base)
                base = current_base;
+       /* If we're freeing current_base, there won't be a current_base. */
        if (base == current_base)
                current_base = NULL;
-
+       /* Don't actually free NULL. */
+       if (base == NULL) {
+               event_warnx("%s: no base to free", __func__);
+               return;
+       }
        /* XXX(niels) - check for internal events first */
-       EVUTIL_ASSERT(base);
 
 #ifdef _WIN32
        event_base_stop_iocp(base);
@@ -2818,3 +2821,18 @@ event_base_del_virtual(struct event_base *base)
                evthread_notify_base(base);
        EVBASE_RELEASE_LOCK(base, th_base_lock);
 }
+
+#ifndef _EVENT_DISABLE_THREAD_SUPPORT
+int
+event_global_setup_locks_(const int enable_locks)
+{
+#ifndef _EVENT_DISABLE_DEBUG_MODE
+       EVTHREAD_SETUP_GLOBAL_LOCK(_event_debug_map_lock, 0);
+#endif
+       if (evsig_global_setup_locks_(enable_locks) < 0)
+               return -1;
+       if (evutil_secure_rng_global_setup_locks_(enable_locks) < 0)
+               return -1;
+       return 0;
+}
+#endif
index fda6b391b2fdd13314b061004054e2499a4a38c4..cf59a0f237809fcf7739872ec27001371a769992 100644 (file)
 #ifndef _EVENT_H_
 #define _EVENT_H_
 
-/** @mainpage
+/** @file event.h
 
-  @section intro Introduction
-
-  libevent is an event notification library for developing scalable network
-  servers.  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), 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 applications; see Steven Grimm's explanation. Libevent should
-  compile on Linux, *BSD, Mac OS X, Solaris and Windows.
-
-  @section usage Standard usage
-
-  Every program that uses libevent must include the <event.h> header, and pass
-  the -levent flag to the linker.  Before using any of the functions in the
-  library, you must call event_init() or event_base_new() to perform one-time
-  initialization of the libevent library.
-
-  @section event Event notification
-
-  For each file descriptor that you wish to monitor, you must declare an event
-  structure and call 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.
-
-  @section bufferevent I/O Buffers
-
-  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 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.
-
-  @section timers Timers
-
-  libevent can also be used to create timers that invoke a callback after a
-  certain amount of time has expired. The 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().
-
-  @section timeouts Timeouts
-
-  In addition to simple timers, libevent can assign timeout events to file
-  descriptors that are triggered whenever a certain amount of time has passed
-  with no activity on a file descriptor.  The 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().
-
-  @section evdns Asynchronous DNS resolution
-
-  libevent provides an asynchronous DNS resolver that should be used instead
-  of the standard DNS resolver functions.  These functions can be imported by
-  including the <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.
-
-  @section evhttp Event-driven HTTP servers
-
-  libevent provides a very simple event-driven HTTP server that can be
-  embedded in your program and used to service HTTP requests.
-
-  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.
-
-  @section evrpc A framework for RPC servers and clients
-
-  libevent provides a framework for creating RPC servers and clients.  It
-  takes care of marshaling and unmarshaling all data structures.
-
-  @section api API Reference
-
-  To browse the complete documentation of the libevent API, click on any of
-  the following links.
-
-  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
-
- */
-
-/** @file libevent/event.h
-
-  A library for writing event-driven network servers
+  A library for writing event-driven network servers.
 
+  The <event.h> header is deprecated in Libevent 2.0 and later; please
+  use <event2/event.h> instead.  Depending on what functionality you
+  need, you may also want to include more of the other event2/
+  headers.
  */
 
 #ifdef __cplusplus
index 99bc4da5f6792d31dce6aad8340cfc75270251c3..1707aa7f082bd95e6b17ec4a0de6ca12395602c4 100644 (file)
 #ifndef _EVHTTP_H_
 #define _EVHTTP_H_
 
+/** @file evhttp.h
+
+  An http implementation subsystem for Libevent.
+
+  The <evhttp.h> header is deprecated in Libevent 2.0 and later; please
+  use <event2/http.h> instead.  Depending on what functionality you
+  need, you may also want to include more of the other event2/*.h
+  headers.
+ */
+
 #include <event.h>
 #include <event2/http.h>
 #include <event2/http_struct.h>
index 8af448ea834782d2e053aeeeaa90c558000f5e02..626bfb7d7654a104c8937f5b2a6ea9a6dd055777 100644 (file)
@@ -128,7 +128,8 @@ HT_GENERATE(event_io_map, event_map_entry, map_node, hashsocket, eqsocket,
                    },                                                  \
                    {                                                   \
                            _ent = mm_calloc(1,sizeof(struct event_map_entry)+fdinfo_len); \
-                           EVUTIL_ASSERT(_ent);                                \
+                           if (EVUTIL_UNLIKELY(_ent == NULL))          \
+                                   return (-1);                        \
                            _ent->fd = slot;                            \
                            (ctor)(&_ent->ent.type);                    \
                            _HT_FOI_INSERT(map_node, map, &_key, _ent, ptr) \
@@ -160,14 +161,16 @@ void evmap_io_clear(struct event_io_map *ctx)
        (x) = (struct type *)((map)->entries[slot])
 /* As GET_SLOT, but construct the entry for 'slot' if it is not present,
    by allocating enough memory for a 'struct type', and initializing the new
-   value by calling the function 'ctor' on it.
+   value by calling the function 'ctor' on it.  Makes the function
+   return -1 on allocation failure.
  */
 #define GET_SIGNAL_SLOT_AND_CTOR(x, map, slot, type, ctor, fdinfo_len) \
        do {                                                            \
                if ((map)->entries[slot] == NULL) {                     \
                        (map)->entries[slot] =                          \
                            mm_calloc(1,sizeof(struct type)+fdinfo_len); \
-                       EVUTIL_ASSERT((map)->entries[slot] != NULL);            \
+                       if (EVUTIL_UNLIKELY((map)->entries[slot] == NULL)) \
+                               return (-1);                            \
                        (ctor)((struct type *)(map)->entries[slot]);    \
                }                                                       \
                (x) = (struct type *)((map)->entries[slot]);            \
index 92147d8da3a549ab85bfae0c4e1612be33939ffe..a9f85d7b3f1a855ee3e24a791a00703294857f85 100644 (file)
 #ifndef _EVRPC_H_
 #define _EVRPC_H_
 
+/** @file evrpc.h
+
+  An RPC system for Libevent.
+
+  The <evrpc.h> header is deprecated in Libevent 2.0 and later; please
+  use <event2/rpc.h> instead.  Depending on what functionality you
+  need, you may also want to include more of the other event2/*.h
+  headers.
+ */
+
 #include <event.h>
 #include <event2/rpc.h>
 #include <event2/rpc_struct.h>
index da6184c4845954b52e22dd69947900cf2c0d749e..793b5eae65156d7a865fff325c14a2a997d242b8 100644 (file)
@@ -347,6 +347,24 @@ EVLOCK_TRY_LOCK(void *lock)
 
 int _evthread_is_debug_lock_held(void *lock);
 void *_evthread_debug_get_real_lock(void *lock);
+
+void *evthread_setup_global_lock_(void *lock_, unsigned locktype,
+    int enable_locks);
+
+#define EVTHREAD_SETUP_GLOBAL_LOCK(lockvar, locktype)                  \
+       do {                                                            \
+               lockvar = evthread_setup_global_lock_(lockvar,          \
+                   (locktype), enable_locks);                          \
+               if (!lockvar) {                                         \
+                       event_warn("Couldn't allocate %s", #lockvar);   \
+                       return -1;                                      \
+               }                                                       \
+       } while (0);
+
+int event_global_setup_locks_(const int enable_locks);
+int evsig_global_setup_locks_(const int enable_locks);
+int evutil_secure_rng_global_setup_locks_(const int enable_locks);
+
 #endif
 
 #ifdef __cplusplus
index 37621dd882c99db84fcfdae62537402f0db12baa..22d09ae4de19bb16db9a29f5abb363526ecdc226 100644 (file)
@@ -77,12 +77,25 @@ evthread_set_lock_callbacks(const struct evthread_lock_callbacks *cbs)
            ? &_original_lock_fns : &_evthread_lock_fns;
 
        if (!cbs) {
+               if (target->alloc)
+                       event_warnx("Trying to disable lock functions after "
+                           "they have been set up will probaby not work.");
                memset(target, 0, sizeof(_evthread_lock_fns));
                return 0;
        }
+       if (target->alloc) {
+               /* Uh oh; we already had locking callbacks set up.*/
+               if (!memcmp(target, cbs, sizeof(_evthread_lock_fns))) {
+                       /* no change -- allow this. */
+                       return 0;
+               }
+               event_warnx("Can't change lock callbacks once they have been "
+                   "initialized.");
+               return -1;
+       }
        if (cbs->alloc && cbs->free && cbs->lock && cbs->unlock) {
                memcpy(target, cbs, sizeof(_evthread_lock_fns));
-               return 0;
+               return event_global_setup_locks_(1);
        } else {
                return -1;
        }
@@ -96,8 +109,24 @@ evthread_set_condition_callbacks(const struct evthread_condition_callbacks *cbs)
            ? &_original_cond_fns : &_evthread_cond_fns;
 
        if (!cbs) {
+               if (target->alloc_condition)
+                       event_warnx("Trying to disable condition functions "
+                           "after they have been set up will probaby not "
+                           "work.");
                memset(target, 0, sizeof(_evthread_cond_fns));
-       } else if (cbs->alloc_condition && cbs->free_condition &&
+               return 0;
+       }
+       if (target->alloc_condition) {
+               /* Uh oh; we already had condition callbacks set up.*/
+               if (!memcmp(target, cbs, sizeof(_evthread_cond_fns))) {
+                       /* no change -- allow this. */
+                       return 0;
+               }
+               event_warnx("Can't change condition callbacks once they "
+                   "have been initialized.");
+               return -1;
+       }
+       if (cbs->alloc_condition && cbs->free_condition &&
            cbs->signal_condition && cbs->wait_condition) {
                memcpy(target, cbs, sizeof(_evthread_cond_fns));
        }
@@ -259,6 +288,9 @@ evthread_enable_lock_debuging(void)
            sizeof(struct evthread_condition_callbacks));
        _evthread_cond_fns.wait_condition = debug_cond_wait;
        _evthread_lock_debugging_enabled = 1;
+
+       /* XXX return value should get checked. */
+       event_global_setup_locks_(0);
 }
 
 int
@@ -282,6 +314,62 @@ _evthread_debug_get_real_lock(void *lock_)
        return lock->lock;
 }
 
+void *
+evthread_setup_global_lock_(void *lock_, unsigned locktype, int enable_locks)
+{
+       /* there are four cases here:
+          1) we're turning on debugging; locking is not on.
+          2) we're turning on debugging; locking is on.
+          3) we're turning on locking; debugging is not on.
+          4) we're turning on locking; debugging is on. */
+
+       if (!enable_locks && _original_lock_fns.alloc == NULL) {
+               /* Case 1: allocate a debug lock. */
+               EVUTIL_ASSERT(lock_ == NULL);
+               return debug_lock_alloc(locktype);
+       } else if (!enable_locks && _original_lock_fns.alloc != NULL) {
+               /* Case 2: wrap the lock in a debug lock. */
+               struct debug_lock *lock;
+               EVUTIL_ASSERT(lock_ != NULL);
+
+               if (!(locktype & EVTHREAD_LOCKTYPE_RECURSIVE)) {
+                       /* We can't wrap it: We need a recursive lock */
+                       _original_lock_fns.free(lock_, locktype);
+                       return debug_lock_alloc(locktype);
+               }
+               lock = mm_malloc(sizeof(struct debug_lock));
+               if (!lock) {
+                       _original_lock_fns.free(lock_, locktype);
+                       return NULL;
+               }
+               lock->lock = lock_;
+               lock->locktype = locktype;
+               lock->count = 0;
+               lock->held_by = 0;
+               return lock;
+       } else if (enable_locks && ! _evthread_lock_debugging_enabled) {
+               /* Case 3: allocate a regular lock */
+               EVUTIL_ASSERT(lock_ == NULL);
+               return _evthread_lock_fns.alloc(locktype);
+       } else {
+               /* Case 4: Fill in a debug lock with a real lock */
+               struct debug_lock *lock = lock_;
+               EVUTIL_ASSERT(enable_locks &&
+                             _evthread_lock_debugging_enabled);
+               EVUTIL_ASSERT(lock->locktype == locktype);
+               EVUTIL_ASSERT(lock->lock == NULL);
+               lock->lock = _original_lock_fns.alloc(
+                       locktype|EVTHREAD_LOCKTYPE_RECURSIVE);
+               if (!lock->lock) {
+                       lock->count = -200;
+                       mm_free(lock);
+                       return NULL;
+               }
+               return lock;
+       }
+}
+
+
 #ifndef EVTHREAD_EXPOSE_STRUCTS
 unsigned long
 _evthreadimpl_get_id()
index 605bfa4bcd6fb500550eed963bfd9b810d59a301..a8dfb4c32864981df6d7c2cf4315b86ec47de696 100644 (file)
 #include <limits.h>
 #include <stdio.h>
 #include <string.h>
-#ifdef _EVENT_HAVE_ARPA_INET_H
-#include <arpa/inet.h>
-#endif
 #ifdef _EVENT_HAVE_NETINET_IN_H
 #include <netinet/in.h>
 #endif
 #ifdef _EVENT_HAVE_NETINET_IN6_H
 #include <netinet/in6.h>
 #endif
+#ifdef _EVENT_HAVE_ARPA_INET_H
+#include <arpa/inet.h>
+#endif
 
 #ifndef _EVENT_HAVE_GETTIMEOFDAY
 #include <sys/timeb.h>
index cb3754a789c8606864a2aa36668b529d30a07614..efa2b4241bd6cf3f508bf2f0f3a40ec172a4a8c7 100644 (file)
 #ifndef _EVUTIL_H_
 #define _EVUTIL_H_
 
+/** @file evutil.h
+
+  Utility and compatibility functions for Libevent.
+
+  The <evutil.h> header is deprecated in Libevent 2.0 and later; please
+  use <event2/util.h> instead.
+*/
+
 #include <event2/util.h>
 
 #endif /* _EVUTIL_H_ */
index 85cd3e9ceb4dfd8df610206b6eb863e1649ffefa..9b42f52a97c61b551d04c3056f7f9acc12872057 100644 (file)
@@ -50,6 +50,11 @@ evutil_secure_rng_init(void)
        (void) arc4random();
        return 0;
 }
+int
+evutil_secure_rng_global_setup_locks_(const int enable_locks)
+{
+       return 0;
+}
 
 #ifndef _EVENT_HAVE_ARC4RANDOM_BUF
 static void
@@ -85,7 +90,9 @@ arc4random_buf(void *buf, size_t n)
 #define ARC4RANDOM_EXPORT static
 #define _ARC4_LOCK() EVLOCK_LOCK(arc4rand_lock, 0)
 #define _ARC4_UNLOCK() EVLOCK_UNLOCK(arc4rand_lock, 0)
+#ifndef _EVENT_DISABLE_THREAD_SUPPORT
 static void *arc4rand_lock;
+#endif
 
 #define ARC4RANDOM_UINT32 ev_uint32_t
 #define ARC4RANDOM_NOSTIR
@@ -94,13 +101,19 @@ static void *arc4rand_lock;
 
 #include "./arc4random.c"
 
+#ifndef _EVENT_DISABLE_THREAD_SUPPORT
+int
+evutil_secure_rng_global_setup_locks_(const int enable_locks)
+{
+       EVTHREAD_SETUP_GLOBAL_LOCK(arc4rand_lock, 0);
+       return 0;
+}
+#endif
+
 int
 evutil_secure_rng_init(void)
 {
        int val;
-       if (!arc4rand_lock) {
-               EVTHREAD_ALLOC_LOCK(arc4rand_lock, 0);
-       }
 
        _ARC4_LOCK();
        if (!arc4_seeded_ok)
index 57624af7242afb661e78acf280f34eb99f84873b..d20e14df82a52c453e5de535d85c4d17529846d8 100644 (file)
@@ -223,7 +223,6 @@ ht_string_hash(const char *s)
                        void *data)                                      \
   {                                                                     \
     unsigned idx;                                                       \
-    int remove;                                                         \
     struct type **p, **nextp, *next;                                    \
     if (!head->hth_table)                                               \
       return;                                                           \
@@ -232,8 +231,7 @@ ht_string_hash(const char *s)
       while (*p) {                                                      \
         nextp = &(*p)->field.hte_next;                                  \
         next = *nextp;                                                  \
-        remove = fn(*p, data);                                          \
-        if (remove) {                                                   \
+        if (fn(*p, data)) {                                             \
           --head->hth_n_entries;                                        \
           *p = next;                                                    \
         } else {                                                        \
index 540c21d02b998f2bd9e5dbf0fdbbe104965f3a77..200b31fcce170bc913c3a774a445ff74cd2de7a3 100644 (file)
@@ -460,8 +460,8 @@ evhttp_make_header_request(struct evhttp_connection *evcon,
        if ((req->type == EVHTTP_REQ_POST || req->type == EVHTTP_REQ_PUT) &&
            evhttp_find_header(req->output_headers, "Content-Length") == NULL){
                char size[22];
-               evutil_snprintf(size, sizeof(size), "%ld",
-                   (long)evbuffer_get_length(req->output_buffer));
+               evutil_snprintf(size, sizeof(size), EV_SIZE_FMT,
+                   EV_SIZE_ARG(evbuffer_get_length(req->output_buffer)));
                evhttp_add_header(req->output_headers, "Content-Length", size);
        }
 }
@@ -519,12 +519,13 @@ evhttp_maybe_add_date_header(struct evkeyvalq *headers)
  * unless it already has a content-length or transfer-encoding header. */
 static void
 evhttp_maybe_add_content_length_header(struct evkeyvalq *headers,
-    long content_length) /* XXX use size_t or int64, not long. */
+    size_t content_length)
 {
        if (evhttp_find_header(headers, "Transfer-Encoding") == NULL &&
            evhttp_find_header(headers, "Content-Length") == NULL) {
                char len[22];
-               evutil_snprintf(len, sizeof(len), "%ld", content_length);
+               evutil_snprintf(len, sizeof(len), EV_SIZE_FMT,
+                   EV_SIZE_ARG(content_length));
                evhttp_add_header(headers, "Content-Length", len);
        }
 }
@@ -564,7 +565,7 @@ evhttp_make_header_response(struct evhttp_connection *evcon,
                         */
                        evhttp_maybe_add_content_length_header(
                                req->output_headers,
-                               (long)evbuffer_get_length(req->output_buffer));
+                               evbuffer_get_length(req->output_buffer));
                }
        }
 
@@ -1077,9 +1078,10 @@ evhttp_read_cb(struct bufferevent *bufev, void *arg)
 
                        input = bufferevent_get_input(evcon->bufev);
                        total_len = evbuffer_get_length(input);
-                       event_debug(("%s: read %d bytes in EVCON_IDLE state,"
-                                    " resetting connection",
-                                       __func__, (int)total_len));
+                       event_debug(("%s: read "EV_SIZE_FMT
+                               " bytes in EVCON_IDLE state,"
+                               " resetting connection",
+                               __func__, EV_SIZE_ARG(total_len)));
 #endif
 
                        evhttp_connection_reset(evcon);
@@ -1961,9 +1963,9 @@ evhttp_get_body_length(struct evhttp_request *req)
                req->ntoread = ntoread;
        }
 
-       event_debug(("%s: bytes to read: %ld (in buffer %ld)\n",
-               __func__, (long)req->ntoread,
-               evbuffer_get_length(bufferevent_get_input(req->evcon->bufev))));
+       event_debug(("%s: bytes to read: "EV_I64_FMT" (in buffer "EV_SIZE_FMT")\n",
+               __func__, EV_I64_ARG(req->ntoread),
+               EV_SIZE_ARG(evbuffer_get_length(bufferevent_get_input(req->evcon->bufev)))));
 
        return (0);
 }
@@ -3309,8 +3311,11 @@ evhttp_new_object(void)
 struct evhttp *
 evhttp_new(struct event_base *base)
 {
-       struct evhttp *http = evhttp_new_object();
+       struct evhttp *http = NULL;
 
+       http = evhttp_new_object();
+       if (http == NULL)
+               return (NULL);
        http->base = base;
 
        return (http);
@@ -3323,8 +3328,11 @@ evhttp_new(struct event_base *base)
 struct evhttp *
 evhttp_start(const char *address, unsigned short port)
 {
-       struct evhttp *http = evhttp_new_object();
+       struct evhttp *http = NULL;
 
+       http = evhttp_new_object();
+       if (http == NULL)
+               return (NULL);
        if (evhttp_bind_socket(http, address, port) == -1) {
                mm_free(http);
                return (NULL);
index 7e2fc3152cff66926e0c20874420dddad639adc3..66cd3d13c0e7dfeee529009e938689495998a32d 100644 (file)
 #ifndef _EVENT2_BUFFER_H_
 #define _EVENT2_BUFFER_H_
 
-/** @file buffer.h
+/** @file event2/buffer.h
 
   Functions for buffering data for network sending or receiving.
 
   An evbuffer can be used for preparing data before sending it to
   the network or conversely for reading data from the network.
   Evbuffers try to avoid memory copies as much as possible.  As a
-  result evbuffers can be used to pass data around without actually
+  result, evbuffers can be used to pass data around without actually
   incurring the overhead of copying the data.
 
   A new evbuffer can be allocated with evbuffer_new(), and can be
-  freed with evbuffer_free().
+  freed with evbuffer_free().  Most users will be using evbuffers via
+  the bufferevent interface.  To access a bufferevent's evbuffers, use
+  bufferevent_get_input() and bufferevent_get_output().
 
-  There are several guide lines for using evbuffers.
+  There are several guidelines for using evbuffers.
 
   - if you already know how much data you are going to add as a result
     of calling evbuffer_add() multiple times, it makes sense to use
     if you use them, you will wind up with fragmented memory in your
        buffer.
 
-  As the contents of an evbuffer can be stored into multiple different
+  - For high-performance code, you may want to avoid copying data into and out
+    of buffers.  You can skip the copy step by using
+    evbuffer_reserve_space()/evbuffer_commit_space() when writing into a
+    buffer, and evbuffer_peek() when reading.
+
+  In Libevent 2.0 and later, evbuffers are represented using a linked
+  list of memory chunks, with pointers to the first and last chunk in
+  the chain.
+
+  As the contents of an evbuffer can be stored in multiple different
   memory blocks, it cannot be accessed directly.  Instead, evbuffer_pullup()
-  can be used to force a specified number of bytes to be continuous. This
+  can be used to force a specified number of bytes to be contiguous. This
   will cause memory reallocation and memory copies if the data is split
-  across multiple blocks.
-
+  across multiple blocks.  It is more efficient, however, to use
+  evbuffer_peek() if you don't require that the memory to be contiguous.
  */
 
 #ifdef __cplusplus
@@ -75,17 +86,41 @@ extern "C" {
 #endif
 #include <event2/util.h>
 
-struct evbuffer;
+/**
+   An evbuffer is an opaque data type for efficiently buffering data to be
+   sent or received on the network.
+
+   @see event2/event.h for more information
+*/
+struct evbuffer
+#ifdef _EVENT_IN_DOXYGEN
+{}
+#endif
+;
+
+/**
+    Pointer to a position within an evbuffer.
+
+    Used when repeatedly searching through a buffer.  Calling any function
+    that modifies or re-packs the buffer contents may invalidate all
+    evbuffer_ptrs for that buffer.  Do not modify these values except with
+    evbuffer_ptr_set.
+
+    Used when repeatedly searching through a buffer.  Calls to any function
+    that modifies or re-packs the buffer contents may invalidate all
+    evbuffer_ptrs for that buffer.  Do not modify these values except with
+    evbuffer_ptr_set.
 
-/** Points to a position within an evbuffer. Used when repeatedly searching
-    through a buffer.  Calls to any function that modifies or re-packs the
-    buffer contents may invalidate all evbuffer_ptrs for that buffer.  Do not
-    modify these values except with evbuffer_ptr_set.
+    An evbuffer_ptr can represent any position from the start of a buffer up
+    to a position immediately after the end of a buffer.
+
+    @see evbuffer_ptr_set()
  */
 struct evbuffer_ptr {
        ev_ssize_t pos;
 
-       /* Do not alter the values of fields. */
+       /* Do not alter or rely on the values of fields: they are for internal
+        * use */
        struct {
                void *chain;
                size_t pos_in_chain;
@@ -118,7 +153,6 @@ struct evbuffer_iovec {
  */
 struct evbuffer *evbuffer_new(void);
 
-
 /**
   Deallocate storage for an evbuffer.
 
@@ -153,10 +187,10 @@ void evbuffer_lock(struct evbuffer *buf);
 void evbuffer_unlock(struct evbuffer *buf);
 
 /**
-  Returns the total number of bytes stored in the event buffer
+  Returns the total number of bytes stored in the evbuffer
 
   @param buf pointer to the evbuffer
-  @return the number of bytes stored in the event buffer
+  @return the number of bytes stored in the evbuffer
 */
 size_t evbuffer_get_length(const struct evbuffer *buf);
 
@@ -175,28 +209,28 @@ size_t evbuffer_get_length(const struct evbuffer *buf);
 size_t evbuffer_get_contiguous_space(const struct evbuffer *buf);
 
 /**
-  Expands the available space in an event buffer.
+  Expands the available space in an evbuffer.
 
-  Expands the available space in the event buffer to at least datlen, so that
+  Expands the available space in the evbuffer to at least datlen, so that
   appending datlen additional bytes will not require any new allocations.
 
-  @param buf the event buffer to be expanded
+  @param buf the evbuffer to be expanded
   @param datlen the new minimum length requirement
   @return 0 if successful, or -1 if an error occurred
 */
 int evbuffer_expand(struct evbuffer *buf, size_t datlen);
 
 /**
-   Reserves space in the last chain of an event buffer.
+   Reserves space in the last chain or chains of an evbuffer.
 
-   Makes space available in the last chain of an event buffer that can
+   Makes space available in the last chain or chains of an evbuffer that can
    be arbitrarily written to by a user.  The space does not become
    available for reading until it has been committed with
    evbuffer_commit_space().
 
    The space is made available as one or more extents, represented by
    an initial pointer and a length.  You can force the memory to be
-   available as only one extent.  Allowing more, however, makes the
+   available as only one extent.  Allowing more extents, however, makes the
    function more efficient.
 
    Multiple subsequent calls to this function will make the same space
@@ -208,19 +242,20 @@ int evbuffer_expand(struct evbuffer *buf, size_t datlen);
    NOTE: The code currently does not ever use more than two extents.
    This may change in future versions.
 
-   @param buf the event buffer in which to reserve space.
+   @param buf the evbuffer in which to reserve space.
    @param size how much space to make available, at minimum.  The
       total length of the extents may be greater than the requested
       length.
    @param vec an array of one or more evbuffer_iovec structures to
       hold pointers to the reserved extents of memory.
-   @param n_vec The length of the vec array.  Must be at least 1.
+   @param n_vec The length of the vec array.  Must be at least 1;
+       2 is more efficient.
    @return the number of provided extents, or -1 on error.
-   @see evbuffer_commit_space
+   @see evbuffer_commit_space()
 */
 int
 evbuffer_reserve_space(struct evbuffer *buf, ev_ssize_t size,
-    struct evbuffer_iovec *vec, int n_vecs);
+    struct evbuffer_iovec *vec, int n_vec);
 
 /**
    Commits previously reserved space.
@@ -233,15 +268,15 @@ evbuffer_reserve_space(struct evbuffer *buf, ev_ssize_t size,
    has been added to the buffer since the space was reserved.
 
    If you want to commit less data than you got reserved space for,
-   modify the iov_len pointer of the buffer to a smaller value.  Note
-   that you may have received more space than you requested if it was
-   available!
+   modify the iov_len pointer of the appropriate extent to a smaller
+   value.  Note that you may have received more space than you
+   requested if it was available!
 
-   @param buf the event buffer in which to reserve space.
+   @param buf the evbuffer in which to reserve space.
    @param vec one or two extents returned by evbuffer_reserve_space.
    @param n_vecs the number of extents.
    @return 0 on success, -1 on error
-   @see evbuffer_reserve_space
+   @see evbuffer_reserve_space()
 */
 int evbuffer_commit_space(struct evbuffer *buf,
     struct evbuffer_iovec *vec, int n_vecs);
@@ -249,7 +284,7 @@ int evbuffer_commit_space(struct evbuffer *buf,
 /**
   Append data to the end of an evbuffer.
 
-  @param buf the event buffer to be appended to
+  @param buf the evbuffer to be appended to
   @param data pointer to the beginning of the data buffer
   @param datlen the number of bytes to be copied from the data buffer
   @return 0 on success, -1 on failure.
@@ -258,9 +293,12 @@ int evbuffer_add(struct evbuffer *buf, const void *data, size_t datlen);
 
 
 /**
-  Read data from an event buffer and drain the bytes read.
+  Read data from an evbuffer and drain the bytes read.
 
-  @param buf the event buffer to be read from
+  If more bytes are requested than are available in the evbuffer, we
+  only extract as many bytes as were available.
+
+  @param buf the evbuffer to be read from
   @param data the destination buffer to store the result
   @param datlen the maximum size of the destination buffer
   @return the number of bytes read, or -1 if we can't drain the buffer.
@@ -268,22 +306,28 @@ int evbuffer_add(struct evbuffer *buf, const void *data, size_t datlen);
 int evbuffer_remove(struct evbuffer *buf, void *data, size_t datlen);
 
 /**
-  Read data from an event buffer, and leave the buffer unchanged.
+  Read data from an evbuffer, and leave the buffer unchanged.
 
-  @param buf the event buffer to be read from
-  @param data the destination buffer to store the result
+  If more bytes are requested than are available in the evbuffer, we
+  only extract as many bytes as were available.
+
+  @param buf the evbuffer to be read from
+  @param data_out the destination buffer to store the result
   @param datlen the maximum size of the destination buffer
   @return the number of bytes read, or -1 if we can't drain the buffer.
  */
 ev_ssize_t evbuffer_copyout(struct evbuffer *buf, void *data_out, size_t datlen);
 
 /**
-  Read data from an event buffer into another event buffer draining
-  the bytes from the src buffer read.  This function avoids memcpy
-  as possible.
+  Read data from an evbuffer into another evbuffer, draining
+  the bytes from the source buffer.  This function avoids copy
+  operations to the extent possible.
 
-  @param src the event buffer to be read from
-  @param dst the destination event buffer to store the result into
+  If more bytes are requested than are available in src, the src
+  buffer is drained completely.
+
+  @param src the evbuffer to be read from
+  @param dst the destination evbuffer to store the result into
   @param datlen the maximum numbers of bytes to transfer
   @return the number of bytes read
  */
@@ -293,7 +337,15 @@ int evbuffer_remove_buffer(struct evbuffer *src, struct evbuffer *dst,
 /** Used to tell evbuffer_readln what kind of line-ending to look for.
  */
 enum evbuffer_eol_style {
-       /** Any sequence of CR and LF characters is acceptable as an EOL. */
+       /** Any sequence of CR and LF characters is acceptable as an
+        * EOL.
+        *
+        * Note that this style can produce ambiguous results: the
+        * sequence "CRLF" will be treated as a single EOL if it is
+        * all in the buffer at once, but if you first read a CR from
+        * the network and later read an LF from the network, it will
+        * be treated as two EOLs.
+        */
        EVBUFFER_EOL_ANY,
        /** An EOL is an LF, optionally preceded by a CR.  This style is
         * most useful for implementing text-based internet protocols. */
@@ -305,7 +357,7 @@ enum evbuffer_eol_style {
 };
 
 /**
- * Read a single line from an event buffer.
+ * Read a single line from an evbuffer.
  *
  * Reads a line terminated by an EOL as determined by the evbuffer_eol_style
  * argument.  Returns a newly allocated nul-terminated string; the caller must
@@ -322,7 +374,7 @@ char *evbuffer_readln(struct evbuffer *buffer, size_t *n_read_out,
     enum evbuffer_eol_style eol_style);
 
 /**
-  Move data from one evbuffer into another evbuffer.
+  Move all data from one evbuffer into another evbuffer.
 
   This is a destructive add.  The data from one buffer moves into
   the other buffer.  However, no unnecessary memory copies occur.
@@ -330,10 +382,17 @@ char *evbuffer_readln(struct evbuffer *buffer, size_t *n_read_out,
   @param outbuf the output buffer
   @param inbuf the input buffer
   @return 0 if successful, or -1 if an error occurred
+
+  @see evbuffer_remove_buffer()
  */
 int evbuffer_add_buffer(struct evbuffer *outbuf, struct evbuffer *inbuf);
 
+/**
+   A cleanup function for a piece of memory added to an evbuffer by
+   reference.
 
+   @see evbuffer_add_reference()
+ */
 typedef void (*evbuffer_ref_cleanup_cb)(const void *data,
     size_t datalen, void *extra);
 
@@ -348,37 +407,38 @@ typedef void (*evbuffer_ref_cleanup_cb)(const void *data,
   @param data the memory to reference
   @param datlen how memory to reference
   @param cleanupfn callback to be invoked when the memory is no longer
-       referenced
-  @param extra optional argument to the cleanup callback
+       referenced by this evbuffer.
+  @param cleanupfn_arg optional argument to the cleanup callback
   @return 0 if successful, or -1 if an error occurred
  */
 int evbuffer_add_reference(struct evbuffer *outbuf,
     const void *data, size_t datlen,
-    evbuffer_ref_cleanup_cb cleanupfn, void *extra);
+    evbuffer_ref_cleanup_cb cleanupfn, void *cleanupfn_arg);
 
 /**
-  Move data from a file into the evbuffer for writing to a socket.
+  Copy data from a file into the evbuffer for writing to a socket.
 
   This function avoids unnecessary data copies between userland and
-  kernel.  Where available, it uses sendfile or splice.
+  kernel.  Where available, it uses sendfile or splice; failing those,
+  it tries to use mmap.
 
   The function owns the resulting file descriptor and will close it
   when finished transferring data.
 
-  The results of using evbuffer_remove() or evbuffer_pullup() are
-  undefined.
+  The results of using evbuffer_remove() or evbuffer_pullup() on
+  evbuffers whose data was added using this function are undefined.
 
   For more fine-grained control, use evbuffer_add_file_segment.
 
   @param outbuf the output buffer
   @param fd the file descriptor
-  @param off the offset from which to read data
+  @param offset the offset from which to read data
   @param length how much data to read, or -1 to read as much as possible.
     (-1 requires that 'fd' support fstat.)
   @return 0 if successful, or -1 if an error occurred
 */
 
-int evbuffer_add_file(struct evbuffer *output, int fd, ev_off_t offset,
+int evbuffer_add_file(struct evbuffer *outbuf, int fd, ev_off_t offset,
     ev_off_t length);
 
 /**
@@ -482,11 +542,14 @@ int evbuffer_add_file_segment(struct evbuffer *buf,
 /**
   Append a formatted string to the end of an evbuffer.
 
+  The string is formated as printf.
+
   @param buf the evbuffer that will be appended to
   @param fmt a format string
   @param ... arguments that will be passed to printf(3)
   @return The number of bytes added if successful, or -1 if an error occurred.
 
+  @see evutil_printf(), evbuffer_add_vprintf()
  */
 int evbuffer_add_printf(struct evbuffer *buf, const char *fmt, ...)
 #ifdef __GNUC__
@@ -494,7 +557,6 @@ int evbuffer_add_printf(struct evbuffer *buf, const char *fmt, ...)
 #endif
 ;
 
-
 /**
   Append a va_list formatted string to the end of an evbuffer.
 
@@ -546,7 +608,7 @@ int evbuffer_write_atmost(struct evbuffer *buffer, evutil_socket_t fd,
 /**
   Read from a file descriptor and store the result in an evbuffer.
 
-  @param buf the evbuffer to store the result
+  @param buffer the evbuffer to store the result
   @param fd the file descriptor to read from
   @param howmuch the number of bytes to be read
   @return the number of bytes read, or -1 if an error occurred
@@ -583,6 +645,10 @@ struct evbuffer_ptr evbuffer_search(struct evbuffer *buffer, const char *what, s
  */
 struct evbuffer_ptr evbuffer_search_range(struct evbuffer *buffer, const char *what, size_t len, const struct evbuffer_ptr *start, const struct evbuffer_ptr *end);
 
+/**
+   Defines how to adjust an evbuffer_ptr by evbuffer_ptr_set()
+
+   @see evbuffer_ptr_set() */
 enum evbuffer_ptr_how {
        /** Sets the pointer to the position; can be called on with an
            uninitialized evbuffer_ptr. */
@@ -594,9 +660,18 @@ enum evbuffer_ptr_how {
 /**
    Sets the search pointer in the buffer to position.
 
-   If evbuffer_ptr is not initialized.  This function can only be called
+   There are two ways to use this function: you can call
+      evbuffer_ptr_set(buf, &pos, N, EVBUFFER_PTR_SET)
+   to move 'pos' to a position 'N' bytes after the start of the buffer, or
+      evbuffer_ptr_set(buf, &pos, N, EVBUFFER_PTR_SET)
+   to move 'pos' forward by 'N' bytes.
+
+   If evbuffer_ptr is not initialized, this function can only be called
    with EVBUFFER_PTR_SET.
 
+   An evbuffer_ptr can represent any position from the start of the buffer to
+   a position immediately after the end of the buffer.
+
    @param buffer the evbuffer to be search
    @param ptr a pointer to a struct evbuffer_ptr
    @param position the position at which to start the next search
@@ -604,7 +679,7 @@ enum evbuffer_ptr_how {
    @returns 0 on success or -1 otherwise
 */
 int
-evbuffer_ptr_set(struct evbuffer *buffer, struct evbuffer_ptr *pos,
+evbuffer_ptr_set(struct evbuffer *buffer, struct evbuffer_ptr *ptr,
     size_t position, enum evbuffer_ptr_how how);
 
 /**
@@ -625,14 +700,6 @@ struct evbuffer_ptr evbuffer_search_eol(struct evbuffer *buffer,
     struct evbuffer_ptr *start, size_t *eol_len_out,
     enum evbuffer_eol_style eol_style);
 
-/** Structure passed to an evbuffer callback */
-struct evbuffer_cb_info {
-       /** The size of */
-       size_t orig_size;
-       size_t n_added;
-       size_t n_deleted;
-};
-
 /** Function to peek at data inside an evbuffer without removing it or
     copying it out.
 
@@ -663,6 +730,21 @@ int evbuffer_peek(struct evbuffer *buffer, ev_ssize_t len,
     struct evbuffer_ptr *start_at,
     struct evbuffer_iovec *vec_out, int n_vec);
 
+
+/** Structure passed to an evbuffer_cb_func evbuffer callback
+
+    @see evbuffer_cb_func, evbuffer_add_cb()
+ */
+struct evbuffer_cb_info {
+       /** The number of bytes in this evbuffer when callbacks were last
+        * invoked. */
+       size_t orig_size;
+       /** The number of bytes added since callbacks were last invoked. */
+       size_t n_added;
+       /** The number of bytes removed since callbacks were last invoked. */
+       size_t n_deleted;
+};
+
 /** Type definition for a callback that is invoked whenever data is added or
     removed from an evbuffer.
 
@@ -718,7 +800,10 @@ int evbuffer_remove_cb_entry(struct evbuffer *buffer,
 int evbuffer_remove_cb(struct evbuffer *buffer, evbuffer_cb_func cb, void *cbarg);
 
 /** If this flag is not set, then a callback is temporarily disabled, and
- * should not be invoked. */
+ * should not be invoked.
+ *
+ * @see evbuffer_cb_set_flags(), evbuffer_cb_clear_flags()
+ */
 #define EVBUFFER_CB_ENABLED 1
 
 /** Change the flags that are set for a callback on a buffer by adding more.
index 6d0a2446221adf90701c7d3d8162b8c41e12064c..65e1c82d92b398ba85510eb2475a3e263c3e6b7f 100644 (file)
@@ -27,7 +27,7 @@
 #ifndef _EVENT2_BUFFER_COMPAT_H_
 #define _EVENT2_BUFFER_COMPAT_H_
 
-/** @file buffer_compat.h
+/** @file event2/buffer_compat.h
 
        Obsolete and deprecated versions of the functions in buffer.h: provided
        only for backward compatibility.
index ee84e08485ba6241fa6e906d8b477797c1e6ba27..dac988e33ee83ba6e3e3da6452059d2318a8c93b 100644 (file)
 #ifndef _EVENT2_BUFFEREVENT_H_
 #define _EVENT2_BUFFEREVENT_H_
 
-/** @file bufferevent.h
+/**
+   @file event2/bufferevent.h
 
   Functions for buffering data for network sending or receiving.  Bufferevents
   are higher level than evbuffers: each has an underlying evbuffer for reading
   and one for writing, and callbacks that are invoked under certain
   circumstances.
 
-  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.
+  A bufferevent provides input and output buffers that get filled and
+  drained automatically.  The user of a bufferevent 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 reading is enabled, the bufferevent will try to read from the
+  file descriptor onto its input buffer, and and call the read callback.
+  When writing is enabled, the bufferevent will try to write data onto its
+  file descriptor when writing is enabled, and call the write callback
+  when the output buffer is sufficiently drained.
+
+  Bufferevents come in several flavors, including:
 
-  Once initialized, the bufferevent structure can be used repeatedly with
-  bufferevent_enable() and bufferevent_disable().
+  <dl>
+    <dt>Socket-based bufferevents</dt>
+      <dd>A bufferevent that reads and writes data onto a network
+          socket. Created with bufferevent_socket_new().</dd>
 
-  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.
+    <dt>Paired bufferevents</dt>
+      <dd>A pair of bufferevents that send and receive data to one
+          another without touching the network.  Created with
+          bufferevent_pair_new().</dd>
 
+    <dt>Filtering bufferevents</dt>
+       <dd>A bufferevent that transforms data, and sends or receives it
+          over another underlying bufferevent.  Created with
+          bufferevent_filter_new().</dd>
+
+    <dt>SSL-backed bufferevents</dt>
+      <dd>A bufferevent that uses the openssl library to send and
+          receive data over an encrypted connection. Created with
+         bufferevent_openssl_socket_new() or
+         bufferevent_openssl_filter_new().</dd>
+  </dl>
  */
 
 #ifdef __cplusplus
@@ -65,20 +89,36 @@ extern "C" {
 /* For int types. */
 #include <event2/util.h>
 
-/* Just for error reporting - use other constants otherwise */
+/** @name Bufferevent event codes
+
+    These flags are passed as arguments to a bufferevent's event callback.
+
+    @{
+*/
 #define BEV_EVENT_READING      0x01    /**< error encountered while reading */
 #define BEV_EVENT_WRITING      0x02    /**< error encountered while writing */
 #define BEV_EVENT_EOF          0x10    /**< eof file reached */
 #define BEV_EVENT_ERROR                0x20    /**< unrecoverable error encountered */
-#define BEV_EVENT_TIMEOUT      0x40    /**< user specified timeout reached */
+#define BEV_EVENT_TIMEOUT      0x40    /**< user-specified timeout reached */
 #define BEV_EVENT_CONNECTED    0x80    /**< connect operation finished. */
-struct bufferevent;
+/**@}*/
+
+/**
+   An opaque type for handling buffered IO
+
+   @see event2/bufferevent.h
+ */
+struct bufferevent
+#ifdef _EVENT_IN_DOXYGEN
+{}
+#endif
+;
 struct event_base;
 struct evbuffer;
 struct sockaddr;
 
 /**
-   type definition for the read or write callback.
+   A read or write callback for a bufferevent.
 
    The read callback is triggered when new data arrives in the input
    buffer and the amount of readable data exceed the low watermark
@@ -88,14 +128,14 @@ struct sockaddr;
    exhausted or fell below its low watermark.
 
    @param bev the bufferevent that triggered the callback
-   @param ctx the user specified context for this bufferevent
+   @param ctx the user-specified context for this bufferevent
  */
 typedef void (*bufferevent_data_cb)(struct bufferevent *bev, void *ctx);
 
 /**
-   type definition for the error callback of a bufferevent.
+   An event/error callback for a bufferevent.
 
-   The error callback is triggered if either an EOF condition or another
+   The event callback is triggered if either an EOF condition or another
    unrecoverable error was encountered.
 
    @param bev the bufferevent for which the error condition was reached
@@ -104,7 +144,7 @@ typedef void (*bufferevent_data_cb)(struct bufferevent *bev, void *ctx);
          and one of the following flags: BEV_EVENT_EOF, BEV_EVENT_ERROR,
          BEV_EVENT_TIMEOUT, BEV_EVENT_CONNECTED.
 
-   @param ctx the user specified context for this bufferevent
+   @param ctx the user-specified context for this bufferevent
 */
 typedef void (*bufferevent_event_cb)(struct bufferevent *bev, short what, void *ctx);
 
@@ -136,6 +176,7 @@ enum bufferevent_options {
            This file descriptor is not allowed to be a pipe(2).
            It is safe to set the fd to -1, so long as you later
            set it with bufferevent_setfd or bufferevent_socket_connect().
+  @param options Zero or more BEV_OPT_* flags
   @return a pointer to a newly allocated bufferevent struct, or NULL if an
          error occurred
   @see bufferevent_free()
@@ -143,8 +184,10 @@ enum bufferevent_options {
 struct bufferevent *bufferevent_socket_new(struct event_base *base, evutil_socket_t fd, int options);
 
 /**
-   Launch a connect() attempt with a socket.  When the connect succeeds,
-   the eventcb will be invoked with BEV_EVENT_CONNECTED set.
+   Launch a connect() attempt with a socket-based bufferevent.
+
+   When the connect succeeds, the eventcb will be invoked with
+   BEV_EVENT_CONNECTED set.
 
    If the bufferevent does not already have a socket set, we allocate a new
    socket here and make it nonblocking before we begin.
@@ -188,7 +231,7 @@ struct evdns_base;
    may block while it waits for a DNS response.         This is probably not
    what you want.
  */
-int bufferevent_socket_connect_hostname(struct bufferevent *b,
+int bufferevent_socket_connect_hostname(struct bufferevent *,
     struct evdns_base *, int, const char *, int);
 
 /**
@@ -383,7 +426,7 @@ int bufferevent_disable(struct bufferevent *bufev, short event);
 short bufferevent_get_enabled(struct bufferevent *bufev);
 
 /**
-  Set the read and write timeout for a buffered event.
+  Set the read and write timeout for a bufferevent.
 
   A bufferevent's timeout will fire the first time that the indicated
   amount of time has elapsed since a successful read or write operation,
@@ -460,8 +503,7 @@ enum bufferevent_flush_mode {
 };
 
 /**
-   Triggers the bufferevent to produce more
-   data if possible.
+   Triggers the bufferevent to produce more data if possible.
 
    @param bufev the bufferevent object
    @param iotype either EV_READ or EV_WRITE or both.
@@ -473,9 +515,10 @@ int bufferevent_flush(struct bufferevent *bufev,
     enum bufferevent_flush_mode mode);
 
 /**
-   Support for filtering input and output of bufferevents.
- */
+   @name Filtering support
 
+   @{
+*/
 /**
    Values that filters can return.
  */
@@ -533,6 +576,7 @@ bufferevent_filter_new(struct bufferevent *underlying,
                       int options,
                       void (*free_context)(void *),
                       void *ctx);
+/**@}*/
 
 /**
    Allocate a pair of linked bufferevents.  The bufferevents behave as would
@@ -680,13 +724,16 @@ int bufferevent_add_to_rate_limit_group(struct bufferevent *bev,
 /** Remove 'bev' from its current rate-limit group (if any). */
 int bufferevent_remove_from_rate_limit_group(struct bufferevent *bev);
 
-/*@{*/
 /**
+   @name Rate limit inspection
+
    Return the current read or write bucket size for a bufferevent.
    If it is not configured with a per-bufferevent ratelimit, return
    EV_SSIZE_MAX.  This function does not inspect the group limit, if any.
    Note that it can return a negative value if the bufferevent has been
    made to read or write more than its limit.
+
+   @{
  */
 ev_ssize_t bufferevent_get_read_limit(struct bufferevent *bev);
 ev_ssize_t bufferevent_get_write_limit(struct bufferevent *bev);
@@ -695,11 +742,14 @@ ev_ssize_t bufferevent_get_write_limit(struct bufferevent *bev);
 ev_ssize_t bufferevent_get_max_to_read(struct bufferevent *bev);
 ev_ssize_t bufferevent_get_max_to_write(struct bufferevent *bev);
 
-/*@{*/
 /**
+   @name GrouprRate limit inspection
+
    Return the read or write bucket size for a bufferevent rate limit
    group.  Note that it can return a negative value if bufferevents in
    the group have been made to read or write more than their limits.
+
+   @{
  */
 ev_ssize_t bufferevent_rate_limit_group_get_read_limit(
        struct bufferevent_rate_limit_group *);
@@ -707,8 +757,9 @@ ev_ssize_t bufferevent_rate_limit_group_get_write_limit(
        struct bufferevent_rate_limit_group *);
 /*@}*/
 
-/*@{*/
 /**
+   @name Rate limit manipulation
+
    Subtract a number of bytes from a bufferevent's read or write bucket.
    The decrement value can be negative, if you want to manually refill
    the bucket. If the change puts the bucket above or below zero, the
@@ -717,13 +768,16 @@ ev_ssize_t bufferevent_rate_limit_group_get_write_limit(
    group, if any.
 
    Returns 0 on success, -1 on internal error.
+
+   @{
  */
 int bufferevent_decrement_read_limit(struct bufferevent *bev, ev_ssize_t decr);
 int bufferevent_decrement_write_limit(struct bufferevent *bev, ev_ssize_t decr);
 /*@}*/
 
-/*@{*/
 /**
+   @name Group rate limit manipulation
+
    Subtract a number of bytes from a bufferevent rate-limiting group's
    read or write bucket.  The decrement value can be negative, if you
    want to manually refill the bucket. If the change puts the bucket
@@ -731,6 +785,8 @@ int bufferevent_decrement_write_limit(struct bufferevent *bev, ev_ssize_t decr);
    suspend reading writing as appropriate.
 
    Returns 0 on success, -1 on internal error.
+
+   @{
  */
 int bufferevent_rate_limit_group_decrement_read(
        struct bufferevent_rate_limit_group *, ev_ssize_t);
@@ -739,14 +795,20 @@ int bufferevent_rate_limit_group_decrement_write(
 /*@}*/
 
 
-/** Set the variable pointed to by total_read_out to the total number of bytes
+/**
+ * Inspect the total bytes read/written on a group.
+ *
+ * Set the variable pointed to by total_read_out to the total number of bytes
  * ever read on grp, and the variable pointed to by total_written_out to the
  * total number of bytes ever written on grp. */
 void bufferevent_rate_limit_group_get_totals(
     struct bufferevent_rate_limit_group *grp,
     ev_uint64_t *total_read_out, ev_uint64_t *total_written_out);
 
-/** Reset the number of bytes read or written on grp as given by
+/**
+ * Reset the total bytes read/written on a group.
+ *
+ * Reset the number of bytes read or written on grp as given by
  * bufferevent_rate_limit_group_reset_totals(). */
 void
 bufferevent_rate_limit_group_reset_totals(
index 49dc4aefa0f0bd98f5e6ef52c9e419e715e5071e..6064a40fe650dbdfd6f109da9b6ee029fcaab92e 100644 (file)
   If multiple bases are in use, bufferevent_base_set() must be called before
   enabling the bufferevent for the first time.
 
+  @deprecated This function is deprecated because it uses the current
+    event base, and as such can be error prone for multithreaded programs.
+    Use bufferevent_socket_new() instead.
+
   @param fd the file descriptor from which data is read and written to.
         This file descriptor is not allowed to be a pipe(2).
   @param readcb callback to invoke when there is data to be read, or NULL if
index 036293317cc145d40174dd12dabde1c55f26b51f..12f00d63680fd695f4fe40357aeb74b052e1bf60 100644 (file)
@@ -26,7 +26,7 @@
 #ifndef _EVENT2_BUFFEREVENT_SSL_H_
 #define _EVENT2_BUFFEREVENT_SSL_H_
 
-/** @file bufferevent_ssl.h
+/** @file event2/bufferevent_ssl.h
 
     OpenSSL support for bufferevents.
  */
 extern "C" {
 #endif
 
+/* This is what openssl's SSL objects are underneath. */
 struct ssl_st;
 
+/**
+   The state of an SSL object to be used when creating a new
+   SSL bufferevent.
+ */
 enum bufferevent_ssl_state {
        BUFFEREVENT_SSL_OPEN = 0,
        BUFFEREVENT_SSL_CONNECTING = 1,
        BUFFEREVENT_SSL_ACCEPTING = 2
 };
 
-#ifdef _EVENT_HAVE_OPENSSL
+#if defined(_EVENT_HAVE_OPENSSL) || defined(_EVENT_IN_DOXYGEN)
+/**
+   Create a new SSL bufferevent to send its data over another bufferevent.
+
+   @param base An event_base to use to detect reading and writing.  It
+      must also be the base for the underlying bufferevent.
+   @param underlying A socket to use for this SSL
+   @param ssl A SSL* object from openssl.
+   @param state The current state of the SSL connection
+   @param options One or more bufferevent_options
+   @return A new bufferevent on success, or NULL on failure
+*/
 struct bufferevent *
 bufferevent_openssl_filter_new(struct event_base *base,
     struct bufferevent *underlying,
@@ -55,6 +71,16 @@ bufferevent_openssl_filter_new(struct event_base *base,
     enum bufferevent_ssl_state state,
     int options);
 
+/**
+   Create a new SSL bufferevent to send its data over an SSL * on a socket.
+
+   @param base An event_base to use to detect reading and writing
+   @param fd A socket to use for this SSL
+   @param ssl A SSL* object from openssl.
+   @param state The current state of the SSL connection
+   @param options One or more bufferevent_options
+   @return A new bufferevent on success, or NULL on failure.
+*/
 struct bufferevent *
 bufferevent_openssl_socket_new(struct event_base *base,
     evutil_socket_t fd,
@@ -62,11 +88,14 @@ bufferevent_openssl_socket_new(struct event_base *base,
     enum bufferevent_ssl_state state,
     int options);
 
+/** Return the underlying openssl SSL * object for an SSL bufferevent. */
 struct ssl_st *
 bufferevent_openssl_get_ssl(struct bufferevent *bufev);
 
+/** Tells a bufferevent to begin SSL renegotiation. */
 int bufferevent_ssl_renegotiate(struct bufferevent *bev);
 
+/** Return the most recent OpenSSL error reported on an SSL bufferevent. */
 unsigned long bufferevent_get_openssl_error(struct bufferevent *bev);
 
 #endif
index 5626e968f59c785b01bcbc540aad6edc6e764456..d4a0a067279ace13ca32b3f0ac83ead8044de37c 100644 (file)
 #ifndef _EVENT2_BUFFEREVENT_STRUCT_H_
 #define _EVENT2_BUFFEREVENT_STRUCT_H_
 
-/** @file bufferevent_struct.h
+/** @file event2/bufferevent_struct.h
 
   Data structures for bufferevents.  Using these structures may hurt forward
   compatibility with later versions of Libevent: be careful!
 
+  @deprecated Use of bufferevent_struct.h is completely deprecated; these
+    structures are only exposed for backward compatibility with programs
+    written before Libevent 2.0 that used them.
  */
 
 #ifdef __cplusplus
index fea00e40836d346b325bf07a902b5b8a06e1cfc2..113a15400de4df79df6576587879b417fbe76929 100644 (file)
@@ -47,7 +47,7 @@
  * the source verbatim in their source distributions)
  */
 
-/** @file dns.h
+/** @file event2/dns.h
  *
  * Welcome, gentle reader
  *
index 1a63fb6f4d0d3e51de817da12a16ee8554d5e1b2..14dfb4973ef332c28554c635826b2a9ad4347dc1 100644 (file)
 #ifndef _EVENT2_DNS_COMPAT_H_
 #define _EVENT2_DNS_COMPAT_H_
 
-/** @file dns_compat.h
+/** @file event2/dns_compat.h
 
   Potentially non-threadsafe versions of the functions in dns.h: provided
   only for backwards compatibility.
 
+
  */
 
 #ifdef __cplusplus
index c501eb20b7f93d7f698add8c92d280c753fdaecd..0eefd40e919207e82354d5524b1da951a55006f3 100644 (file)
@@ -27,7 +27,7 @@
 #ifndef _EVENT2_DNS_STRUCT_H_
 #define _EVENT2_DNS_STRUCT_H_
 
-/** @file dns_struct.h
+/** @file event2/dns_struct.h
 
   Data structures for dns.  Using these structures may hurt forward
   compatibility with later versions of Libevent: be careful!
index 3850318f47ffd83d2d5867603dfa9294cb88ad82..c487f7808888a542d4019d9a5079ed19b1a4799a 100644 (file)
 #ifndef _EVENT2_EVENT_H_
 #define _EVENT2_EVENT_H_
 
+/**
+   @mainpage
+
+  @section intro Introduction
+
+  Libevent is an event notification library for developing scalable network
+  servers.  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), select(2), poll(2),
+  epoll(4), and evports. 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 multithreaded programs.  Libevent
+  should compile on Linux, *BSD, Mac OS X, Solaris and, Windows.
+
+  @section usage Standard usage
+
+  Every program that uses Libevent must inclurde the <event2/event.h>
+  header, and pass the -levent flag to the linker.  (You can instead link
+  -levent_core if you only want the main event and buffered IO-based code,
+  and don't want to link any protocol code.)
+
+  @section setup Library setup
+
+  Before you call any other Libevent functions, you need to set up the
+  library.  If you're going to use Libevent from multiple threads in a
+  multithreaded application, you need to initialize thread support --
+  typically by using evthread_use_pthreads() or
+  evthread_use_windows_threads().  See <event2/thread.h> for more
+  information.
+
+  This is also the point where you can replace Libevent's memory
+  management functions with event_set_mem_functions, and enable debug mode
+  with event_enable_debug_mode().
+
+  @section base Creating an event base
+
+  Next, you need to create an event_base structure, using event_base_new()
+  or event_base_new_with_config().  The event_base is responsible for
+  keeping track of which events are "pending" (that is to say, being
+  watched to see if they become active) and which events are "active".
+  Every event is associated with a single event_base.
+
+  @section event Event notification
+
+  For each file descriptor that you wish to monitor, you must create an
+  event structure with event_new().  (You may also declare an event
+  structure and call event_assign() 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 generally be
+  allocated on the heap.
+
+  @section loop Dispaching evets.
+
+  Finally, you call event_base_dispatch() to loop and dispatch events.
+  You can also use event_base_loop() for more fine-grained control.
+
+  Currently, only one thread can be dispatching a given event_base at a
+  time.  If you want to run events in multiple threads at once, you can
+  either have a single event_base whose events add work to a work queue,
+  or you can create multiple event_base objects.
+
+  @section bufferevent I/O Buffers
+
+  Libevent provides a buffered I/O abstraction on top of the regular event
+  callbacks. This abstraction is called a bufferevent. A bufferevent
+  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 via bufferevent_socket_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.
+
+  See <event2/bufferevent*.h> for more information.
+
+  @section timers Timers
+
+  Libevent can also be used to create timers that invoke a callback after a
+  certain amount of time has expired. The evtimer_new() function returns
+  an event struct to use as a timer. To activate the timer, call
+  evtimer_add(). Timers can be deactivated by calling evtimer_del().
+
+  @section evdns Asynchronous DNS resolution
+
+  Libevent provides an asynchronous DNS resolver that should be used instead
+  of the standard DNS resolver functions.  See the <event2/dns.h>
+  functions for more detail.
+
+  @section evhttp Event-driven HTTP servers
+
+  Libevent provides a very simple event-driven HTTP server that can be
+  embedded in your program and used to service HTTP requests.
+
+  To use this capability, you need to include the <event2/http.h> header in your
+  program.  See that header for more information.
+
+  @section evrpc A framework for RPC servers and clients
+
+  Libevent provides a framework for creating RPC servers and clients.  It
+  takes care of marshaling and unmarshaling all data structures.
+
+  @section api API Reference
+
+  To browse the complete documentation of the libevent API, click on any of
+  the following links.
+
+  event2/event.h
+  The primary libevent header
+
+  event2/thread.h
+  Functions for use by multithreaded programs
+
+  event2/buffer.h and event2/bufferevent.h
+  Buffer management for network reading and writing
+
+  event2/util.h
+  Utility functions for portable nonblocking network code
+
+  event2/dns.h
+  Asynchronous DNS resolution
+
+  event2/http.h
+  An embedded libevent-based HTTP server
+
+  event2/rpc.h
+  A framework for creating RPC servers and clients
+
+ */
+
 /** @file event2/event.h
 
   Core functions for waiting for and receiving events, and using event bases.
-
 */
 
 #ifdef __cplusplus
@@ -50,15 +197,109 @@ extern "C" {
 /* For int types. */
 #include <event2/util.h>
 
-struct event_base;
-struct event;
-struct event_config;
+/**
+ * Structure to hold information and state for a Libevent dispatch loop.
+ *
+ * The event_base lies at the center of Libevent; every application will
+ * have one.  It keeps track of all pending and active events, and
+ * notifies your application of the active ones.
+ *
+ * This is an opaque structure; you can allocate one using
+ * event_base_new() or event_base_new_with_config().
+ *
+ * @see event_base_new(), event_base_free(), event_base_loop(),
+ *    event_base_new_with_config()
+ */
+struct event_base
+#ifdef _EVENT_IN_DOXYGEN
+{/*Empty body so that doxygen will generate documentation here.*/}
+#endif
+;
 
-/** Enable some relatively expensive debugging checks in Libevent that would
- * normally be turned off.  Generally, these cause code that would otherwise
- * crash mysteriously to fail earlier with an assertion failure.  Note that
- * this method MUST be called before any events or event_bases have been
- * created.
+/**
+ * @struct event
+ *
+ * Structure to represent a single event.
+ *
+ * An event can have some underlying condition it represents: a socket
+ * becoming readable or writeable (or both), or a signal becoming raised.
+ * (An event that represents no underlying condition is still useful: you
+ * can use one to implement a timer, or to communicate between threads.)
+ *
+ * Generally, you can create events with event_new(), then make them
+ * pending with event_add().  As your event_base runs, it will run the
+ * callbacks of an events whose conditions are triggered.  When you
+ * longer want the event, free it with event_free().
+ *
+ * In more depth:
+ *
+ * An event may be "pending" (one whose condition we are watching),
+ * "active" (one whose condition has triggered and whose callback is about
+ * to run), neither, or both.  Events come into existence via
+ * event_assign() or event_new(), and are then neither active nor pending.
+ *
+ * To make an event pending, pass it to event_add().  When doing so, you
+ * can also set a timeout for the event.
+ *
+ * Events become active during an event_base_loop() call when either their
+ * condition has triggered, or when their timeout has elapsed.  You can
+ * also activate an event manually using event_active().  The even_base
+ * loop will run the callbacks of active events; after it has done so, it
+ * marks them as no longer active.
+ *
+ * You can make an event non-pending by passing it to event_del().  This
+ * also makes the event non-active.
+ *
+ * Events can be "persistent" or "non-persistent".  A non-persistent event
+ * becomes non-pending as soon as it is triggered: thus, it only runs at
+ * most once per call to event_add().  A persistent event remains pending
+ * even when it becomes active: you'll need to event_del() it manually in
+ * order to make it non-pending.  When a persistent event with a timeout
+ * becomes active, its timeout is reset: this means you can use persistent
+ * events to implement periodic timeouts.
+ *
+ * This should be treated as an opaque structure; you should never read or
+ * write any of its fields directly.  For backward compatibility with old
+ * code, it is defined in the event2/event_struct.h header; including this
+ * header may make your code incompatible with other versions of Libevent.
+ *
+ * @see event_new(), event_free(), event_assign(), event_get_assignment(),
+ *    event_add(), event_del(), event_active(), event_pending(),
+ *    event_get_fd(), event_get_base(), event_get_events(),
+ *    event_get_callback(), event_get_callback_arg(),
+ *    event_priority_set()
+ */
+struct event
+#ifdef _EVENT_IN_DOXYGEN
+{/*Empty body so that doxygen will generate documentation here.*/}
+#endif
+;
+
+/**
+ * Configuration for an event_base.
+ *
+ * There are many options that can be used to alter the behavior and
+ * implementation of an event_base.  To avoid having to pass them all in a
+ * complex many-argument constructor, we provide an abstract data type
+ * wrhere you set up configation information before passing it to
+ * event_base_new_with_config().
+ *
+ * @see event_config_new(), event_config_free(), event_base_new_with_config(),
+ *   event_config_avoid_method(), event_config_require_features(),
+ *   event_config_set_flag(), event_config_set_num_cpus_hint()
+ */
+struct event_config
+#ifdef _EVENT_IN_DOXYGEN
+{/*Empty body so that doxygen will generate documentation here.*/}
+#endif
+;
+
+/**
+ * Enable some relatively expensive debugging checks in Libevent that
+ * would normally be turned off.  Generally, these checks cause code that
+ * would otherwise crash mysteriously to fail earlier with an assertion
+ * failure.  Note that this method MUST be called before any events or
+ * event_bases have been created.
  *
  * Debug mode can currently catch the following errors:
  *    An event is re-assigned while it is added
@@ -70,6 +311,8 @@ struct event_config;
  * debug mode, and you find yourself running out of memory, you will need
  * to use event_debug_unassign to explicitly stop tracking events that
  * are no longer considered set-up.
+ *
+ * @see event_debug_unassign()
  */
 void event_enable_debug_mode(void);
 
@@ -79,40 +322,44 @@ void event_enable_debug_mode(void);
  * nothing.
  *
  * This function must only be called on a non-added event.
+ *
+ * @see event_enable_debug_mode()
  */
 void event_debug_unassign(struct event *);
 
 /**
-  Initialize the event API.
-
-  Use event_base_new() to initialize a new event base.
-
-  @see event_base_set(), event_base_free(),
-    event_base_new_with_config()
+ * Create and return a new event_base to use with the rest of Libevent.
+ *
+ * @return a new event_base on success, or NULL on failure.
+ *
+ * @see event_base_free(), event_base_new_with_config()
  */
 struct event_base *event_base_new(void);
 
 /**
-  Reinitialized the event base after a fork
+  Reinitialize 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.
 
   @param base the event base that needs to be re-initialized
   @return 0 if successful, or -1 if some events could not be re-added.
-  @see event_base_new(), event_init()
+  @see event_base_new()
 */
 int event_reinit(struct event_base *base);
 
 /**
-  Threadsafe event dispatching loop.
+   Event dispatching loop
 
   This loop will run the event base until either there are no more added
   events, or until something calls event_base_loopbreak() or
-  evenet_base_loopexit().
+  event_base_loopexit().
 
-  @param eb the event_base structure returned by event_init()
-  @see event_init(), event_dispatch()
+  @param base the event_base structure returned by event_base_new() or
+     event_base_new_with_config()
+  @return 0 if successful, -1 if an error occurred, or 1 if no events were
+    registered.
+  @see event_base_loop()
  */
 int event_base_dispatch(struct event_base *);
 
@@ -144,10 +391,10 @@ const char **event_get_supported_methods(void);
    The event configuration object can be used to change the behavior of
    an event base.
 
-   @return an event_config object that can be used to store configuration or
-     NULL when an error is encountered.
+   @return an event_config object that can be used to store configuration, or
+     NULL if an error is encountered.
+   @see event_base_new_with_config(), event_config_free(), event_config
 */
-
 struct event_config *event_config_new(void);
 
 /**
@@ -161,28 +408,46 @@ void event_config_free(struct event_config *cfg);
    Enters an event method that should be avoided into the configuration.
 
    This can be used to avoid event mechanisms that do not support certain
-   file descriptor types.  An application can make use of multiple event
-   bases to accommodate incompatible file descriptor types.
+   file descriptor types, or for debugging to avoid certain event
+   mechanisms.  An application can make use of multiple event bases to
+   accommodate incompatible file descriptor types.
 
    @param cfg the event configuration object
-   @param method the event method to avoid
+   @param method the name of the event method to avoid
    @return 0 on success, -1 on failure.
 */
 int event_config_avoid_method(struct event_config *cfg, const char *method);
 
+/**
+   A flag used to describe which features an event_base (must) provide.
+
+   Because of OS limitations, not every Libevent backend supports every
+   possible feature.  You can use this type with
+   event_config_require_features() to tell Libevent to only proceed if your
+   event_base implements a given feature, and you can receive this type from
+   event_base_get_features() to see which features are available.
+*/
 enum event_method_feature {
-    /* Require an event method that allows edge-triggered events with EV_ET. */
+    /** Require an event method that allows edge-triggered events with EV_ET. */
     EV_FEATURE_ET = 0x01,
-    /* Require an event method where having one event triggered among
+    /** Require an event method where having one event triggered among
      * many is [approximately] an O(1) operation. This excludes (for
      * example) select and poll, which are approximately O(N) for N
      * equal to the total number of possible events. */
     EV_FEATURE_O1 = 0x02,
-    /* Require an event method that allows file descriptors as well as
+    /** Require an event method that allows file descriptors as well as
      * sockets. */
     EV_FEATURE_FDS = 0x04
 };
 
+/**
+   A flag passed to event_config_set_flag().
+
+    These flags change the behavior of an allocated event_base.
+
+    @see event_config_set_flag(), event_base_new_with_config(),
+       event_method_feature
+ */
 enum event_base_config_flag {
        /** Do not allocate a lock for the event base, even if we have
            locking set up. */
@@ -190,7 +455,12 @@ enum event_base_config_flag {
        /** Do not check the EVENT_* environment variables when configuring
            an event_base  */
        EVENT_BASE_FLAG_IGNORE_ENV = 0x02,
-       /** Windows only: enable the IOCP dispatcher at startup */
+       /** Windows only: enable the IOCP dispatcher at startup
+
+           If this flag is set then bufferevent_socket_new() and
+           evconn_listener_new() will use IOCP-backed implementations
+           instead of the usual select-based one on Windows.
+        */
        EVENT_BASE_FLAG_STARTUP_IOCP = 0x04,
        /** Instead of checking the current time every time the event loop is
            ready to run timeout callbacks, check after each timeout callback.
@@ -215,7 +485,11 @@ enum event_base_config_flag {
 };
 
 /**
- Return a bitmask of the features implemented by an event base.
+   Return a bitmask of the features implemented by an event base.  This
+   will be a bitwise OR of one or more of the values of
+   event_method_feature
+
+   @see event_method_feature
  */
 int event_base_get_features(const struct event_base *base);
 
@@ -239,11 +513,16 @@ int event_base_get_features(const struct event_base *base);
    @param feature a bitfield of one or more event_method_feature values.
           Replaces values from previous calls to this function.
    @return 0 on success, -1 on failure.
+   @see event_method_feature, event_base_new_with_config()
 */
 int event_config_require_features(struct event_config *cfg, int feature);
 
-/** Sets one or more flags to configure what parts of the eventual event_base
- * will be initialized, and how they'll work. */
+/**
+ * Sets one or more flags to configure what parts of the eventual event_base
+ * will be initialized, and how they'll work.
+ *
+ * @see event_base_config_flags, event_base_new_with_config()
+ **/
 int event_config_set_flag(struct event_config *cfg, int flag);
 
 /**
@@ -275,19 +554,25 @@ struct event_base *event_base_new_with_config(const struct event_config *);
   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.
+  to event_new as the argument to callback.
 
   @param eb an event_base to be freed
  */
 void event_base_free(struct event_base *);
 
+/** @name Log severities
+ */
+/**@{*/
 #define _EVENT_LOG_DEBUG 0
 #define _EVENT_LOG_MSG   1
 #define _EVENT_LOG_WARN  2
 #define _EVENT_LOG_ERR   3
+/**@}*/
 
-/*
+/**
   A callback function used to intercept Libevent's log messages.
+
+  @see event_set_log_callback
  */
 typedef void (*event_log_cb)(int severity, const char *msg);
 /**
@@ -302,6 +587,13 @@ typedef void (*event_log_cb)(int severity, const char *msg);
   */
 void event_set_log_callback(event_log_cb cb);
 
+/**
+   A function to be called if Libevent encounters a fatal internal error.
+
+   @see event_set_fatal_callback
+ */
+typedef void (*event_fatal_cb)(int err);
+
 /**
  Override Libevent's behavior in the event of a fatal internal error.
 
@@ -314,31 +606,34 @@ void event_set_log_callback(event_log_cb cb);
  Libevent will (almost) always log an _EVENT_LOG_ERR message before calling
  this function; look at the last log message to see why Libevent has died.
  */
-typedef void (*event_fatal_cb)(int err);
 void event_set_fatal_callback(event_fatal_cb cb);
 
 /**
   Associate a different event base with an event.
 
+  The event to be associated must not be currently active or pending.
+
   @param eb the event base
   @param ev the event
+  @return 0 on success, -1 on failure.
  */
 int event_base_set(struct event_base *, struct event *);
 
-/**
- event_base_loop() flags
+/** @name Loop flags
+
+    These flags control the behavior of event_base_loop().
  */
-/*@{*/
+/**@{*/
 /** Block until we have an active event, then exit once all active events
  * have had their callbacks run. */
 #define EVLOOP_ONCE    0x01
 /** Do not block: see which events are ready now, run the callbacks
  * of the highest-priority ones, then exit. */
 #define EVLOOP_NONBLOCK        0x02
-/*@}*/
+/**@}*/
 
 /**
-  Handle events (threadsafe version).
+  Wait for events to become active, and run their callbacks.
 
   This is a more flexible version of event_base_dispatch().
 
@@ -347,16 +642,18 @@ int event_base_set(struct event_base *, struct event *);
   evenet_base_loopexit().  You can override this behavior with the 'flags'
   argument.
 
-  @param eb the event_base structure returned by event_init()
+  @param eb the event_base structure returned by event_base_new() or
+     event_base_new_with_config()
   @param flags any combination of EVLOOP_ONCE | EVLOOP_NONBLOCK
   @return 0 if successful, -1 if an error occurred, or 1 if no events were
     registered.
-  @see event_loopexit(), event_base_loop()
+  @see event_base_loopexit(), event_base_dispatch(), EVLOOP_ONCE,
+     EVLOOP_NONBLOCK
   */
 int event_base_loop(struct event_base *, int);
 
 /**
-  Exit the event loop after the specified time (threadsafe variant).
+  Exit the event loop after the specified time
 
   The next event_base_loop() iteration after the given timer expires will
   complete normally (handling all queued events) then exit without
@@ -365,9 +662,10 @@ int event_base_loop(struct event_base *, int);
   Subsequent invocations of event_base_loop() will proceed normally.
 
   @param eb the event_base structure returned by event_init()
-  @param tv the amount of time after which the loop should terminate.
+  @param tv the amount of time after which the loop should terminate,
+    or NULL to exit after running all currently active events.
   @return 0 if successful, or -1 if an error occurred
-  @see event_loopexit()
+  @see event_base_loopbreak()
  */
 int event_base_loopexit(struct event_base *, const struct timeval *);
 
@@ -382,7 +680,7 @@ int event_base_loopexit(struct event_base *, const struct timeval *);
 
   @param eb the event_base structure returned by event_init()
   @return 0 if successful, or -1 if an error occurred
-  @see event_base_loopexit
+  @see event_base_loopexit()
  */
 int event_base_loopbreak(struct event_base *);
 
@@ -395,8 +693,8 @@ int event_base_loopbreak(struct event_base *);
   @param eb the event_base structure returned by event_init()
   @return true if event_base_loopexit() was called on this event base,
     or 0 otherwise
-  @see event_base_loopexit
-  @see event_base_got_break
+  @see event_base_loopexit()
+  @see event_base_got_break()
  */
 int event_base_got_exit(struct event_base *);
 
@@ -409,52 +707,58 @@ int event_base_got_exit(struct event_base *);
   @param eb the event_base structure returned by event_init()
   @return true if event_base_loopbreak() was called on this event base,
     or 0 otherwise
-  @see event_base_loopbreak
-  @see event_base_got_exit
+  @see event_base_loopbreak()
+  @see event_base_got_exit()
  */
 int event_base_got_break(struct event_base *);
 
-/* Flags to pass to event_set(), event_new(), event_assign(),
- * event_pending(), and anything else with an argument of the form
- * "short events" */
+/**
+ * @name event flags
+ *
+ * Flags to pass to event_new(), event_assign(), event_pending(), and
+ * anything else with an argument of the form "short events"
+ */
+/**@{*/
+/** Indicates that a timeout has occurred.  It's not necessary to pass
+ * this flag to event_for new()/event_assign() to get a timeout. */
 #define EV_TIMEOUT     0x01
+/** Wait for a socket or FD to become readable */
 #define EV_READ                0x02
+/** Wait for a socket or FD to become writeable */
 #define EV_WRITE       0x04
+/** Wait for a POSIX signal to be raised*/
 #define EV_SIGNAL      0x08
-/** Persistent event: won't get removed automatically when activated. */
+/**
+ * Persistent event: won't get removed automatically when activated.
+ *
+ * When a persistent event with a timeout becomes activated, its timeout
+ * is reset to 0.
+ */
 #define EV_PERSIST     0x10
 /** Select edge-triggered behavior, if supported by the backend. */
 #define EV_ET       0x20
+/**@}*/
 
 /**
-  Define a timer event.
+   @name evtimer_* macros
 
-  @param ev event struct to be modified
-  @param b an event_base
-  @param cb callback function
-  @param arg argument that will be passed to the callback function
- */
+    Aliases for working with one-shot timer events */
+/**@{*/
 #define evtimer_assign(ev, b, cb, arg) \
        event_assign((ev), (b), -1, 0, (cb), (arg))
 #define evtimer_new(b, cb, arg)               event_new((b), -1, 0, (cb), (arg))
-
-/**
-  Add a timer event.
-
-  @param ev the event struct
-  @param tv timeval struct
- */
 #define evtimer_add(ev, tv)            event_add((ev), (tv))
-
-/**
- * Delete a timer event.
- *
- * @param ev the event struct to be disabled
- */
 #define evtimer_del(ev)                        event_del(ev)
 #define evtimer_pending(ev, tv)                event_pending((ev), EV_TIMEOUT, (tv))
 #define evtimer_initialized(ev)                event_initialized(ev)
+/**@}*/
+
+/**
+   @name evsignal_* macros
 
+   Aliases for working with signal events
+ */
+/**@{*/
 #define evsignal_add(ev, tv)           event_add((ev), (tv))
 #define evsignal_assign(ev, b, x, cb, arg)                     \
        event_assign((ev), (b), (x), EV_SIGNAL|EV_PERSIST, cb, (arg))
@@ -463,57 +767,117 @@ int event_base_got_break(struct event_base *);
 #define evsignal_del(ev)               event_del(ev)
 #define evsignal_pending(ev, tv)       event_pending((ev), EV_SIGNAL, (tv))
 #define evsignal_initialized(ev)       event_initialized(ev)
+/**@}*/
 
+/**
+   A callback function for an event.
+
+   It receives three arguments:
+
+   @param fd An fd or signal
+   @param events One or more EV_* flags
+   @param arg A user-supplied argument.
+
+   @see event_new()
+ */
 typedef void (*event_callback_fn)(evutil_socket_t, short, void *);
 
 /**
-  Prepare an event structure to be added.
+  Allocate and asssign a new event structure, ready to be added.
+
+  The function event_new() returns a new event that can be used in
+  future calls to event_add() and event_del().  The fd and events
+  arguments determine which conditions will trigger the event; the
+  callback and callback_arg arguments tell Libevent what to do when the
+  event becomes active.
+
+  If events contains one of EV_READ, EV_WRITE, or EV_READ|EV_WRITE, then
+  fd is a file descriptor or socket that should get monitored for
+  readiness to read, readiness to write, or readiness for either operation
+  (respectively).  If events contains EV_SIGNAL, then fd is a signal
+  number to wait for.  If events contains none of those flags, then the
+  event can be triggered only by a timeout or by manual activation with
+  event_active(): In this case, fd must be -1.
+
+  The EV_PERSIST flag can also be passed in the events argument: it makes
+  event_add() persistent until event_del() is called.
+
+  The EV_ET flag is compatible with EV_READ and EV_WRITE, and supported
+  only by certain backends.  It tells Libevent to use edge-triggered
+  events.
+
+  The EV_TIMEOUT flag has no effect here.
+
+  It is okay to have multiple events all listening on the same fds; but
+  they must either all be edge-triggered, or all not be edge triggerd.
+
+  When the event becomes active, the event loop will run the provided
+  callbuck function, with three arguments.  The first will be the provided
+  fd value.  The second will be a bitfield of the events that triggered:
+  EV_READ, EV_WRITE, or EV_SIGNAL.  Here the EV_TIMEOUT flag indicates
+  that a timeout occurred, and EV_ET indicates that an edge-triggered
+  event occurred.  The third event will be the callback_arg pointer that
+  you provide.
+
+  @param base the event base to which the event should be attached.
+  @param fd the file descriptor or signal to be monitored, or -1.
+  @param events desired events to monitor: bitfield of EV_READ, EV_WRITE,
+      EV_SIGNAL, EV_PERSIST, EV_ET.
+  @param callback callback function to be invoked when the event occurs
+  @param callback_arg an argument to be passed to the callback function
 
-  The function event_assign() 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.
+  @return a newly allocated struct event that must later be freed with
+    event_free().
+  @see event_free(), event_add(), event_del(), event_assign()
+ */
+struct event *event_new(struct event_base *, evutil_socket_t, short, event_callback_fn, void *);
+
+
+/**
+  Prepare a new, already-allocated event structure to be added.
 
-  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.
+  The function event_assign() prepares the event structure ev to be used
+  in future calls to event_add() and event_del().  Unlike event_new(), it
+  doesn't allocate memory itself: it requires that you have already
+  allocated a struct event, probably on the heap.  Doing this will
+  typically make your code depend on the size of the event structure, and
+  thereby create incompatibility with future versions of Libevent.
 
-  Note that using event_assign() request that you have already allocated the
-  event struct.  Doing so will often require your code to depend on the size
-  of the structure, and will create possible incompatibility with future
-  versions of Libevent.  If this seems like a bad idea to you, use event_new()
-  and event_free() instead.
+  The easiest way to avoid this problem is just to use event_new() and
+  event_free() instead.
+
+  A slightly harder way to future-proof your code is to use
+  event_get_struct_event_size() to determine the required size of an event
+  at runtime.
+
+  Note that it is NOT safe to call this function on an event that is
+  active or pending.  Doing so WILL corrupt internal data structures in
+  Libevent, and lead to strange, hard-to-diagnose bugs.  You _can_ use
+  event_assign to change an existing event, but only if it is not active
+  or pending!
+
+  The arguments for this function, and the behavior of the events that it
+  makes, are as for event_new().
 
   @param ev an event struct to be modified
   @param base the event base to which ev should be attached.
   @param fd the file descriptor to be monitored
-  @param event desired events to monitor; can be EV_READ and/or EV_WRITE
-  @param fn callback function to be invoked when the event occurs
-  @param arg an argument to be passed to the callback function
+  @param events desired events to monitor; can be EV_READ and/or EV_WRITE
+  @param callback callback function to be invoked when the event occurs
+  @param callback_arg an argument to be passed to the callback function
 
   @return 0 if success, or -1 on invalid arguments.
 
-  @see event_add(), event_del(), event_once()
-
+  @see event_new(), event_add(), event_del(), event_base_once(),
+    event_get_struct_event_size()
   */
 int event_assign(struct event *, struct event_base *, evutil_socket_t, short, event_callback_fn, void *);
 
-/**
-  Create and allocate a new event structure, ready to be added.
-
-  Arguments are as for event_assign; returns a newly allocated struct event *
-  that must later be deallocated with event_free().
-
- */
-struct event *event_new(struct event_base *, evutil_socket_t, short, event_callback_fn, void *);
-
 /**
    Deallocate a struct event * returned by event_new().
+
+   If the event is pending or active, first make it non-pending and
+   non-active.
  */
 void event_free(struct event *);
 
@@ -521,41 +885,49 @@ void event_free(struct event *);
   Schedule a one-time event
 
   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
+  schedules a callback to be called exactly once, and does not require the
   caller to prepare an event structure.
 
-  @param base an event_base returned by event_init()
-  @param fd a file descriptor to monitor
-  @param events event(s) to monitor; can be any of EV_TIMEOUT | EV_READ |
-         EV_WRITE
+  Note that in Libevent 2.0 and earlier, if the event is never triggered,
+  the internal memory used to hold it will never be freed.  This may be
+  fixed in a later version of Libevent.
+
+  @param base an event_base
+  @param fd a file descriptor to monitor, or -1 for no fd.
+  @param events event(s) to monitor; can be any of EV_READ |
+         EV_WRITE, or EV_TIMEOUT
   @param callback callback function to be invoked when the event occurs
   @param arg an argument to be passed to the callback function
-  @param timeout the maximum amount of time to wait for the event, or NULL
-         to wait forever
+  @param timeout the maximum amount of time to wait for the event. NULL
+         makes an EV_READ/EV_WRITE event make forever; NULL makes an
+        EV_TIMEOUT event succees immediately.
   @return 0 if successful, or -1 if an error occurred
-  @see event_once()
  */
 int event_base_once(struct event_base *, evutil_socket_t, short, event_callback_fn, void *, const struct timeval *);
 
 /**
-  Add an event to the set of monitored events.
+  Add an event to the set of pending 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.
+  event specified in event_assign()/event_new() occurs, or when the time
+  specified in timeout has elapesed.  If atimeout is NULL, no timeout
+  occurs and the function will only be
+  called if a matching event occurs.  The event in the
+  ev argument must be already initialized by event_assign() or event_new()
+  and may not be used
+  in calls to event_assign() until it is no longer pending.
+
+  If the event in the ev argument already has a scheduled timeout, calling
+  event_add() replaces the old timeout with the new one, or clears the old
+  timeout if the timeout argument is NULL.
 
   @param ev an event struct initialized via event_set()
   @param timeout the maximum amount of time to wait for the event, or NULL
          to wait forever
   @return 0 if successful, or -1 if an error occurred
-  @see event_del(), event_set()
+  @see event_del(), event_assign(), event_new()
   */
-int event_add(struct event *, const struct timeval *);
+int event_add(struct event *ev, const struct timeval *timeout);
 
 /**
   Remove an event from the set of monitored events.
@@ -574,18 +946,24 @@ int event_del(struct event *);
 /**
   Make an event active.
 
+  You can use this function on a pending or a non-pending event to make it
+  active, so that its callback will be run by event_base_dispatch() or
+  event_base_loop().
+
+  One common use in multithreaded programs is to wake the thread running
+  event_base_loop() from another thread.
+
   @param ev an event to make active.
   @param res a set of flags to pass to the event's callback.
-  @param ncalls
+  @param ncalls an obsolete argument: this is ignored.
  **/
-void event_active(struct event *, int, short);
-
+void event_active(struct event *ev, int res, short ncalls);
 
 /**
   Checks if a specific event is pending or scheduled.
 
   @param ev an event struct previously passed to event_add()
-  @param what the requested event type; any of EV_TIMEOUT|EV_READ|
+  @param events the requested event type; any of EV_TIMEOUT|EV_READ|
          EV_WRITE|EV_SIGNAL
   @param tv if this field is not NULL, and the event has a timeout,
          this field is set to hold the time at which the timeout will
@@ -593,9 +971,8 @@ void event_active(struct event *, int, short);
 
   @return true if the event is pending on any of the events in 'what', (that
   is to say, it has been added), or 0 if the event is not added.
-
  */
-int event_pending(const struct event *, short, struct timeval *);
+int event_pending(const struct event *ev, short events, struct timeval *tv);
 
 
 /**
@@ -616,17 +993,18 @@ int event_pending(const struct event *, short, struct timeval *);
 int event_initialized(const struct event *ev);
 
 /**
-   Get the signal number assigned to an event.
+   Get the signal number assigned to a signal event
 */
 #define event_get_signal(ev) ((int)event_get_fd(ev))
 
 /**
-   Get the socket assigned to an event.
+   Get the socket or signal assigned to an event, or -1 if the event has
+   no socket.
 */
 evutil_socket_t event_get_fd(const struct event *ev);
 
 /**
-   Get the event_base assigned to an event.
+   Get the event_base associated with an event.
 */
 struct event_base *event_get_base(const struct event *ev);
 
@@ -701,20 +1079,37 @@ ev_uint32_t event_get_version_number(void);
  * headers. */
 #define LIBEVENT_VERSION_NUMBER _EVENT_NUMERIC_VERSION
 
+/** Largest number of priorities that Libevent can support. */
 #define EVENT_MAX_PRIORITIES 256
 /**
-  Set the number of different event priorities (threadsafe variant).
-
-  See the description of event_priority_init() for more information.
-
-  @param eb the event_base structure returned by event_init()
+  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_base_priority_init() function.  This function should be called
+  before the first call to event_base_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.
+
+  Note that urgent-priority events can starve less-urgent events: after
+  running all urgent-priority callbacks, Libevent checks for more urgent
+  events again, before running less-urgent events.  Less-urgent events
+  will not have their callbacks run until there are no events more urgent
+  than them that want to be active.
+
+  @param eb the event_base structure returned by event_base_new()
   @param npriorities the maximum number of priorities
   @return 0 if successful, or -1 if an error occurred
-  @see event_priority_init(), event_priority_set()
+  @see event_priority_set()
  */
 int    event_base_priority_init(struct event_base *, int);
 
-
 /**
   Assign a priority to an event.
 
@@ -726,14 +1121,15 @@ int      event_base_priority_init(struct event_base *, int);
 int    event_priority_set(struct event *, int);
 
 /**
-   Prepare Libevent to use a large number of timeouts with the same duration.
+   Prepare an event_base to use a large number of timeouts with the same
+   duration.
 
    Libevent's default scheduling algorithm is optimized for having a large
-   number of timeouts with their durations more or less randomly distributed.
-   If you have a large number of timeouts that all have the same duration (for
-   example, if you have a large number of connections that all have a
-   10-second timeout), then you can improve Libevent's performance by telling
-   Libevent about it.
+   number of timeouts with their durations more or less randomly
+   distributed.  But if you have a large number of timeouts that all have
+   the same duration (for example, if you have a large number of
+   connections that all have a 10-second timeout), then you can improve
+   Libevent's performance by telling Libevent about it.
 
    To do this, call this function with the common duration.  It will return a
    pointer to a different, opaque timeout value.  (Don't depend on its actual
@@ -746,14 +1142,13 @@ int      event_priority_set(struct event *, int);
 const struct timeval *event_base_init_common_timeout(struct event_base *base,
     const struct timeval *duration);
 
-#ifndef _EVENT_DISABLE_MM_REPLACEMENT
+#if !defined(_EVENT_DISABLE_MM_REPLACEMENT) || defined(_EVENT_IN_DOXYGEN)
 /**
  Override the functions that Libevent uses for memory management.
 
  Usually, Libevent uses the standard libc functions malloc, realloc, and
  free to allocate memory.  Passing replacements for those functions to
- event_set_mem_functions() overrides this behavior.  To restore the default
- behavior, pass NULLs as the arguments to this function.
+ event_set_mem_functions() overrides this behavior.
 
  Note that all memory returned from Libevent will be allocated by the
  replacement functions rather than by malloc() and realloc().  Thus, if you
@@ -761,6 +1156,11 @@ const struct timeval *event_base_init_common_timeout(struct event_base *base,
  that you get from Libevent.  Instead, you must use the free_fn replacement
  that you provided.
 
+ Note also that if you are going to call this function, you should do so
+ before any call to any Libevent function that does allocation.
+ Otherwise, those funtions will allocate their memory using malloc(), but
+ then later free it using your provided free_fn.
+
  @param malloc_fn A replacement for malloc.
  @param realloc_fn A replacement for realloc
  @param free_fn A replacement for free.
@@ -769,6 +1169,8 @@ void event_set_mem_functions(
        void *(*malloc_fn)(size_t sz),
        void *(*realloc_fn)(void *ptr, size_t sz),
        void (*free_fn)(void *ptr));
+/** This definition is present if Libevent was built with support for
+    event_set_mem_functions() */
 #define EVENT_SET_MEM_FUNCTIONS_IMPLEMENTED
 #endif
 
index af2d0e0a6cec8b6a51d880bd0d8588acd0b183e2..d501ef7d96c0bb19ad25e842a4a70ea8176c9b80 100644 (file)
 #ifndef _EVENT2_EVENT_COMPAT_H_
 #define _EVENT2_EVENT_COMPAT_H_
 
-/** @file event_compat.h
+/** @file event2/event_compat.h
 
   Potentially non-threadsafe versions of the functions in event.h: provided
   only for backwards compatibility.
 
+  In the oldest versions of Libevent, event_base was not a first-class
+  structure.  Instead, there was a single event base that every function
+  manipulated.  Later, when separate event bases were added, the old functions
+  that didn't take an event_base argument needed to work by manipulating the
+  "current" event base.  This could lead to thread-safety issues, and obscure,
+  hard-to-diagnose bugs.
+
+  @deprecated All functions in this file are by definition deprecated.
  */
 
 #ifdef __cplusplus
@@ -67,31 +75,26 @@ struct event_base *event_init(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.
+  Like event_base_dispatch(), but uses the "current" base.
 
   @deprecated This function is deprecated because it is easily confused by
     multiple calls to event_init(), and because it is not safe for
     multithreaded use.  The replacement is event_base_dispatch().
 
-  @see event_base_dispatch()
+  @see event_base_dispatch(), event_init()
  */
 int event_dispatch(void);
 
 /**
   Handle events.
 
-  This is a more flexible version of event_dispatch().
+  This function behaves like event_base_loop(), but uses the "current" base
 
   @deprecated This function is deprecated because it uses the event base from
     the last call to event_init, and is therefore not safe for multithreaded
     use.  The replacement is event_base_loop().
 
-  @param flags any combination of EVLOOP_ONCE | EVLOOP_NONBLOCK
-  @return 0 if successful, -1 if an error occurred, or 1 if no events were
-    registered.
-  @see event_base_loopexit(), event_base_loop()
+  @see event_base_loop(), event_init()
 */
 int event_loop(int);
 
@@ -99,19 +102,14 @@ int event_loop(int);
 /**
   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.
+  This function behaves like event_base_loopexit(), except that it uses the
+  "current" base.
 
-  @deprecated This function is deprecated because it is easily confused by
-    multiple calls to event_init(), and because it is not safe for
-    multithreaded use.  The replacement is event_base_loopexit().
+  @deprecated This function is deprecated because it uses the event base from
+    the last call to event_init, and is therefore not safe for multithreaded
+    use.  The replacement is event_base_loopexit().
 
-  @param tv the amount of time after which the loop should terminate.
-  @return 0 if successful, or -1 if an error occurred
-  @see event_loop(), event_base_loop(), event_base_loopexit()
+  @see event_init, event_base_loopexit()
   */
 int event_loopexit(const struct timeval *);
 
@@ -119,42 +117,25 @@ int event_loopexit(const struct timeval *);
 /**
   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.
+  This function behaves like event_base_loopbreakt(), except that it uses the
+  "current" base.
 
-  @deprecated This function is deprecated because it is easily confused by
-    multiple calls to event_init(), and because it is not safe for
-    multithreaded use.  The replacement is event_base_loopbreak().
+  @deprecated This function is deprecated because it uses the event base from
+    the last call to event_init, and is therefore not safe for multithreaded
+    use.  The replacement is event_base_loopbreak().
 
-  @return 0 if successful, or -1 if an error occurred
-  @see event_base_loopbreak(), event_loopexit()
+  @see event_base_loopbreak(), event_init()
  */
 int event_loopbreak(void);
 
 /**
   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.
-
-  @deprecated This function is deprecated because it is easily confused by
-    multiple calls to event_init(), and because it is not safe for
-    multithreaded use.  The replacement is event_base_once().
-
-  @param fd a file descriptor to monitor
-  @param events event(s) to monitor; can be any of EV_TIMEOUT | EV_READ |
-         EV_WRITE
-  @param callback callback function to be invoked when the event occurs
-  @param arg an argument to be passed to the callback function
-  @param timeout the maximum amount of time to wait for the event, or NULL
-         to wait forever
-  @return 0 if successful, or -1 if an error occurred
-  @see event_set()
+  @deprecated This function is obsolete, and has been replaced by
+    event_base_once(). Its use is deprecated because it relies on the
+    "current" base configured by event_init().
 
+  @see event_base_once()
  */
 int event_once(evutil_socket_t , short,
     void (*)(evutil_socket_t, short, void *), void *, const struct timeval *);
@@ -163,11 +144,11 @@ int event_once(evutil_socket_t , short,
 /**
   Get the kernel event notification mechanism used by Libevent.
 
-  @return a string identifying the kernel event mechanism (kqueue, epoll, etc.)
+  @deprecated This function is obsolete, and has been replaced by
+    event_base_get_method(). Its use is deprecated because it relies on the
+    "current" base configured by event_init().
 
-  @deprecated This function is deprecated because it is easily confused by
-    multiple calls to event_init(), and because it is not safe for
-    multithreaded use.  The replacement is event_base_get_method().
+  @see event_base_get_method()
  */
 const char *event_get_method(void);
 
@@ -175,61 +156,19 @@ const char *event_get_method(void);
 /**
   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.
-
   @deprecated This function is deprecated because it is easily confused by
     multiple calls to event_init(), and because it is not safe for
     multithreaded use.  The replacement is event_base_priority_init().
 
-  @param npriorities the maximum number of priorities
-  @return 0 if successful, or -1 if an error occurred
-  @see event_base_priority_init(), event_priority_set()
-
+  @see event_base_priority_init()
  */
 int    event_priority_init(int);
 
 /**
   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.
-
-  For read and write events, edge-triggered behavior can be requested
-  with the EV_ET flag.  Not all backends support edge-triggered
-  behavior.  When an edge-triggered event is activated, the EV_ET flag
-  is added to its events argument.
-
-  @param ev an event struct to be modified
-  @param fd the file descriptor to be monitored
-  @param event desired events to monitor; can be EV_READ and/or EV_WRITE
-  @param fn callback function to be invoked when the event occurs
-  @param arg an argument to be passed to the callback function
-
-  @see event_add(), event_del(), event_once()
-
   @deprecated event_set() is not recommended for new code, because it requires
-     a subsequent call to event_base_set() to be safe under many circumstances.
+     a subsequent call to event_base_set() to be safe under most circumstances.
      Use event_assign() or event_new() instead.
  */
 void event_set(struct event *, evutil_socket_t, short, void (*)(evutil_socket_t, short, void *), void *);
@@ -240,76 +179,33 @@ void event_set(struct event *, evutil_socket_t, short, void (*)(evutil_socket_t,
 
 
 /**
- * Add a timeout event.
- *
- * @param ev the event struct to be disabled
- * @param tv the timeout value, in seconds
- *
- * @deprecated This macro is deprecated because its naming is inconsistent.
- *    The recommend macro is evtimer_add().
- */
-#define timeout_add(ev, tv)            event_add((ev), (tv))
-
+   @name timeout_* macros
 
-/**
- * Define a timeout event.
- *
- * @param ev the event struct to be defined
- * @param cb the callback to be invoked when the timeout expires
- * @param arg the argument to be passed to the callback
- *
- * @deprecated This macro is deprecated because its naming is inconsistent.
- *    The recommend macro is evtimer_set().
+   @deprecated These macros are deprecated because their naming is inconsisten
+     with the rest of Libevent.  Use the evtimer_* macros instead.
+   @{
  */
+#define timeout_add(ev, tv)            event_add((ev), (tv))
 #define timeout_set(ev, cb, arg)       event_set((ev), -1, 0, (cb), (arg))
-
-/**
- * Disable a timeout event.
- *
- * @param ev the timeout event to be disabled
- *
- * @deprecated This macro is deprecated because its naming is inconsistent.
- *    The recommend macro is evtimer_del().
- */
 #define timeout_del(ev)                        event_del(ev)
-
-/**
-   @deprecated This macro is deprecated because its naming is inconsistent.
-   The recommend macro is evtimer_pending().
-*/
 #define timeout_pending(ev, tv)                event_pending((ev), EV_TIMEOUT, (tv))
-/**
-   @deprecated This macro is deprecated because its naming is inconsistent.
-   The recommend macro is evtimer_initialized().
-*/
 #define timeout_initialized(ev)                event_initialized(ev)
+/**@}*/
 
 /**
-   @deprecated This macro is deprecated because its naming is inconsistent.
-    The recommend macro is evsignal_add().
-*/
+   @name signal_* macros
+
+   @deprecated These macros are deprecated because their naming is inconsisten
+     with the rest of Libevent.  Use the evsignal_* macros instead.
+   @{
+ */
 #define signal_add(ev, tv)             event_add((ev), (tv))
-/**
-   @deprecated This macro is deprecated because its naming is inconsistent.
-    The recommend macro is evsignal_set().
-*/
 #define signal_set(ev, x, cb, arg)                             \
        event_set((ev), (x), EV_SIGNAL|EV_PERSIST, (cb), (arg))
-/**
-   @deprecated This macro is deprecated because its naming is inconsistent.
-    The recommend macro is evsignal_del().
-*/
 #define signal_del(ev)                 event_del(ev)
-/**
-   @deprecated This macro is deprecated because its naming is inconsistent.
-    The recommend macro is evsignal_pending().
-*/
 #define signal_pending(ev, tv)         event_pending((ev), EV_SIGNAL, (tv))
-/**
-   @deprecated This macro is deprecated because its naming is inconsistent.
-    The recommend macro is evsignal_initialized().
-*/
 #define signal_initialized(ev)         event_initialized(ev)
+/**@}*/
 
 #ifndef EVENT_FD
 /* These macros are obsolete; use event_get_fd and event_get_signal instead. */
index 4138ffd26b4c0c7e21e9a44232d242defe6dcfc7..d3cfb0cca9bba916c6c5d98a8a310514b3905a40 100644 (file)
 #ifndef _EVENT2_EVENT_STRUCT_H_
 #define _EVENT2_EVENT_STRUCT_H_
 
-/** @file event_struct.h
+/** @file event2/event_struct.h
 
-  Structures used by event.h.  Using these structures directly may harm
-  forward compatibility: be careful!
+  Structures used by event.h.  Using these structures directly WILL harm
+  forward compatibility: be careful.
 
+  No field declared in this file should be used directly in user code.  Except
+  for historical reasons, these fields would not be exposed at all.
  */
 
 #ifdef __cplusplus
index 793e2b8189bd82f1b769d7b3a3fae6f59871e2c5..e69ebf9eced0a3feeb09b56702fead80bde7e722 100644 (file)
@@ -38,7 +38,7 @@ extern "C" {
 struct evbuffer;
 struct event_base;
 
-/** @file http.h
+/** @file event2/http.h
  *
  * Basic support for HTTP serving.
  *
index b23dd9e052e8b7debdaeb8922dd0c14668c95c37..02a080beb712bcb0d035d3d664415da98596ee50 100644 (file)
@@ -27,7 +27,7 @@
 #ifndef _EVENT2_HTTP_COMPAT_H_
 #define _EVENT2_HTTP_COMPAT_H_
 
-/** @file http_compat.h
+/** @file event2/http_compat.h
 
   Potentially non-threadsafe versions of the functions in http.h: provided
   only for backwards compatibility.
index 7a68d4e5c8ecedc424d06b18b29e47469b391569..3545fdf5b93983f4f4ac39745309cee996cbe19b 100644 (file)
@@ -27,7 +27,7 @@
 #ifndef _EVENT2_HTTP_STRUCT_H_
 #define _EVENT2_HTTP_STRUCT_H_
 
-/** @file http_struct.h
+/** @file event2/http_struct.h
 
   Data structures for http.  Using these structures may hurt forward
   compatibility with later versions of Libevent: be careful!
index af1ef99fff2ec90955db56b92c88b0c38ab03e3b..1f3b3a1fd5f0fe40732ce14040b374bfa020c379 100644 (file)
@@ -27,7 +27,7 @@
 #ifndef _EVENT2_RPC_COMPAT_H_
 #define _EVENT2_RPC_COMPAT_H_
 
-/** @file rpc_compat.h
+/** @file event2/rpc_compat.h
 
   Deprecated versions of the functions in rpc.h: provided only for
   backwards compatibility.
index c1efe1d8823f2ccc9a73105c65c4ef21fdd58b8c..1345fb7430380a36018c22157ffd798f51b9efa4 100644 (file)
@@ -31,7 +31,7 @@
 extern "C" {
 #endif
 
-/** @file rpc_struct.h
+/** @file event2/rpc_struct.h
 
   Structures used by rpc.h.  Using these structures directly may harm
   forward compatibility: be careful!
index 7ab2346be6d3b459382f6be9939595e6a1f91a4c..54ce8c65828c2fe6f97fc6631ced76d9a055858e 100644 (file)
@@ -27,7 +27,7 @@
 #ifndef _EVENT2_TAG_H_
 #define _EVENT2_TAG_H_
 
-/** @file tag.h
+/** @file event2/tag.h
 
   Helper functions for reading and writing tagged data onto buffers.
 
index 410157405cdd879dc78b61510e49b48a1429aebd..8a47e8a38ce514ae982231dfcd7ecd972e99199b 100644 (file)
 #ifndef _EVENT2_TAG_COMPAT_H_
 #define _EVENT2_TAG_COMPAT_H_
 
-/** @file tag_compat.h
+/** @file event2/tag_compat.h
 
     Obsolete/deprecated functions from tag.h; provided only for backwards
     compatibility.
  */
 
+/**
+   @name Misnamed functions
+
+   @deprecated These macros are deprecated because their names don't follow
+     Libevent's naming conventions.  Use evtag_encode_int and
+     evtag_encode_int64 instead.
+
+   @{
+*/
 #define encode_int(evbuf, number) evtag_encode_int((evbuf), (number))
 #define encode_int64(evbuf, number) evtag_encode_int64((evbuf), (number))
+/**@}*/
 
 #endif /* _EVENT2_TAG_H_ */
index f5b4fe3bd0e9cddc3b06f3d1f716eb88ae0c3f92..3e7216d1237f39317fdff4911929209521f9c937 100644 (file)
@@ -26,7 +26,7 @@
 #ifndef _EVENT2_THREAD_H_
 #define _EVENT2_THREAD_H_
 
-/** @file thread.h
+/** @file event2/thread.h
 
   Functions for multi-threaded applications using Libevent.
 
   _must_ be set up before an event_base is created if you want the base to
   use them.
 
-  A multi-threaded application must provide locking functions to
-  Libevent via evthread_set_locking_callback().  Libevent will invoke
-  this callback whenever a lock needs to be acquired or released.
-
-  The total number of locks employed by Libevent can be determined
-  via the evthread_num_locks() function.  An application must provision
-  that many locks.
-
-  If the owner of an event base is waiting for events to happen,
-  Libevent may signal the thread via a special file descriptor to wake
-  up.   To enable this feature, an application needs to provide a
-  thread identity function via evthread_set_id_callback().
+  Most programs will either be using Windows threads or Posix threads.  You
+  can configure Libevent to use one of these event_use_windows_threads() or
+  event_use_pthreads() respectively.  If you're using another threading
+  library, you'll need to configure threading functions manually using
+  evthread_set_lock_callbacks() and evthread_set_condition_callbacks().
 
  */
 
@@ -59,6 +52,11 @@ extern "C" {
 
 #include <event2/event-config.h>
 
+/**
+   @name Flags passed to lock functions
+
+   @{
+*/
 /** A flag passed to a locking callback when the lock was allocated as a
  * read-write lock, and we want to acquire or release the lock for writing. */
 #define EVTHREAD_WRITE 0x04
@@ -69,11 +67,16 @@ extern "C" {
  * for the lock; if we can't get the lock immediately, we will instead
  * return nonzero from the locking callback. */
 #define EVTHREAD_TRY    0x10
+/**@}*/
 
-#ifndef _EVENT_DISABLE_THREAD_SUPPORT
+#if !defined(_EVENT_DISABLE_THREAD_SUPPORT) || defined(_EVENT_IN_DOXYGEN)
 
 #define EVTHREAD_LOCK_API_VERSION 1
 
+/**
+   @name Types of locks
+
+   @{*/
 /** A recursive lock is one that can be acquired multiple times at once by the
  * same thread.  No other process can allocate the lock until the thread that
  * has been holding it has unlocked it as many times as it locked it. */
@@ -81,9 +84,10 @@ extern "C" {
 /* A read-write lock is one that allows multiple simultaneous readers, but
  * where any one writer excludes all other writers and readers. */
 #define EVTHREAD_LOCKTYPE_READWRITE 2
+/**@}*/
 
 /** This structure describes the interface a threading library uses for
- * locking.   It's used to tell evthread_set_lock_callbacks how to use
+ * locking.   It's used to tell evthread_set_lock_callbacks() how to use
  * locking on this platform.
  */
 struct evthread_lock_callbacks {
@@ -168,7 +172,7 @@ struct evthread_condition_callbacks {
  *
  * Note that if you're using Windows or the Pthreads threading library, you
  * probably shouldn't call this function; instead, use
- * evthread_use_windows_threads() or evthread_use_posix_threads() if you can.
+ * evthread_use_windows_threads() or evthread_use_pthreads() if you can.
  */
 int evthread_set_condition_callbacks(
        const struct evthread_condition_callbacks *);
@@ -183,38 +187,45 @@ int evthread_set_condition_callbacks(
 void evthread_set_id_callback(
     unsigned long (*id_fn)(void));
 
-#if defined(_WIN32) && !defined(_EVENT_DISABLE_THREAD_SUPPORT)
+#if (defined(_WIN32) && !defined(_EVENT_DISABLE_THREAD_SUPPORT)) || defined(_EVENT_IN_DOXYGEN)
 /** Sets up Libevent for use with Windows builtin locking and thread ID
-       functions.  Unavailable if Libevent is not built for Windows.
+    functions.  Unavailable if Libevent is not built for Windows.
 
-       @return 0 on success, -1 on failure. */
+    @return 0 on success, -1 on failure. */
 int evthread_use_windows_threads(void);
+/**
+   Defined if Libevent was built with support for evthread_use_windows_threads()
+*/
 #define EVTHREAD_USE_WINDOWS_THREADS_IMPLEMENTED 1
 #endif
 
-#if defined(_EVENT_HAVE_PTHREADS)
+#if defined(_EVENT_HAVE_PTHREADS) || defined(_EVENT_IN_DOXYGEN)
 /** Sets up Libevent for use with Pthreads locking and thread ID functions.
-       Unavailable if Libevent is not build for use with pthreads.  Requires
-       libraries to link against Libevent_pthreads as well as Libevent.
+    Unavailable if Libevent is not build for use with pthreads.  Requires
+    libraries to link against Libevent_pthreads as well as Libevent.
 
-       @return 0 on success, -1 on failure. */
+    @return 0 on success, -1 on failure. */
 int evthread_use_pthreads(void);
+/** Defined if Libevent was built with support for evthread_use_pthreads() */
 #define EVTHREAD_USE_PTHREADS_IMPLEMENTED 1
 
 #endif
 
 /** Enable debugging wrappers around the current lock callbacks.  If Libevent
  * makes one of several common locking errors, exit with an assertion failure.
+ *
+ * If you're going to call this function, you must do so before any locks are
+ * allocated.
  **/
 void evthread_enable_lock_debuging(void);
 
 #endif /* _EVENT_DISABLE_THREAD_SUPPORT */
 
 struct event_base;
-/** Make sure it's safe to tell an event base to wake up from another thread.
+/** Make sure it's safe to tell an event base to wake up from another thread
     or a signal handler.
 
-       @return 0 on success, -1 on failure.
+    @return 0 on success, -1 on failure.
  */
 int evthread_make_base_notifiable(struct event_base *base);
 
index 687c92d97249e0bd28dd588ccb17b1650d2dce16..c71fdcf510cded8ebbc0f6ed35a83aa295982be3 100644 (file)
@@ -69,19 +69,39 @@ extern "C" {
 #include <sys/socket.h>
 #endif
 
-/* Integer type definitions for types that are supposed to be defined in the
+/* Some openbsd autoconf versions get the name of this macro wrong. */
+#if defined(_EVENT_SIZEOF_VOID__) && !defined(_EVENT_SIZEOF_VOID_P)
+#define _EVENT_SIZEOF_VOID_P _EVENT_SIZEOF_VOID__
+#endif
+
+/**
+ * @name Standard integer types.
+ *
+ * Integer type definitions for types that are supposed to be defined in the
  * C99-specified stdint.h.  Shamefully, some platforms do not include
  * stdint.h, so we need to replace it.  (If you are on a platform like this,
  * your C headers are now over 10 years out of date.  You should bug them to
  * do something about this.)
  *
  * We define:
- *    ev_uint64_t, ev_uint32_t, ev_uint16_t, ev_uint8_t -- unsigned integer
- *      types of exactly 64, 32, 16, and 8 bits respectively.
- *    ev_int64_t, ev_int32_t, ev_int16_t, ev_int8_t -- signed integer
- *      types of exactly 64, 32, 16, and 8 bits respectively.
- *    ev_uintptr_t, ev_intptr_t -- unsigned/signed integers large enough
- *      to hold a pointer without loss of bits.
+ *
+ * <dl>
+ *   <dt>ev_uint64_t, ev_uint32_t, ev_uint16_t, ev_uint8_t</dt>
+ *      <dd>unsigned integer types of exactly 64, 32, 16, and 8 bits
+ *          respectively.</dd>
+ *    <dt>ev_int64_t, ev_int32_t, ev_int16_t, ev_int8_t</dt>
+ *      <dd>signed integer types of exactly 64, 32, 16, and 8 bits
+ *          respectively.</dd>
+ *    <dt>ev_uintptr_t, ev_intptr_t</dt>
+ *      <dd>unsigned/signed integers large enough
+ *      to hold a pointer without loss of bits.</dd>
+ *    <dt>ev_ssize_t</dt>
+ *      <dd>A signed type of the same size as size_t</dd>
+ *    <dt>ev_off_t</dt>
+ *      <dd>A signed type typically used to represent offsets within a
+ *      (potentially large) file</dd>
+ *
+ * @{
  */
 #ifdef _EVENT_HAVE_UINT64_T
 #define ev_uint64_t uint64_t
@@ -95,6 +115,9 @@ extern "C" {
 #elif _EVENT_SIZEOF_LONG == 8
 #define ev_uint64_t unsigned long
 #define ev_int64_t long
+#elif defined(_EVENT_IN_DOXYGEN)
+#define ev_uint64_t ...
+#define ev_int64_t ...
 #else
 #error "No way to define ev_uint64_t"
 #endif
@@ -111,6 +134,9 @@ extern "C" {
 #elif _EVENT_SIZEOF_INT == 4
 #define ev_uint32_t unsigned int
 #define ev_int32_t signed int
+#elif defined(_EVENT_IN_DOXYGEN)
+#define ev_uint32_t ...
+#define ev_int32_t ...
 #else
 #error "No way to define ev_uint32_t"
 #endif
@@ -127,6 +153,9 @@ extern "C" {
 #elif _EVENT_SIZEOF_SHORT == 2
 #define ev_uint16_t unsigned short
 #define ev_int16_t  signed short
+#elif defined(_EVENT_IN_DOXYGEN)
+#define ev_uint16_t ...
+#define ev_int16_t ...
 #else
 #error "No way to define ev_uint16_t"
 #endif
@@ -134,16 +163,14 @@ extern "C" {
 #ifdef _EVENT_HAVE_UINT8_T
 #define ev_uint8_t uint8_t
 #define ev_int8_t int8_t
+#elif defined(_EVENT_IN_DOXYGEN)
+#define ev_uint8_t ...
+#define ev_int8_t ...
 #else
 #define ev_uint8_t unsigned char
 #define ev_int8_t signed char
 #endif
 
-/* Some openbsd autoconf versions get the name of this macro wrong. */
-#if defined(_EVENT_SIZEOF_VOID__) && !defined(_EVENT_SIZEOF_VOID_P)
-#define _EVENT_SIZEOF_VOID_P _EVENT_SIZEOF_VOID__
-#endif
-
 #ifdef _EVENT_HAVE_UINTPTR_T
 #define ev_uintptr_t uintptr_t
 #define ev_intptr_t intptr_t
@@ -153,6 +180,9 @@ extern "C" {
 #elif _EVENT_SIZEOF_VOID_P <= 8
 #define ev_uintptr_t ev_uint64_t
 #define ev_intptr_t ev_int64_t
+#elif defined(_EVENT_IN_DOXYGEN)
+#define ev_uintptr_t ...
+#define ev_intptr_t ...
 #else
 #error "No way to define ev_uintptr_t"
 #endif
@@ -168,6 +198,7 @@ extern "C" {
 #else
 #define ev_off_t off_t
 #endif
+/**@}*/
 
 /* Limits for integer types.
 
@@ -176,6 +207,14 @@ extern "C" {
      - The platform does signed arithmetic in two's complement.
 */
 
+/**
+   @name Limits for integer types
+
+   These macros hold the largest or smallest values possible for the
+   ev_[u]int*_t types.
+
+   @{
+*/
 #define EV_UINT64_MAX ((((ev_uint64_t)0xffffffffUL) << 32) | 0xffffffffUL)
 #define EV_INT64_MAX  ((((ev_int64_t) 0x7fffffffL) << 32) | 0xffffffffL)
 #define EV_INT64_MIN  ((-EV_INT64_MAX) - 1)
@@ -188,18 +227,28 @@ extern "C" {
 #define EV_UINT8_MAX  255
 #define EV_INT8_MAX   127
 #define EV_INT8_MIN   ((-EV_INT8_MAX) - 1)
+/** @} */
+
+/**
+   @name Limits for SIZE_T and SSIZE_T
 
+   @{
+*/
 #if _EVENT_SIZEOF_SIZE_T == 8
 #define EV_SIZE_MAX EV_UINT64_MAX
 #define EV_SSIZE_MAX EV_INT64_MAX
 #elif _EVENT_SIZEOF_SIZE_T == 4
 #define EV_SIZE_MAX EV_UINT32_MAX
 #define EV_SSIZE_MAX EV_INT32_MAX
+#elif defined(_EVENT_IN_DOXYGEN)
+#define EV_SIZE_MAX ...
+#define EV_SSIZE_MAX ...
 #else
 #error "No way to define SIZE_MAX"
 #endif
 
 #define EV_SSIZE_MIN ((-EV_SSIZE_MAX) - 1)
+/**@}*/
 
 #ifdef _WIN32
 #define ev_socklen_t int
@@ -216,17 +265,20 @@ extern "C" {
 #endif
 #endif
 
-#ifdef _WIN32
-/** A type wide enough to hold the output of "socket()" or "accept()".  On
+/**
+ * A type wide enough to hold the output of "socket()" or "accept()".  On
  * Windows, this is an intptr_t; elsewhere, it is an int. */
+#ifdef _WIN32
 #define evutil_socket_t intptr_t
 #else
 #define evutil_socket_t int
 #endif
 
-/** Create two new sockets that are connected to each other.  On Unix, this
-    simply calls socketpair().  On Windows, it uses the loopback network
-    interface on 127.0.0.1, and only AF_INET,SOCK_STREAM are supported.
+/** Create two new sockets that are connected to each other.
+
+    On Unix, this simply calls socketpair().  On Windows, it uses the
+    loopback network interface on 127.0.0.1, and only
+    AF_INET,SOCK_STREAM are supported.
 
     (This may fail on some Windows hosts where firewall software has cleverly
     decided to keep 127.0.0.1 from talking to itself.)
@@ -241,9 +293,13 @@ int evutil_socketpair(int d, int type, int protocol, evutil_socket_t sv[2]);
  */
 int evutil_make_socket_nonblocking(evutil_socket_t sock);
 
-/** Do platform-specific operations on a listener socket to make sure that
-    another program will be able to bind this address right after we've
-    closed the listener
+/** Do platform-specific operations to make a listener socket reusable.
+
+    Specifically, we want to make sure that another program will be able
+    to bind this address right after we've closed the listener.
+
+    This differs from Windows's interpretation of "reusable", which
+    allows multiple listeners to bind the same address at the same time.
 
     @param sock The socket to make reusable
     @return 0 on success, -1 on failure
@@ -267,11 +323,6 @@ int evutil_make_socket_closeonexec(evutil_socket_t sock);
 int evutil_closesocket(evutil_socket_t sock);
 #define EVUTIL_CLOSESOCKET(s) evutil_closesocket(s)
 
-/* Winsock handles socket errors differently from the rest of the world.
- * Elsewhere, a socket error is like any other error and is stored in errno.
- * But winsock functions require you to retrieve the error with a special
- * function, and don't let you use strerror for the error codes.  And handling
- * EWOULDBLOCK is ... different. */
 
 #ifdef _WIN32
 /** Return the most recent socket error.  Not idempotent on all platforms. */
@@ -283,6 +334,30 @@ int evutil_closesocket(evutil_socket_t sock);
 int evutil_socket_geterror(evutil_socket_t sock);
 /** Convert a socket error to a string. */
 const char *evutil_socket_error_to_string(int errcode);
+#elif defined(_EVENT_IN_DOXYGEN)
+/**
+   @name Socket error functions
+
+   These functions are needed for making programs compatible between
+   Windows and Unix-like platforms.
+
+   You see, Winsock handles socket errors differently from the rest of
+   the world.  Elsewhere, a socket error is like any other error and is
+   stored in errno.  But winsock functions require you to retrieve the
+   error with a special function, and don't let you use strerror for
+   the error codes.  And handling EWOULDBLOCK is ... different.
+
+   @{
+*/
+/** Return the most recent socket error.  Not idempotent on all platforms. */
+#define EVUTIL_SOCKET_ERROR() ...
+/** Replace the most recent socket error with errcode */
+#define EVUTIL_SET_SOCKET_ERROR(errcode) ...
+/** Return the most recent socket error to occur on sock. */
+#define evutil_socket_geterror(sock) ...
+/** Convert a socket error to a string. */
+#define evutil_socket_error_to_string(errcode) ...
+/**@}*/
 #else
 #define EVUTIL_SOCKET_ERROR() (errno)
 #define EVUTIL_SET_SOCKET_ERROR(errcode)               \
@@ -291,9 +366,14 @@ const char *evutil_socket_error_to_string(int errcode);
 #define evutil_socket_error_to_string(errcode) (strerror(errcode))
 #endif
 
-/*
- * Manipulation macros for struct timeval.  We define replacements
+
+/**
+ * @name Manipulation macros for struct timeval.
+ *
+ * We define replacements
  * for timeradd, timersub, timerclear, timercmp, and timerisset.
+ *
+ * @{
  */
 #ifdef _EVENT_HAVE_TIMERADD
 #define evutil_timeradd(tvp, uvp, vvp) timeradd((tvp), (uvp), (vvp))
@@ -324,6 +404,7 @@ const char *evutil_socket_error_to_string(int errcode);
 #else
 #define        evutil_timerclear(tvp)  (tvp)->tv_sec = (tvp)->tv_usec = 0
 #endif
+/**@}*/
 
 /** Return true iff the tvp is related to uvp according to the relational
  * operator cmp.  Recognized values for cmp are ==, <=, <, >=, and >. */
@@ -338,7 +419,7 @@ const char *evutil_socket_error_to_string(int errcode);
 #define        evutil_timerisset(tvp)  ((tvp)->tv_sec || (tvp)->tv_usec)
 #endif
 
-/* Replacement for offsetof on platforms that don't define it. */
+/** Replacement for offsetof on platforms that don't define it. */
 #ifdef offsetof
 #define evutil_offsetof(type, field) offsetof(type, field)
 #else
@@ -349,7 +430,7 @@ const char *evutil_socket_error_to_string(int errcode);
 /** Parse a 64-bit value from a string.  Arguments are as for strtol. */
 ev_int64_t evutil_strtoll(const char *s, char **endptr, int base);
 
-/* Replacement for gettimeofday on platforms that lack it. */
+/** Replacement for gettimeofday on platforms that lack it. */
 #ifdef _EVENT_HAVE_GETTIMEOFDAY
 #define evutil_gettimeofday(tv, tz) gettimeofday((tv), (tz))
 #else
@@ -365,6 +446,9 @@ int evutil_snprintf(char *buf, size_t buflen, const char *format, ...)
        __attribute__((format(printf, 3, 4)))
 #endif
 ;
+/** Replacement for vsnprintf to get consistent behavior on platforms for
+    which the return value of snprintf does not conform to C99.
+ */
 int evutil_vsnprintf(char *buf, size_t buflen, const char *format, va_list ap);
 
 /** Replacement for inet_ntop for platforms which lack it. */
@@ -412,11 +496,16 @@ int evutil_ascii_strcasecmp(const char *str1, const char *str2);
  */
 int evutil_ascii_strncasecmp(const char *str1, const char *str2, size_t n);
 
-/* Here we define evutil_addrinfo to the native addrinfo type, or redefinte it
+/* Here we define evutil_addrinfo to the native addrinfo type, or redefine it
  * if this system has no getaddrinfo(). */
 #ifdef _EVENT_HAVE_STRUCT_ADDRINFO
 #define evutil_addrinfo addrinfo
 #else
+/** A definition of struct addrinfo for systems that lack it.
+
+    (This is just an alias for struct addrinfo if the system defines
+    struct addrinfo.)
+*/
 struct evutil_addrinfo {
        int     ai_flags;     /* AI_PASSIVE, AI_CANONNAME, AI_NUMERICHOST */
        int     ai_family;    /* PF_xxx */
@@ -428,6 +517,13 @@ struct evutil_addrinfo {
        struct evutil_addrinfo  *ai_next; /* next structure in linked list */
 };
 #endif
+/** @name evutil_getaddrinfo() error codes
+
+    These values are possible error codes for evutil_getaddrinfo() and
+    related functions.
+
+    @{
+*/
 #ifdef EAI_ADDRFAMILY
 #define EVUTIL_EAI_ADDRFAMILY EAI_ADDRFAMILY
 #else
@@ -524,9 +620,11 @@ struct evutil_addrinfo {
 #else
 #define EVUTIL_AI_ADDRCONFIG 0x40000
 #endif
+/**@}*/
 
 struct evutil_addrinfo;
-/* This function clones getaddrinfo for systems that don't have it.  For full
+/**
+ * This function clones getaddrinfo for systems that don't have it.  For full
  * details, see RFC 3493, section 6.1.
  *
  * Limitations:
@@ -539,12 +637,12 @@ struct evutil_addrinfo;
 int evutil_getaddrinfo(const char *nodename, const char *servname,
     const struct evutil_addrinfo *hints_in, struct evutil_addrinfo **res);
 
-/* Release storage allocated by evutil_getaddrinfo or evdns_getaddrinfo. */
+/** Release storage allocated by evutil_getaddrinfo or evdns_getaddrinfo. */
 void evutil_freeaddrinfo(struct evutil_addrinfo *ai);
 
 const char *evutil_gai_strerror(int err);
 
-/* Generate n bytes of secure pseudorandom data, and store them in buf.
+/** Generate n bytes of secure pseudorandom data, and store them in buf.
  *
  * By default, Libevent uses an ARC4-based random number generator, seeded
  * using the platform's entropy source (/dev/urandom on Unix-like systems;
index bf5a1c9d1b88933e23c54f1ac291aaa195eb202d..b0772dc13f008ceed208a09740d21663531dd70f 100644 (file)
  * easy way to tell them apart via autoconf, so we need to use OS macros. */
 #if defined(_EVENT_HAVE_INTTYPES_H) && !defined(__OpenBSD__) && !defined(__FreeBSD__) && !defined(__darwin__) && !defined(__APPLE__)
 #define PTR_TO_UDATA(x)        ((intptr_t)(x))
+#define INT_TO_UDATA(x) ((intptr_t)(x))
 #else
 #define PTR_TO_UDATA(x)        (x)
+#define INT_TO_UDATA(x) ((void*)(x))
 #endif
 
 #include "event-internal.h"
@@ -168,6 +170,8 @@ kq_sighandler(int sig)
        /* Do nothing here */
 }
 
+#define ADD_UDATA 0x30303
+
 static void
 kq_setup_kevent(struct kevent *out, evutil_socket_t fd, int filter, short change)
 {
@@ -177,6 +181,9 @@ kq_setup_kevent(struct kevent *out, evutil_socket_t fd, int filter, short change
 
        if (change & EV_CHANGE_ADD) {
                out->flags = EV_ADD;
+               /* We set a magic number here so that we can tell 'add'
+                * errors from 'del' errors. */
+               out->udata = INT_TO_UDATA(ADD_UDATA);
                if (change & EV_ET)
                        out->flags |= EV_CLEAR;
 #ifdef NOTE_EOF
@@ -315,27 +322,47 @@ kq_dispatch(struct event_base *base, struct timeval *tv)
                int which = 0;
 
                if (events[i].flags & EV_ERROR) {
-                       /*
-                        * Error messages that can happen, when a delete fails.
-                        *   EBADF happens when the file descriptor has been
-                        *   closed,
-                        *   ENOENT when the file descriptor was closed and
-                        *   then reopened.
-                        *   EINVAL for some reasons not understood; EINVAL
-                        *   should not be returned ever; but FreeBSD does :-\
-                        * An error is also indicated when a callback deletes
-                        * an event we are still processing.  In that case
-                        * the data field is set to ENOENT.
-                        */
-                       if (events[i].data == EBADF ||
-                           events[i].data == EINVAL ||
-                           events[i].data == ENOENT)
+                       switch (events[i].data) {
+
+                       /* Can occur on delete if we are not currently
+                        * watching any events on this fd.  That can
+                        * happen when the fd was closed and another
+                        * file was opened with that fd. */
+                       case ENOENT:
+                       /* Can occur for reasons not fully understood
+                        * on FreeBSD. */
+                       case EINVAL:
                                continue;
-                       errno = events[i].data;
-                       return (-1);
-               }
 
-               if (events[i].filter == EVFILT_READ) {
+                       /* Can occur on a delete if the fd is closed.  Can
+                        * occur on an add if the fd was one side of a pipe,
+                        * and the other side was closed. */
+                       case EBADF:
+                       /* These two can occur on an add if the fd was one side
+                        * of a pipe, and the other side was closed. */
+                       case EPERM:
+                       case EPIPE:
+                               /* Report read events, if we're listening for
+                                * them, so that the user can learn about any
+                                * add errors.  (If the operation was a
+                                * delete, then udata should be cleared.) */
+                               if (events[i].udata) {
+                                       /* The operation was an add:
+                                        * report the error as a read. */
+                                       which |= EV_READ;
+                                       break;
+                               } else {
+                                       /* The operation was a del:
+                                        * report nothing. */
+                                       continue;
+                               }
+
+                       /* Other errors shouldn't occur. */
+                       default:
+                               errno = events[i].data;
+                               return (-1);
+                       }
+               } else if (events[i].filter == EVFILT_READ) {
                        which |= EV_READ;
                } else if (events[i].filter == EVFILT_WRITE) {
                        which |= EV_WRITE;
index 4ade6aab992ee3193e861fbf5b38dcccbe8e686f..df0d0df0441a0679b3d41f22530a0dddc6d00a56 100644 (file)
@@ -1,7 +1,7 @@
 AUTOMAKE_OPTIONS = foreign no-dependencies
 
 LDADD = $(LIBEVENT_GC_SECTIONS) ../libevent.la
-AM_CFLAGS = -I$(top_srcdir) -I$(top_srcdir)/compat -I$(top_srcdir)/include -I../include
+AM_CPPFLAGS = -I$(top_srcdir) -I$(top_srcdir)/compat -I$(top_srcdir)/include -I../include
 
 noinst_PROGRAMS = event-test time-test signal-test dns-example hello-world http-server
 
index e418261df6ffdcd377f50930a64f21447ec7b9e6..805c08d0efc1b692cb86a6ee3fe92c7fe208e126 100644 (file)
 #include "event2/event-config.h"
 #include "evconfig-private.h"
 
+#ifdef __APPLE__
+/* Apple wants us to define this if we might ever pass more than
+ * FD_SETSIZE bits to select(). */
+#define _DARWIN_UNLIMITED_SELECT
+#endif
+
 #include <sys/types.h>
 #ifdef _EVENT_HAVE_SYS_TIME_H
 #include <sys/time.h>
 #include "log-internal.h"
 #include "evmap-internal.h"
 
-#ifndef howmany
-#define howmany(x, y)   (((x)+((y)-1))/(y))
-#endif
-
 #ifndef _EVENT_HAVE_FD_MASK
 /* This type is mandatory, but Android doesn't define it. */
-#undef NFDBITS
-#define NFDBITS (sizeof(long)*8)
 typedef unsigned long fd_mask;
 #endif
 
+#ifndef NFDBITS
+#define NFDBITS (sizeof(fd_mask)*8)
+#endif
+
+/* Divide positive x by y, rounding up. */
+#define DIV_ROUNDUP(x, y)   (((x)+((y)-1))/(y))
+
+/* How many bytes to allocate for N fds? */
+#define SELECT_ALLOC_SIZE(n) \
+       (DIV_ROUNDUP(n, NFDBITS) * sizeof(fd_mask))
+
 struct selectop {
        int event_fds;          /* Highest fd in fd set */
        int event_fdsz;
@@ -101,7 +112,7 @@ select_init(struct event_base *base)
        if (!(sop = mm_calloc(1, sizeof(struct selectop))))
                return (NULL);
 
-       if (select_resize(sop, howmany(32 + 1, NFDBITS)*sizeof(fd_mask))) {
+       if (select_resize(sop, SELECT_ALLOC_SIZE(32 + 1))) {
                select_free_selectop(sop);
                return (NULL);
        }
@@ -254,8 +265,7 @@ select_add(struct event_base *base, int fd, short old, short events, void *p)
                /* In theory we should worry about overflow here.  In
                 * reality, though, the highest fd on a unixy system will
                 * not overflow here. XXXX */
-               while (fdsz <
-                   (int) (howmany(fd + 1, NFDBITS) * sizeof(fd_mask)))
+               while (fdsz < (int) SELECT_ALLOC_SIZE(fd + 1))
                        fdsz *= 2;
 
                if (fdsz != sop->event_fdsz) {
index bd52ced34ec6dc98c7575089b31d20df0289b6e1..72c0847ccd78ce2956c12879881a31e0d1399ec0 100644 (file)
@@ -169,11 +169,6 @@ evsig_cb(evutil_socket_t fd, short what, void *arg)
 int
 evsig_init(struct event_base *base)
 {
-#ifndef _EVENT_DISABLE_THREAD_SUPPORT
-       if (! evsig_base_lock)
-               EVTHREAD_ALLOC_LOCK(evsig_base_lock, 0);
-#endif
-
        /*
         * Our signal handler is going to write to one end of the socket
         * pair to wake up our event loop.  The event loop then scans for
@@ -437,3 +432,12 @@ evsig_dealloc(struct event_base *base)
                base->sig.sh_old = NULL;
        }
 }
+
+#ifndef _EVENT_DISABLE_THREAD_SUPPORT
+int
+evsig_global_setup_locks_(const int enable_locks)
+{
+       EVTHREAD_SETUP_GLOBAL_LOCK(evsig_base_lock, 0);
+       return 0;
+}
+#endif
index b867501f016750c69cf09e6f261c6ce65768a70e..66e01ea35e1103ac9833b6eaa8ba94a9e8bed056 100644 (file)
@@ -72,7 +72,13 @@ bench_httpclient_SOURCES = bench_httpclient.c
 bench_httpclient_LDADD = $(LIBEVENT_GC_SECTIONS) ../libevent_core.la
 
 regress.gen.c regress.gen.h: regress.rpc $(top_srcdir)/event_rpcgen.py
-       $(top_srcdir)/event_rpcgen.py $(srcdir)/regress.rpc || echo "No Python installed"
+       if $(top_srcdir)/event_rpcgen.py $(srcdir)/regress.rpc ; then \
+          echo "HI"; \
+       else \
+          echo "No Python installed; can't test RPC."; \
+          echo " "> regress.gen.c; \
+          echo "#define NO_PYTHON_EXISTS" > regress.gen.h; \
+       fi
 
 DISTCLEANFILES = *~
 
index e361d655af2da334cd451a57d4e459ac8d74e386..6f37db9b86ef398dbbb08a140b03ee764b6f46fb 100644 (file)
@@ -50,6 +50,11 @@ bench_http.exe: bench_http.obj
 bench_httpclient.exe: bench_httpclient.obj
        $(CC) $(CFLAGS) $(LIBS) bench_httpclient.obj
 
+regress.gen.c regress.gen.h: regress.rpc ../event_rpcgen.py
+       echo // > regress.gen.c
+       echo #define NO_PYTHON_EXISTS > regress.gen.h
+       -python ..\event_rpcgen.py regress.rpc
+
 clean:
        -del $(REGRESS_OBJS)
        -del $(OTHER_OBJS)
index b5f21623a8f459b80ec86309e201a79d391af9a6..03a27ead17c85fd6d4940aded9279b752365a1c8 100644 (file)
@@ -1037,13 +1037,69 @@ test_evbuffer_readln(void *ptr)
        free(cp); cp = NULL;
        evbuffer_validate(evb);
 
-       test_ok = 1;
  end:
        evbuffer_free(evb);
        evbuffer_free(evb_tmp);
        if (cp) free(cp);
 }
 
+static void
+test_evbuffer_search_eol(void *ptr)
+{
+       struct evbuffer *buf = evbuffer_new();
+       struct evbuffer_ptr ptr1, ptr2;
+       const char *s;
+       size_t eol_len;
+
+       s = "string! \r\n\r\nx\n";
+       evbuffer_add(buf, s, strlen(s));
+       eol_len = -1;
+       ptr1 = evbuffer_search_eol(buf, NULL, &eol_len, EVBUFFER_EOL_CRLF);
+       tt_int_op(ptr1.pos, ==, 8);
+       tt_int_op(eol_len, ==, 2);
+
+       eol_len = -1;
+       ptr2 = evbuffer_search_eol(buf, &ptr1, &eol_len, EVBUFFER_EOL_CRLF);
+       tt_int_op(ptr2.pos, ==, 8);
+       tt_int_op(eol_len, ==, 2);
+
+       evbuffer_ptr_set(buf, &ptr1, 1, EVBUFFER_PTR_ADD);
+       eol_len = -1;
+       ptr2 = evbuffer_search_eol(buf, &ptr1, &eol_len, EVBUFFER_EOL_CRLF);
+       tt_int_op(ptr2.pos, ==, 9);
+       tt_int_op(eol_len, ==, 1);
+
+       eol_len = -1;
+       ptr2 = evbuffer_search_eol(buf, &ptr1, &eol_len, EVBUFFER_EOL_CRLF_STRICT);
+       tt_int_op(ptr2.pos, ==, 10);
+       tt_int_op(eol_len, ==, 2);
+
+       eol_len = -1;
+       ptr1 = evbuffer_search_eol(buf, NULL, &eol_len, EVBUFFER_EOL_LF);
+       tt_int_op(ptr1.pos, ==, 9);
+       tt_int_op(eol_len, ==, 1);
+
+       eol_len = -1;
+       ptr2 = evbuffer_search_eol(buf, &ptr1, &eol_len, EVBUFFER_EOL_LF);
+       tt_int_op(ptr2.pos, ==, 9);
+       tt_int_op(eol_len, ==, 1);
+
+       evbuffer_ptr_set(buf, &ptr1, 1, EVBUFFER_PTR_ADD);
+       eol_len = -1;
+       ptr2 = evbuffer_search_eol(buf, &ptr1, &eol_len, EVBUFFER_EOL_LF);
+       tt_int_op(ptr2.pos, ==, 11);
+       tt_int_op(eol_len, ==, 1);
+
+       tt_assert(evbuffer_ptr_set(buf, &ptr1, evbuffer_get_length(buf), EVBUFFER_PTR_SET) == 0);
+       eol_len = -1;
+       ptr2 = evbuffer_search_eol(buf, &ptr1, &eol_len, EVBUFFER_EOL_LF);
+       tt_int_op(ptr2.pos, ==, -1);
+       tt_int_op(eol_len, ==, 0);
+
+end:
+       evbuffer_free(buf);
+}
+
 static void
 test_evbuffer_iterative(void *ptr)
 {
@@ -1140,6 +1196,15 @@ test_evbuffer_ptr_set(void *ptr)
        struct evbuffer_ptr pos;
        struct evbuffer_iovec v[1];
 
+       tt_int_op(evbuffer_get_length(buf), ==, 0);
+
+       tt_assert(evbuffer_ptr_set(buf, &pos, 0, EVBUFFER_PTR_SET) == 0);
+       tt_assert(pos.pos == 0);
+       tt_assert(evbuffer_ptr_set(buf, &pos, 1, EVBUFFER_PTR_ADD) == -1);
+       tt_assert(pos.pos == -1);
+       tt_assert(evbuffer_ptr_set(buf, &pos, 1, EVBUFFER_PTR_SET) == -1);
+       tt_assert(pos.pos == -1);
+
        /* create some chains */
        evbuffer_reserve_space(buf, 5000, v, 1);
        v[0].iov_len = 5000;
@@ -1172,6 +1237,8 @@ test_evbuffer_ptr_set(void *ptr)
        tt_assert(pos.pos == 10000);
        tt_assert(evbuffer_ptr_set(buf, &pos, 1000, EVBUFFER_PTR_ADD) == 0);
        tt_assert(pos.pos == 11000);
+       tt_assert(evbuffer_ptr_set(buf, &pos, 1000, EVBUFFER_PTR_ADD) == 0);
+       tt_assert(pos.pos == 12000);
        tt_assert(evbuffer_ptr_set(buf, &pos, 1000, EVBUFFER_PTR_ADD) == -1);
        tt_assert(pos.pos == -1);
 
@@ -1187,6 +1254,18 @@ test_evbuffer_search(void *ptr)
        struct evbuffer *tmp = evbuffer_new();
        struct evbuffer_ptr pos, end;
 
+       pos = evbuffer_search(buf, "x", 1, NULL);
+       tt_int_op(pos.pos, ==, -1);
+       tt_assert(evbuffer_ptr_set(buf, &pos, 0, EVBUFFER_PTR_SET) == 0);
+       pos = evbuffer_search(buf, "x", 1, &pos);
+       tt_int_op(pos.pos, ==, -1);
+       tt_assert(evbuffer_ptr_set(buf, &pos, 0, EVBUFFER_PTR_SET) == 0);
+       pos = evbuffer_search_range(buf, "x", 1, &pos, &pos);
+       tt_int_op(pos.pos, ==, -1);
+       tt_assert(evbuffer_ptr_set(buf, &pos, 0, EVBUFFER_PTR_SET) == 0);
+       pos = evbuffer_search_range(buf, "x", 1, &pos, NULL);
+       tt_int_op(pos.pos, ==, -1);
+
        /* set up our chains */
        evbuffer_add_printf(tmp, "hello");  /* 5 chars */
        evbuffer_add_buffer(buf, tmp);
@@ -1230,6 +1309,21 @@ test_evbuffer_search(void *ptr)
        pos = evbuffer_search_range(buf, "ack", 3, NULL, &end);
        tt_int_op(pos.pos, ==, -1);
 
+       /* Set "end" after the last byte in the buffer. */
+       tt_assert(evbuffer_ptr_set(buf, &end, 17, EVBUFFER_PTR_SET) == 0);
+
+       pos = evbuffer_search_range(buf, "attack", 6, NULL, &end);
+       tt_int_op(pos.pos, ==, 11);
+       tt_assert(evbuffer_ptr_set(buf, &pos, 11, EVBUFFER_PTR_SET) == 0);
+       pos = evbuffer_search_range(buf, "attack", 6, &pos, &end);
+       tt_int_op(pos.pos, ==, 11);
+       tt_assert(evbuffer_ptr_set(buf, &pos, 17, EVBUFFER_PTR_SET) == 0);
+       pos = evbuffer_search_range(buf, "attack", 6, &pos, &end);
+       tt_int_op(pos.pos, ==, -1);
+       tt_assert(evbuffer_ptr_set(buf, &pos, 17, EVBUFFER_PTR_SET) == 0);
+       pos = evbuffer_search_range(buf, "attack", 6, &pos, NULL);
+       tt_int_op(pos.pos, ==, -1);
+
 end:
        if (buf)
                evbuffer_free(buf);
@@ -1579,6 +1673,13 @@ test_evbuffer_peek(void *info)
        tt_iov_eq(&v[0], "Contents of chunk [2]\n");
        tt_iov_eq(&v[1], "Contents of chunk [3]\n"); /*more than we asked for*/
 
+       /* peek at the end of the buffer */
+       memset(v, 0, sizeof(v));
+       tt_assert(evbuffer_ptr_set(buf, &ptr, evbuffer_get_length(buf), EVBUFFER_PTR_SET) == 0);
+       i = evbuffer_peek(buf, 44, &ptr, v, 20);
+       tt_int_op(i, ==, 0);
+       tt_assert(v[0].iov_base == NULL);
+
 end:
        if (buf)
                evbuffer_free(buf);
@@ -1704,6 +1805,7 @@ struct testcase_t evbuffer_testcases[] = {
        { "reference", test_evbuffer_reference, 0, NULL, NULL },
        { "iterative", test_evbuffer_iterative, 0, NULL, NULL },
        { "readln", test_evbuffer_readln, TT_NO_LOGS, &basic_setup, NULL },
+       { "search_eol", test_evbuffer_search_eol, 0, NULL, NULL },
        { "find", test_evbuffer_find, 0, NULL, NULL },
        { "ptr_set", test_evbuffer_ptr_set, 0, NULL, NULL },
        { "search", test_evbuffer_search, 0, NULL, NULL },
index d9d59ec03ff384ab1f6805e5e3716462b3e1be50..530b6bf447d29b2a5c3d93f8c9b93c5dd1bab2f4 100644 (file)
@@ -71,6 +71,8 @@
 #include "regress.h"
 #include "regress_testutils.h"
 
+#ifndef NO_PYTHON_EXISTS
+
 static struct evhttp *
 http_setup(ev_uint16_t *pport)
 {
@@ -870,6 +872,13 @@ end:
        { #name, run_legacy_test_fn, TT_FORK|TT_NEED_BASE|TT_LEGACY,    \
                    &legacy_setup,                                      \
                    rpc_##name }
+#else
+/* NO_PYTHON_EXISTS */
+
+#define RPC_LEGACY(name) \
+       { #name, NULL, TT_SKIP, NULL, NULL }
+
+#endif
 
 struct testcase_t rpc_testcases[] = {
        RPC_LEGACY(basic_test),
index 00b87c13e2433be46142b98daf82f05d4cd4a81b..66c2af87625aacf78296777ca1d48b0dcc3d1e5c 100644 (file)
@@ -380,6 +380,11 @@ test_evutil_snprintf(void *ptr)
 {
        char buf[16];
        int r;
+       ev_uint64_t u64 = ((ev_uint64_t)1000000000)*200;
+       ev_int64_t i64 = -1 * (ev_int64_t) u64;
+       size_t size = 8000;
+       ev_ssize_t ssize = -9000;
+
        r = evutil_snprintf(buf, sizeof(buf), "%d %d", 50, 100);
        tt_str_op(buf, ==, "50 100");
        tt_int_op(r, ==, 6);
@@ -388,6 +393,19 @@ test_evutil_snprintf(void *ptr)
        tt_str_op(buf, ==, "longish 1234567");
        tt_int_op(r, ==, 18);
 
+       r = evutil_snprintf(buf, sizeof(buf), EV_U64_FMT, EV_U64_ARG(u64));
+       tt_str_op(buf, ==, "200000000000");
+       tt_int_op(r, ==, 12);
+
+       r = evutil_snprintf(buf, sizeof(buf), EV_I64_FMT, EV_I64_ARG(i64));
+       tt_str_op(buf, ==, "-200000000000");
+       tt_int_op(r, ==, 13);
+
+       r = evutil_snprintf(buf, sizeof(buf), EV_SIZE_FMT" "EV_SSIZE_FMT,
+           EV_SIZE_ARG(size), EV_SSIZE_ARG(ssize));
+       tt_str_op(buf, ==, "8000 -9000");
+       tt_int_op(r, ==, 10);
+
       end:
        ;
 }
index 08a4cddb7a977096ce16d75a39017b842fd8a572..58ab553113db2033da24230585be7577941243f2 100755 (executable)
@@ -114,49 +114,27 @@ run_tests () {
        fi
 }
 
+do_test() {
+       setup
+       announce "$1 $2"
+       unset EVENT_NO$1
+       if test "$2" = "(changelist)" ; then
+           EVENT_EPOLL_USE_CHANGELIST=yes; export EVENT_EPOLL_USE_CHANGELIST
+        fi
+       run_tests
+}
+
 announce "Running tests:"
 
 # Need to do this by hand?
-setup
-unset EVENT_NOEVPORT
-announce "EVPORT"
-run_tests
-
-setup
-unset EVENT_NOKQUEUE
-announce "KQUEUE"
-run_tests
-
-setup
-unset EVENT_NOEPOLL
-announce "EPOLL"
-run_tests
-
-setup
-unset EVENT_NOEPOLL
-EVENT_EPOLL_USE_CHANGELIST=yes; export EVENT_EPOLL_USE_CHANGELIST
-announce "EPOLL (changelist)"
-run_tests
-
-setup
-unset EVENT_NODEVPOLL
-announce "DEVPOLL"
-run_tests
-
-setup
-unset EVENT_NOPOLL
-announce "POLL"
-run_tests
-
-setup
-unset EVENT_NOSELECT
-announce "SELECT"
-run_tests
-
-setup
-unset EVENT_NOWIN32
-announce "WIN32"
-run_tests
+do_test EVPORT
+do_test KQUEUE
+do_test EPOLL
+do_test EPOLL "(changelist)"
+do_test DEVPOLL
+do_test POLL
+do_test SELECT
+do_test WIN32
 
 if test "$FAILED" = "yes"; then
        exit 1
index 8caa4f5453dc5ce6a682e3a898b67267e4f5962c..051d9f9347c9950f39693b3985ac3d0632000384 100644 (file)
@@ -66,8 +66,8 @@ const char *cur_test_prefix = NULL; /**< prefix of the current test group */
 const char *cur_test_name = NULL;
 
 #ifdef _WIN32
-/** Pointer to argv[0] for win32. */
-static const char *commandname = NULL;
+/* Copy of argv[0] for win32. */
+static char commandname[MAX_PATH+1];
 #endif
 
 static void usage(struct testgroup_t *groups, int list_groups)
@@ -291,7 +291,12 @@ tinytest_main(int c, const char **v, struct testgroup_t *groups)
        int i, j, n=0;
 
 #ifdef _WIN32
-       commandname = v[0];
+       const char *sp = strrchr(v[0], '.');
+       const char *extension = "";
+       if (!sp || stricmp(sp, ".exe"))
+               extension = ".exe"; /* Add an exe so CreateProcess will work */
+       snprintf(commandname, sizeof(commandname), "%s%s", v[0], extension);
+       commandname[MAX_PATH]='\0';
 #endif
        for (i=1; i<c; ++i) {
                if (v[i][0] == '-') {
index 770d158cf5e2fd583d705c74b949271974039863..0ff1ce06ab368a148f92b1319cd1d951326481dc 100644 (file)
@@ -272,6 +272,43 @@ int evutil_hex_char_to_int(char c);
 HANDLE evutil_load_windows_system_library(const TCHAR *library_name);
 #endif
 
+#ifndef EV_SIZE_FMT
+#if defined(_MSC_VER) || defined(__MINGW32__) || defined(__MINGW64__)
+#define EV_U64_FMT "%I64u"
+#define EV_I64_FMT "%I64d"
+#define EV_I64_ARG(x) ((__int64)(x))
+#define EV_U64_ARG(x) ((unsigned __int64)(x))
+#else
+#define EV_U64_FMT "%llu"
+#define EV_I64_FMT "%lld"
+#define EV_I64_ARG(x) ((long long)(x))
+#define EV_U64_ARG(x) ((unsigned long long)(x))
+#endif
+#endif
+
+#if defined(__STDC__) && defined(__STDC_VERSION__)
+#if (__STDC_VERSION__ >= 199901L)
+#define EV_SIZE_FMT "%zu"
+#define EV_SSIZE_FMT "%zd"
+#define EV_SIZE_ARG(x) (x)
+#define EV_SSIZE_ARG(x) (x)
+#endif
+#endif
+
+#ifndef EV_SIZE_FMT
+#if (_EVENT_SIZEOF_SIZE_T <= _EVENT_SIZEOF_LONG)
+#define EV_SIZE_FMT "%lu"
+#define EV_SSIZE_FMT "%ld"
+#define EV_SIZE_ARG(x) ((unsigned long)(x))
+#define EV_SSIZE_ARG(x) ((long)(x))
+#else
+#define EV_SIZE_FMT EV_U64_FMT
+#define EV_SSIZE_FMT EV_I64_FMT
+#define EV_SIZE_ARG(x) EV_U64_ARG(x)
+#define EV_SSIZE_ARG(x) EV_I64_ARG(x)
+#endif
+#endif
+
 #ifdef __cplusplus
 }
 #endif