summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNiels Provos <provos@gmail.com>2007-11-14 17:52:21 +0000
committerNiels Provos <provos@gmail.com>2007-11-14 17:52:21 +0000
commitf586f42885b7558b1617396f53f19299f7c46ba8 (patch)
treeb71537c07684e760497d3da4a4b51ca31d8547c0
parent56934d5d977892afa1342c8c3f55035989626bc5 (diff)
downloadlibevent-f586f42885b7558b1617396f53f19299f7c46ba8.tar.gz
provide event_base_new() as a mechanism for not setting the current_global
svn:r529
-rw-r--r--ChangeLog1
-rw-r--r--event.c12
-rw-r--r--event.h20
-rw-r--r--test/regress.c24
4 files changed, 53 insertions, 4 deletions
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
@@ -158,6 +158,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 <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() 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
@@ -270,8 +270,22 @@ struct eventop {
/**
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
@@ -648,6 +648,28 @@ test_free_active_base(void)
}
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)
{
struct timeval tv, tv_start, tv_end;
@@ -1155,6 +1177,8 @@ main (int argc, char **argv)
test_free_active_base();
+ test_event_base_new();
+
http_suite();
rpc_suite();