mirror of
https://github.com/cuberite/libevent.git
synced 2025-09-08 03:44:22 -04:00
provide event_base_new() as a mechanism for not setting the current_global
svn:r529
This commit is contained in:
parent
56934d5d97
commit
f586f42885
@ -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
12
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);
|
||||
}
|
||||
|
||||
|
20
event.h
20
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
|
||||
|
||||
@ -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);
|
||||
|
||||
|
@ -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();
|
||||
|
Loading…
x
Reference in New Issue
Block a user