]> granicus.if.org Git - libevent/commitdiff
evhttp: Add evhttp_foreach_bound_socket.
authorSamy Al Bahra <sbahra@appnexus.com>
Mon, 24 Oct 2011 01:31:55 +0000 (01:31 +0000)
committerNick Mathewson <nickm@torproject.org>
Wed, 26 Oct 2011 02:17:24 +0000 (22:17 -0400)
Applies the function specified in the first argument to all
evhttp_bound_sockets associated with a struct evhttp. The user
must not attempt to free or remove any connections, sockets or
listeners in the callback function.

http.c
include/event2/http.h

diff --git a/http.c b/http.c
index abc73471b58b0d88c10b27df71b9dab1094eacc3..f9feabdf55a2306a562e533e3181fa89c36886d9 100644 (file)
--- a/http.c
+++ b/http.c
@@ -3239,6 +3239,16 @@ evhttp_accept_socket(struct evhttp *http, evutil_socket_t fd)
        return (0);
 }
 
+void
+evhttp_foreach_bound_socket(struct evhttp *http,
+                            evhttp_bound_socket_foreach_fn *function,
+                            void *argument)
+{
+       struct evhttp_bound_socket *bound;
+
+       TAILQ_FOREACH(bound, &http->sockets, next)
+               function(bound, argument);
+}
 
 struct evhttp_bound_socket *
 evhttp_accept_socket_with_handle(struct evhttp *http, evutil_socket_t fd)
index 401635f74b3f3979cbfb0e3ecec03543a11dfaeb..9ae95d7625faec33795e436345fe46d6d1646e10 100644 (file)
@@ -150,6 +150,19 @@ struct evhttp_bound_socket *evhttp_bind_listener(struct evhttp *http, struct evc
  */
 struct evconnlistener *evhttp_bound_socket_get_listener(struct evhttp_bound_socket *bound);
 
+typedef void evhttp_bound_socket_foreach_fn(struct evhttp_bound_socket *, void *);
+/**
+ * Applies the function specified in the first argument to all
+ * evhttp_bound_sockets associated with "http". The user must not
+ * attempt to free or remove any connections, sockets or listeners
+ * in the callback "function".
+ *
+ * @param http pointer to an evhttp object
+ * @param function function to apply to every bound socket
+ * @param argument pointer value passed to function for every socket iterated
+ */
+void evhttp_foreach_bound_socket(struct evhttp *http, evhttp_bound_socket_foreach_fn *function, void *argument);
+
 /**
  * Makes an HTTP server stop accepting connections on the specified socket
  *