]> granicus.if.org Git - libevent/commitdiff
provide an api for retrieving the supported event mechanisms
authorNiels Provos <provos@gmail.com>
Thu, 8 May 2008 05:33:15 +0000 (05:33 +0000)
committerNiels Provos <provos@gmail.com>
Thu, 8 May 2008 05:33:15 +0000 (05:33 +0000)
svn:r788

ChangeLog
event.c
include/event2/event.h
test/regress.c

index 2314a58b6bee5246e3ad5d820619eb0a1fd449e0..bca7bf80be9a8ea8e58fe08f9cac41cd627276bf 100644 (file)
--- 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 568a0afd4663e8f727361a860f6de65a24fbb847..11c91864058f71e0d58a0d7b891afd3e35ca1297 100644 (file)
--- 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)
 {
index 69529e304927b4e290f73e7d4f682609adb6b564..4ceede73e373dedcbfbb059d1b2b04745abeb775 100644 (file)
@@ -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);
         
         
 /**
index 451053411d1c3cc4ceaa0d7845ffde2eb248cd54..b8c69f0ead91f6aa995b721f2dcc83625aea06a4 100644 (file)
@@ -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();