mirror of
https://github.com/cuberite/libevent.git
synced 2025-09-12 13:58:58 -04:00
Functions to actually use evhttp_bound_socket with/as evconnlistener.
This commit is contained in:
parent
46ee061ca0
commit
006efa7dbb
38
http.c
38
http.c
@ -2764,23 +2764,35 @@ evhttp_accept_socket_with_handle(struct evhttp *http, evutil_socket_t fd)
|
|||||||
const int flags =
|
const int flags =
|
||||||
LEV_OPT_REUSEABLE|LEV_OPT_CLOSE_ON_EXEC|LEV_OPT_CLOSE_ON_FREE;
|
LEV_OPT_REUSEABLE|LEV_OPT_CLOSE_ON_EXEC|LEV_OPT_CLOSE_ON_FREE;
|
||||||
|
|
||||||
|
listener = evconnlistener_new(http->base, NULL, NULL,
|
||||||
|
flags,
|
||||||
|
0, /* Backlog is '0' because we already said 'listen' */
|
||||||
|
fd);
|
||||||
|
if (!listener)
|
||||||
|
return (NULL);
|
||||||
|
|
||||||
|
bound = evhttp_bind_listener(http, listener);
|
||||||
|
if (!bound) {
|
||||||
|
evconnlistener_free(listener);
|
||||||
|
return (NULL);
|
||||||
|
}
|
||||||
|
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));
|
bound = mm_malloc(sizeof(struct evhttp_bound_socket));
|
||||||
if (bound == NULL)
|
if (bound == NULL)
|
||||||
return (NULL);
|
return (NULL);
|
||||||
|
|
||||||
listener = evconnlistener_new(http->base, accept_socket_cb, http,
|
|
||||||
flags,
|
|
||||||
0, /* Backlog is '0' because we already said 'listen' */
|
|
||||||
fd);
|
|
||||||
if (!listener) {
|
|
||||||
mm_free(bound);
|
|
||||||
return (NULL);
|
|
||||||
}
|
|
||||||
bound->listener = listener;
|
bound->listener = listener;
|
||||||
|
|
||||||
TAILQ_INSERT_TAIL(&http->sockets, bound, next);
|
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)
|
evutil_socket_t evhttp_bound_socket_get_fd(struct evhttp_bound_socket *bound)
|
||||||
@ -2788,6 +2800,12 @@ evutil_socket_t evhttp_bound_socket_get_fd(struct evhttp_bound_socket *bound)
|
|||||||
return evconnlistener_get_fd(bound->listener);
|
return evconnlistener_get_fd(bound->listener);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
struct evconnlistener *
|
||||||
|
evhttp_bound_socket_get_listener(struct evhttp_bound_socket *bound)
|
||||||
|
{
|
||||||
|
return bound->listener;
|
||||||
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
evhttp_del_accept_socket(struct evhttp *http, struct evhttp_bound_socket *bound)
|
evhttp_del_accept_socket(struct evhttp *http, struct evhttp_bound_socket *bound)
|
||||||
{
|
{
|
||||||
|
@ -63,6 +63,7 @@ struct evhttp;
|
|||||||
struct evhttp_request;
|
struct evhttp_request;
|
||||||
struct evkeyvalq;
|
struct evkeyvalq;
|
||||||
struct evhttp_bound_socket;
|
struct evhttp_bound_socket;
|
||||||
|
struct evconnlistener;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a new HTTP server.
|
* Create a new HTTP server.
|
||||||
@ -130,6 +131,18 @@ int evhttp_accept_socket(struct evhttp *http, evutil_socket_t fd);
|
|||||||
*/
|
*/
|
||||||
struct evhttp_bound_socket *evhttp_accept_socket_with_handle(struct evhttp *http, evutil_socket_t fd);
|
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
|
* Makes an HTTP server stop accepting connections on the specified socket
|
||||||
*
|
*
|
||||||
|
Loading…
x
Reference in New Issue
Block a user