from trunk: do not use SO_REUSEADDR when connecting

svn:r855
This commit is contained in:
Niels Provos 2008-06-20 06:55:26 +00:00
parent 921693c44e
commit fb0b274e97
2 changed files with 12 additions and 8 deletions

View File

@ -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:

19
http.c
View File

@ -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);