diff --git a/ChangeLog b/ChangeLog index 576345b7..d42a90ae 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,6 +1,7 @@ Changes in current version: o free minheap on event_base_free(); from Christopher Layne o debug cleanups in signal.c; from Christopher Layne + o provide event_base_new() that does not set the current_base global Changes in 1.4.0: o allow \r or \n individually to separate HTTP headers instead of the standard "\r\n"; from Charles Kerr. diff --git a/event.c b/event.c index cb7f4d40..3e6295cb 100644 --- a/event.c +++ b/event.c @@ -157,6 +157,17 @@ gettime(struct timeval *tp) struct event_base * event_init(void) +{ + struct event_base *base = event_base_new(); + + if (base != NULL) + current_base = base; + + return (base); +} + +struct event_base * +event_base_new(void) { int i; struct event_base *base; @@ -193,7 +204,6 @@ event_init(void) /* allocate a single active event queue */ event_base_priority_init(base, 1); - current_base = base; return (base); } diff --git a/event.h b/event.h index 7eeaccbc..4dd87338 100644 --- a/event.h +++ b/event.h @@ -55,8 +55,8 @@ Every program that uses libevent must include the header, and pass the -levent flag to the linker. Before using any of the functions in the - library, you must call event_init() to perform one-time initialization of - the libevent library. + library, you must call event_init() or event_base_new() to perform one-time + initialization of the libevent library. @section event Event notification @@ -267,11 +267,25 @@ struct eventop { void (*dealloc)(struct event_base *, void *); }; +/** + Initialize the event API. + + Use event_base_new() to initialize a new event base, but does not set + the current_base global. If using only event_base_new(), each event + added must have an event base set with event_base_set() + + @see event_base_set(), event_base_free(), event_init() + */ +struct event_base *event_base_new(void); + /** Initialize the event API. The event API needs to be initialized with event_init() before it can be - used. + used. Sets the current_base global representing the default base for + events that have no base associated with them. + + @see event_base_set(), event_base_new() */ struct event_base *event_init(void); diff --git a/test/regress.c b/test/regress.c index 105ac504..a153da48 100644 --- a/test/regress.c +++ b/test/regress.c @@ -647,6 +647,28 @@ test_free_active_base(void) cleanup_test(); } +void +test_event_base_new(void) +{ + struct event_base *base; + struct event ev1; + setup_test("Event base new: "); + + write(pair[0], TEST1, strlen(TEST1)+1); + shutdown(pair[0], SHUT_WR); + + base = event_base_new(); + event_set(&ev1, pair[1], EV_READ, simple_read_cb, &ev1); + event_base_set(base, &ev1); + event_add(&ev1, NULL); + + event_base_dispatch(base); + + event_base_free(base); + test_ok = 1; + cleanup_test(); +} + void test_loopexit(void) { @@ -1155,6 +1177,8 @@ main (int argc, char **argv) test_free_active_base(); + test_event_base_new(); + http_suite(); rpc_suite();