const int flags =
LEV_OPT_REUSEABLE|LEV_OPT_CLOSE_ON_EXEC|LEV_OPT_CLOSE_ON_FREE;
- bound = mm_malloc(sizeof(struct evhttp_bound_socket));
- if (bound == NULL)
- return (NULL);
-
- listener = evconnlistener_new(http->base, accept_socket_cb, http,
+ listener = evconnlistener_new(http->base, NULL, NULL,
flags,
0, /* Backlog is '0' because we already said 'listen' */
fd);
- if (!listener) {
- mm_free(bound);
+ if (!listener)
+ return (NULL);
+
+ bound = evhttp_bind_listener(http, listener);
+ if (!bound) {
+ evconnlistener_free(listener);
return (NULL);
}
- bound->listener = listener;
+ return (bound);
+}
+struct evhttp_bound_socket *
+evhttp_bind_listener(struct evhttp *http, struct evconnlistener *listener)
+{
+ struct evhttp_bound_socket *bound;
+
+ bound = mm_malloc(sizeof(struct evhttp_bound_socket));
+ if (bound == NULL)
+ return (NULL);
+
+ bound->listener = listener;
TAILQ_INSERT_TAIL(&http->sockets, bound, next);
- return (bound);
+ evconnlistener_set_cb(listener, accept_socket_cb, http);
+ return bound;
}
evutil_socket_t evhttp_bound_socket_get_fd(struct evhttp_bound_socket *bound)
return evconnlistener_get_fd(bound->listener);
}
+struct evconnlistener *
+evhttp_bound_socket_get_listener(struct evhttp_bound_socket *bound)
+{
+ return bound->listener;
+}
+
void
evhttp_del_accept_socket(struct evhttp *http, struct evhttp_bound_socket *bound)
{
struct evhttp_request;
struct evkeyvalq;
struct evhttp_bound_socket;
+struct evconnlistener;
/**
* Create a new HTTP server.
*/
struct evhttp_bound_socket *evhttp_accept_socket_with_handle(struct evhttp *http, evutil_socket_t fd);
+/**
+ * The most low-level evhttp_bind/accept method: takes an evconnlistener, and
+ * returns an evhttp_bound_socket. The listener will be freed when the bound
+ * socket is freed.
+ */
+struct evhttp_bound_socket *evhttp_bind_listener(struct evhttp *http, struct evconnlistener *listener);
+
+/**
+ * Return the listener used to implement a bound socket.
+ */
+struct evconnlistener *evhttp_bound_socket_get_listener(struct evhttp_bound_socket *bound);
+
/**
* Makes an HTTP server stop accepting connections on the specified socket
*