From 5792d42f0ff130380d036ff427d8408ecd61b6f2 Mon Sep 17 00:00:00 2001 From: Niels Provos Date: Sun, 16 Nov 2008 23:22:14 +0000 Subject: [PATCH] Allow setting of local port for evhttp connections to support millions of connections from a single system; from Richard Jones svn:r948 --- ChangeLog | 1 + http-internal.h | 1 + http.c | 10 +++++++++- include/event2/http.h | 4 ++++ 4 files changed, 15 insertions(+), 1 deletion(-) diff --git a/ChangeLog b/ChangeLog index cbf18157..e7e4634e 100644 --- a/ChangeLog +++ b/ChangeLog @@ -127,6 +127,7 @@ Changes in current version: o Do not remove Accept-Encoding header 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.0: o allow \r or \n individually to separate HTTP headers instead of the standard "\r\n"; from Charles Kerr. diff --git a/http-internal.h b/http-internal.h index b1225a87..a02a57e7 100644 --- a/http-internal.h +++ b/http-internal.h @@ -65,6 +65,7 @@ struct evhttp_connection { struct event close_ev; 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; diff --git a/http.c b/http.c index 6f1e0b0e..bfd3456a 100644 --- a/http.c +++ b/http.c @@ -982,6 +982,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, + ev_uint16_t port) +{ + assert(evcon->state == EVCON_DISCONNECTED); + evcon->bind_port = port; +} static void evhttp_request_dispatch(struct evhttp_connection* evcon) @@ -1761,7 +1768,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)); diff --git a/include/event2/http.h b/include/event2/http.h index a10d0c1e..97949f30 100644 --- a/include/event2/http.h +++ b/include/event2/http.h @@ -312,6 +312,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, + ev_uint16_t port); + /** Sets the timeout for events related to this connection */ void evhttp_connection_set_timeout(struct evhttp_connection *evcon, int timeout_in_secs); -- 2.40.0