|
@ -74,6 +74,7 @@ int check_local_ip(const struct sockaddr *saddr) |
|
|
static int connect_remote(struct sockaddr_storage *remote_addr){ |
|
|
static int connect_remote(struct sockaddr_storage *remote_addr){ |
|
|
int remote_fd = 0, yes = 1; |
|
|
int remote_fd = 0, yes = 1; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//Use NONBLOCK to avoid slow connects affecting the performance of other
|
|
|
//Use NONBLOCK to avoid slow connects affecting the performance of other
|
|
|
//connections
|
|
|
//connections
|
|
|
if((remote_fd = socket(remote_addr->ss_family, SOCK_STREAM | |
|
|
if((remote_fd = socket(remote_addr->ss_family, SOCK_STREAM | |
|
@ -87,6 +88,11 @@ static int connect_remote(struct sockaddr_storage *remote_addr){ |
|
|
close(remote_fd); |
|
|
close(remote_fd); |
|
|
return 0; |
|
|
return 0; |
|
|
} |
|
|
} |
|
|
|
|
|
if(setsockopt(remote_fd, SOL_SOCKET, SO_KEEPALIVE, &yes, sizeof(yes)) < 0){ |
|
|
|
|
|
perror("setsockopt (SO_KEEPALIVE, connect_remote): "); |
|
|
|
|
|
close(remote_fd); |
|
|
|
|
|
return 0; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
if(connect(remote_fd, (struct sockaddr*) remote_addr, |
|
|
if(connect(remote_fd, (struct sockaddr*) remote_addr, |
|
|
remote_addr->ss_family == AF_INET ? sizeof(struct sockaddr_in) : |
|
|
remote_addr->ss_family == AF_INET ? sizeof(struct sockaddr_in) : |
|
|