from trunk: Allow setting of local port for evhttp connections to support millions of connections from a single system; from Richard Jones

svn:r949
This commit is contained in:
Niels Provos 2008-11-16 23:26:38 +00:00
parent 3ad06489ee
commit 0a41d762ec
4 changed files with 15 additions and 1 deletions

View File

@ -2,6 +2,7 @@ Changes in 1.4.9-stable:
o event_add would not return error for some backends; from Dean McNamee
o Clear the timer cache on entering the event loop; reported by Victor Chang
o Only bind the socket on connect when a local address has been provided; reported by Alejo Sanchez
o Allow setting of local port for evhttp connections to support millions of connections from a single system; from Richard Jones.
Changes in 1.4.8-stable:
o Match the query in DNS replies to the query in the request; from Vsevolod Stakhov.

View File

@ -267,6 +267,10 @@ void evhttp_connection_free(struct evhttp_connection *evcon);
void evhttp_connection_set_local_address(struct evhttp_connection *evcon,
const char *address);
/** sets the local port from which http connections are made */
void evhttp_connection_set_local_port(struct evhttp_connection *evcon,
unsigned short port);
/** Sets the timeout for events related to this connection */
void evhttp_connection_set_timeout(struct evhttp_connection *evcon,
int timeout_in_secs);

View File

@ -61,6 +61,7 @@ struct evhttp_connection {
struct evbuffer *output_buffer;
char *bind_address; /* address to use for binding the src */
u_short bind_port; /* local port for binding the src */
char *address; /* address to connect to */
u_short port;

10
http.c
View File

@ -1038,6 +1038,13 @@ evhttp_connection_set_local_address(struct evhttp_connection *evcon,
event_err(1, "%s: strdup", __func__);
}
void
evhttp_connection_set_local_port(struct evhttp_connection *evcon,
unsigned short port)
{
assert(evcon->state == EVCON_DISCONNECTED);
evcon->bind_port = port;
}
static void
evhttp_request_dispatch(struct evhttp_connection* evcon)
@ -1731,7 +1738,8 @@ evhttp_connection_connect(struct evhttp_connection *evcon)
assert(!(evcon->flags & EVHTTP_CON_INCOMING));
evcon->flags |= EVHTTP_CON_OUTGOING;
evcon->fd = bind_socket(evcon->bind_address, 0 /*port*/, 0 /*reuse*/);
evcon->fd = bind_socket(
evcon->bind_address, evcon->bind_port, 0 /*reuse*/);
if (evcon->fd == -1) {
event_debug(("%s: failed to bind to \"%s\"",
__func__, evcon->bind_address));