]> granicus.if.org Git - libevent/commitdiff
Allow setting of local port for evhttp connections to support millions of connections...
authorNiels Provos <provos@gmail.com>
Sun, 16 Nov 2008 23:22:14 +0000 (23:22 +0000)
committerNiels Provos <provos@gmail.com>
Sun, 16 Nov 2008 23:22:14 +0000 (23:22 +0000)
svn:r948

ChangeLog
http-internal.h
http.c
include/event2/http.h

index cbf18157cbcfa0490e5b573ff08e4c55b389ff28..e7e4634ea600f667451a9d1cfa6f80c320e93c5f 100644 (file)
--- 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.
index b1225a8759c368bb5151b414f9636d3732b6f07a..a02a57e7d5d35e5f223c141806ea9d44bbf3ee25 100644 (file)
@@ -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 6f1e0b0ea73a02711cb98e865b234634ee27b4c1..bfd3456ae6fe99481a061ce13fe00a08c8bef1cc 100644 (file)
--- 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));
index a10d0c1e1cc6cf1830c31923dc1d517560dd33b0..97949f30ad42fc0c84e629baf995f3e339e1af70 100644 (file)
@@ -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);