From 3b2022ef3a9eba280b256ac7bbe99f224a8584ad Mon Sep 17 00:00:00 2001 From: Niels Provos Date: Thu, 8 May 2008 05:33:15 +0000 Subject: [PATCH] provide an api for retrieving the supported event mechanisms svn:r788 --- ChangeLog | 2 +- event.c | 30 ++++++++++++++++++++++++++++++ include/event2/event.h | 12 ++++++++++++ test/regress.c | 22 ++++++++++++++++++++++ 4 files changed, 65 insertions(+), 1 deletion(-) diff --git a/ChangeLog b/ChangeLog index 2314a58b..bca7bf80 100644 --- a/ChangeLog +++ b/ChangeLog @@ -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. diff --git a/event.c b/event.c index 568a0afd..11c91864 100644 --- a/event.c +++ b/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) { diff --git a/include/event2/event.h b/include/event2/event.h index 69529e30..4ceede73 100644 --- a/include/event2/event.h +++ b/include/event2/event.h @@ -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); /** diff --git a/test/regress.c b/test/regress.c index 45105341..b8c69f0e 100644 --- a/test/regress.c +++ b/test/regress.c @@ -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(); -- 2.50.0