mirror of
https://github.com/libevent/libevent.git
synced 2025-01-31 09:12:55 +08:00
from trunk: do not use SO_REUSEADDR when connecting
svn:r855
This commit is contained in:
parent
921693c44e
commit
fb0b274e97
@ -4,6 +4,7 @@ Changes in 1.4.5-stable:
|
|||||||
o Constify struct timeval * where possible; pointed out by Forest Wilkinson
|
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 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 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:
|
Changes in 1.4.4-stable:
|
||||||
|
19
http.c
19
http.c
@ -152,8 +152,8 @@ fake_freeaddrinfo(struct addrinfo *ai)
|
|||||||
extern int debug;
|
extern int debug;
|
||||||
|
|
||||||
static int socket_connect(int fd, const char *address, unsigned short port);
|
static int socket_connect(int fd, const char *address, unsigned short port);
|
||||||
static int bind_socket_ai(struct addrinfo *);
|
static int bind_socket_ai(struct addrinfo *, int reuse);
|
||||||
static int bind_socket(const char *, u_short);
|
static int bind_socket(const char *, u_short, int reuse);
|
||||||
static void name_from_addr(struct sockaddr *, socklen_t, char **, char **);
|
static void name_from_addr(struct sockaddr *, socklen_t, char **, char **);
|
||||||
static int evhttp_associate_new_request_with_connection(
|
static int evhttp_associate_new_request_with_connection(
|
||||||
struct evhttp_connection *evcon);
|
struct evhttp_connection *evcon);
|
||||||
@ -1541,7 +1541,7 @@ evhttp_connection_connect(struct evhttp_connection *evcon)
|
|||||||
assert(!(evcon->flags & EVHTTP_CON_INCOMING));
|
assert(!(evcon->flags & EVHTTP_CON_INCOMING));
|
||||||
evcon->flags |= EVHTTP_CON_OUTGOING;
|
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) {
|
if (evcon->fd == -1) {
|
||||||
event_debug(("%s: failed to bind to \"%s\"",
|
event_debug(("%s: failed to bind to \"%s\"",
|
||||||
__func__, evcon->bind_address));
|
__func__, evcon->bind_address));
|
||||||
@ -2012,7 +2012,7 @@ evhttp_bind_socket(struct evhttp *http, const char *address, u_short port)
|
|||||||
int fd;
|
int fd;
|
||||||
int res;
|
int res;
|
||||||
|
|
||||||
if ((fd = bind_socket(address, port)) == -1)
|
if ((fd = bind_socket(address, port, 1 /*reuse*/)) == -1)
|
||||||
return (-1);
|
return (-1);
|
||||||
|
|
||||||
if (listen(fd, 128) == -1) {
|
if (listen(fd, 128) == -1) {
|
||||||
@ -2423,7 +2423,7 @@ name_from_addr(struct sockaddr *sa, socklen_t salen,
|
|||||||
/* Either connect or bind */
|
/* Either connect or bind */
|
||||||
|
|
||||||
static int
|
static int
|
||||||
bind_socket_ai(struct addrinfo *ai)
|
bind_socket_ai(struct addrinfo *ai, int reuse)
|
||||||
{
|
{
|
||||||
int fd, on = 1, r;
|
int fd, on = 1, r;
|
||||||
int serrno;
|
int serrno;
|
||||||
@ -2446,7 +2446,10 @@ bind_socket_ai(struct addrinfo *ai)
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
setsockopt(fd, SOL_SOCKET, SO_KEEPALIVE, (void *)&on, sizeof(on));
|
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);
|
r = bind(fd, ai->ai_addr, ai->ai_addrlen);
|
||||||
if (r == -1)
|
if (r == -1)
|
||||||
@ -2500,7 +2503,7 @@ make_addrinfo(const char *address, u_short port)
|
|||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
bind_socket(const char *address, u_short port)
|
bind_socket(const char *address, u_short port, int reuse)
|
||||||
{
|
{
|
||||||
int fd;
|
int fd;
|
||||||
struct addrinfo *aitop = make_addrinfo(address, port);
|
struct addrinfo *aitop = make_addrinfo(address, port);
|
||||||
@ -2508,7 +2511,7 @@ bind_socket(const char *address, u_short port)
|
|||||||
if (aitop == NULL)
|
if (aitop == NULL)
|
||||||
return (-1);
|
return (-1);
|
||||||
|
|
||||||
fd = bind_socket_ai(aitop);
|
fd = bind_socket_ai(aitop, reuse);
|
||||||
|
|
||||||
#ifdef HAVE_GETADDRINFO
|
#ifdef HAVE_GETADDRINFO
|
||||||
freeaddrinfo(aitop);
|
freeaddrinfo(aitop);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user