mirror of
https://github.com/bol-van/zapret.git
synced 2025-04-19 21:42:59 +03:00
tpws: prevent hang connection with SO_KEEPALIVE
This commit is contained in:
parent
ad071a122d
commit
e106a0c668
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -701,6 +701,12 @@ int main(int argc, char *argv[]) {
|
|||||||
close(listen_fd);
|
close(listen_fd);
|
||||||
exit(EXIT_FAILURE);
|
exit(EXIT_FAILURE);
|
||||||
}
|
}
|
||||||
|
if (setsockopt(listen_fd, SOL_SOCKET, SO_KEEPALIVE, &yes, sizeof(yes)) == -1)
|
||||||
|
{
|
||||||
|
perror("setsockopt (SO_KEEPALIVE): ");
|
||||||
|
close(listen_fd);
|
||||||
|
exit(EXIT_FAILURE);
|
||||||
|
}
|
||||||
|
|
||||||
//Mark that this socket can be used for transparent proxying
|
//Mark that this socket can be used for transparent proxying
|
||||||
//This allows the socket to accept connections for non-local IPs
|
//This allows the socket to accept connections for non-local IPs
|
||||||
|
@ -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) :
|
||||||
|
Loading…
x
Reference in New Issue
Block a user