mirror of
https://github.com/cuberite/libevent.git
synced 2025-09-12 05:48:51 -04:00
provide an api for retrieving the supported event mechanisms
svn:r788
This commit is contained in:
parent
0a804f3c83
commit
3b2022ef3a
@ -91,7 +91,7 @@ Changes in current version:
|
||||
o support for virtual HTTP hosts.
|
||||
o turn event_initialized() into a function, and add function equivalents to EVENT_SIGNAL and EVENT_FD so that people don't need to include event_struct.h
|
||||
o Build test directory correctly with CPPFLAGS set.
|
||||
|
||||
o Provide an API for retrieving the supported event mechanisms.
|
||||
|
||||
Changes in 1.4.0:
|
||||
o allow \r or \n individually to separate HTTP headers instead of the standard "\r\n"; from Charles Kerr.
|
||||
|
30
event.c
30
event.c
@ -318,6 +318,36 @@ event_reinit(struct event_base *base)
|
||||
return (res);
|
||||
}
|
||||
|
||||
const char **
|
||||
event_supported_methods()
|
||||
{
|
||||
static const char **methods;
|
||||
const struct eventop **method;
|
||||
const char **tmp;
|
||||
int i = 0, k;
|
||||
|
||||
if (methods != NULL)
|
||||
return (methods);
|
||||
|
||||
/* count all methods */
|
||||
for (method = &eventops[0]; *method != NULL; ++method)
|
||||
++i;
|
||||
|
||||
/* allocate one more than we need for the NULL pointer */
|
||||
tmp = mm_malloc((i + 1) * sizeof(char *));
|
||||
if (tmp == NULL)
|
||||
return (NULL);
|
||||
|
||||
/* populate the array with the supported methods */
|
||||
for (k = 0; k < i; ++k)
|
||||
tmp[k] = eventops[k]->name;
|
||||
tmp[i] = NULL;
|
||||
|
||||
methods = tmp;
|
||||
|
||||
return (methods);
|
||||
}
|
||||
|
||||
int
|
||||
event_priority_init(int npriorities)
|
||||
{
|
||||
|
@ -97,6 +97,18 @@ int event_base_dispatch(struct event_base *);
|
||||
@return a string identifying the kernel event mechanism (kqueue, epoll, etc.)
|
||||
*/
|
||||
const char *event_base_get_method(struct event_base *);
|
||||
|
||||
/**
|
||||
Gets all event notification mechanisms supported by libevent.
|
||||
|
||||
This functions returns the event mechanism in order preferred
|
||||
by libevent.
|
||||
|
||||
@return an array with pointers to the names of support methods.
|
||||
The end of the array is indicated by a NULL pointer. If an
|
||||
error is encountered NULL is returned.
|
||||
*/
|
||||
const char **event_supported_methods(void);
|
||||
|
||||
|
||||
/**
|
||||
|
@ -2066,6 +2066,26 @@ test_evutil_strtoll(void)
|
||||
cleanup_test();
|
||||
}
|
||||
|
||||
static void
|
||||
test_methods(void)
|
||||
{
|
||||
const char **methods = event_supported_methods();
|
||||
|
||||
fprintf(stderr, "Testing supported methods: ");
|
||||
|
||||
if (methods == NULL) {
|
||||
fprintf(stderr, "FAILED\n");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
while (*methods != NULL) {
|
||||
fprintf(stderr, "%s ", *methods);
|
||||
++methods;
|
||||
}
|
||||
|
||||
fprintf(stderr, "OK\n");
|
||||
}
|
||||
|
||||
|
||||
int
|
||||
main (int argc, char **argv)
|
||||
@ -2082,6 +2102,8 @@ main (int argc, char **argv)
|
||||
|
||||
setvbuf(stdout, NULL, _IONBF, 0);
|
||||
|
||||
test_methods();
|
||||
|
||||
/* Initalize the event library */
|
||||
global_base = event_init();
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user