From fb0b274e9710adfcdd78cfc098e112b203fffde4 Mon Sep 17 00:00:00 2001 From: Niels Provos Date: Fri, 20 Jun 2008 06:55:26 +0000 Subject: [PATCH] from trunk: do not use SO_REUSEADDR when connecting svn:r855 --- ChangeLog | 1 + http.c | 19 +++++++++++-------- 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/ChangeLog b/ChangeLog index db184b25..fce08669 100644 --- a/ChangeLog +++ b/ChangeLog @@ -4,6 +4,7 @@ Changes in 1.4.5-stable: o Constify struct timeval * where possible; pointed out by Forest Wilkinson o allow min_heap_erase to be called on removed members; from liusifan. o Rename INPUT and OUTPUT to EVRPC_INPUT and EVRPC_OUTPUT. Retain INPUT/OUTPUT aliases on on-win32 platforms for backwards compatibility. + o Do not use SO_REUSEADDR when connecting Changes in 1.4.4-stable: diff --git a/http.c b/http.c index 2fa2af81..2a9d4393 100644 --- a/http.c +++ b/http.c @@ -152,8 +152,8 @@ fake_freeaddrinfo(struct addrinfo *ai) extern int debug; static int socket_connect(int fd, const char *address, unsigned short port); -static int bind_socket_ai(struct addrinfo *); -static int bind_socket(const char *, u_short); +static int bind_socket_ai(struct addrinfo *, int reuse); +static int bind_socket(const char *, u_short, int reuse); static void name_from_addr(struct sockaddr *, socklen_t, char **, char **); static int evhttp_associate_new_request_with_connection( struct evhttp_connection *evcon); @@ -1541,7 +1541,7 @@ 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); + evcon->fd = bind_socket(evcon->bind_address, 0 /*port*/, 0 /*reuse*/); if (evcon->fd == -1) { event_debug(("%s: failed to bind to \"%s\"", __func__, evcon->bind_address)); @@ -2012,7 +2012,7 @@ evhttp_bind_socket(struct evhttp *http, const char *address, u_short port) int fd; int res; - if ((fd = bind_socket(address, port)) == -1) + if ((fd = bind_socket(address, port, 1 /*reuse*/)) == -1) return (-1); if (listen(fd, 128) == -1) { @@ -2423,7 +2423,7 @@ name_from_addr(struct sockaddr *sa, socklen_t salen, /* Either connect or bind */ static int -bind_socket_ai(struct addrinfo *ai) +bind_socket_ai(struct addrinfo *ai, int reuse) { int fd, on = 1, r; int serrno; @@ -2446,7 +2446,10 @@ bind_socket_ai(struct addrinfo *ai) #endif setsockopt(fd, SOL_SOCKET, SO_KEEPALIVE, (void *)&on, sizeof(on)); - setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, (void *)&on, sizeof(on)); + if (reuse) { + setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, + (void *)&on, sizeof(on)); + } r = bind(fd, ai->ai_addr, ai->ai_addrlen); if (r == -1) @@ -2500,7 +2503,7 @@ make_addrinfo(const char *address, u_short port) } static int -bind_socket(const char *address, u_short port) +bind_socket(const char *address, u_short port, int reuse) { int fd; struct addrinfo *aitop = make_addrinfo(address, port); @@ -2508,7 +2511,7 @@ bind_socket(const char *address, u_short port) if (aitop == NULL) return (-1); - fd = bind_socket_ai(aitop); + fd = bind_socket_ai(aitop, reuse); #ifdef HAVE_GETADDRINFO freeaddrinfo(aitop);