provide event_base_new() as a mechanism for not setting the current_global

svn:r529
This commit is contained in:
Niels Provos 2007-11-14 17:52:21 +00:00
parent 56934d5d97
commit f586f42885
4 changed files with 53 additions and 4 deletions

View File

@ -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.

12
event.c
View File

@ -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);
}

20
event.h
View File

@ -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
@ -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);

View File

@ -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();