mirror of
https://github.com/cuberite/libevent.git
synced 2025-09-10 13:04:23 -04:00
introduce evhttp_accept_socket() to accept from an already created socket
svn:r666
This commit is contained in:
parent
b14cd655d1
commit
0b114da2b6
@ -48,6 +48,7 @@ Changes in current version:
|
|||||||
o simplify evbuffer by removing orig_buffer
|
o simplify evbuffer by removing orig_buffer
|
||||||
o do not insert event into list when evsel->add fails
|
o do not insert event into list when evsel->add fails
|
||||||
o add support for PUT/DELETE requests; from Josh Rotenberg
|
o add support for PUT/DELETE requests; from Josh Rotenberg
|
||||||
|
o introduce evhttp_accept_socket() to accept from an already created socket
|
||||||
|
|
||||||
|
|
||||||
Changes in 1.4.0:
|
Changes in 1.4.0:
|
||||||
|
20
evhttp.h
20
evhttp.h
@ -40,6 +40,9 @@ extern "C" {
|
|||||||
#undef WIN32_LEAN_AND_MEAN
|
#undef WIN32_LEAN_AND_MEAN
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
/* For int types. */
|
||||||
|
#include <evutil.h>
|
||||||
|
|
||||||
/** @file evhttp.h
|
/** @file evhttp.h
|
||||||
*
|
*
|
||||||
* Basic support for HTTP serving.
|
* Basic support for HTTP serving.
|
||||||
@ -82,10 +85,25 @@ struct evhttp *evhttp_new(struct event_base *base);
|
|||||||
* @param address a string containing the IP address to listen(2) on
|
* @param address a string containing the IP address to listen(2) on
|
||||||
* @param port the port number to listen on
|
* @param port the port number to listen on
|
||||||
* @return 0 on success, -1 on failure.
|
* @return 0 on success, -1 on failure.
|
||||||
* @see evhttp_free()
|
* @see evhttp_free(), evhttp_accept_socket()
|
||||||
*/
|
*/
|
||||||
int evhttp_bind_socket(struct evhttp *http, const char *address, u_short port);
|
int evhttp_bind_socket(struct evhttp *http, const char *address, u_short port);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Makes an HTTP server accept connections on the specified socket
|
||||||
|
*
|
||||||
|
* This may be useful to create a socket and then fork multiple instances
|
||||||
|
* of an http server, or when a socket has been communicated via file
|
||||||
|
* descriptor passing in situations where an http servers does not have
|
||||||
|
* permissions to bind to a low-numbered port.
|
||||||
|
*
|
||||||
|
* @param http a pointer to an evhttp object
|
||||||
|
* @param fd a socket fd that is ready for accepting connections
|
||||||
|
* @return 0 on success, -1 on failure.
|
||||||
|
* @see evhttp_free(), evhttp_bind_socket()
|
||||||
|
*/
|
||||||
|
int evhttp_accept_socket(struct evhttp *http, evutil_socket_t fd);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Free the previously created HTTP server.
|
* Free the previously created HTTP server.
|
||||||
*
|
*
|
||||||
|
22
http.c
22
http.c
@ -2009,8 +2009,8 @@ accept_socket(evutil_socket_t fd, short what, void *arg)
|
|||||||
int
|
int
|
||||||
evhttp_bind_socket(struct evhttp *http, const char *address, u_short port)
|
evhttp_bind_socket(struct evhttp *http, const char *address, u_short port)
|
||||||
{
|
{
|
||||||
struct event *ev = &http->bind_ev;
|
|
||||||
evutil_socket_t fd;
|
evutil_socket_t fd;
|
||||||
|
int res;
|
||||||
|
|
||||||
if ((fd = bind_socket(address, port)) == -1)
|
if ((fd = bind_socket(address, port)) == -1)
|
||||||
return (-1);
|
return (-1);
|
||||||
@ -2021,14 +2021,24 @@ evhttp_bind_socket(struct evhttp *http, const char *address, u_short port)
|
|||||||
return (-1);
|
return (-1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
res = evhttp_accept_socket(http, fd);
|
||||||
|
|
||||||
|
if (res != -1)
|
||||||
|
event_debug(("Bound to port %d - Awaiting connections ... ",
|
||||||
|
port));
|
||||||
|
|
||||||
|
return (res);
|
||||||
|
}
|
||||||
|
|
||||||
|
int
|
||||||
|
evhttp_accept_socket(struct evhttp *http, evutil_socket_t fd)
|
||||||
|
{
|
||||||
|
struct event *ev = &http->bind_ev;
|
||||||
|
|
||||||
/* Schedule the socket for accepting */
|
/* Schedule the socket for accepting */
|
||||||
event_set(ev, fd, EV_READ | EV_PERSIST, accept_socket, http);
|
event_set(ev, fd, EV_READ | EV_PERSIST, accept_socket, http);
|
||||||
EVHTTP_BASE_SET(http, ev);
|
EVHTTP_BASE_SET(http, ev);
|
||||||
event_add(ev, NULL);
|
return (event_add(ev, NULL));
|
||||||
|
|
||||||
event_debug(("Bound to port %d - Awaiting connections ... ", port));
|
|
||||||
|
|
||||||
return (0);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static struct evhttp*
|
static struct evhttp*
|
||||||
|
Loading…
x
Reference in New Issue
Block a user