diff --git a/binaries/armhf/tpws b/binaries/armhf/tpws index fd888a0..fff92ca 100755 Binary files a/binaries/armhf/tpws and b/binaries/armhf/tpws differ diff --git a/binaries/mips32r1-lsb/tpws b/binaries/mips32r1-lsb/tpws index ac6eb0d..7f7cb54 100755 Binary files a/binaries/mips32r1-lsb/tpws and b/binaries/mips32r1-lsb/tpws differ diff --git a/binaries/mips32r1-msb/tpws b/binaries/mips32r1-msb/tpws index 1b1d4ee..f575f27 100755 Binary files a/binaries/mips32r1-msb/tpws and b/binaries/mips32r1-msb/tpws differ diff --git a/binaries/x86_64/tpws b/binaries/x86_64/tpws index b115de7..7f7cb54 100755 Binary files a/binaries/x86_64/tpws and b/binaries/x86_64/tpws differ diff --git a/tpws/tpws.c b/tpws/tpws.c index 88776eb..c0ece75 100644 --- a/tpws/tpws.c +++ b/tpws/tpws.c @@ -701,6 +701,12 @@ int main(int argc, char *argv[]) { close(listen_fd); 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 //This allows the socket to accept connections for non-local IPs diff --git a/tpws/tpws_conn.c b/tpws/tpws_conn.c index 8419e32..b8f3b0d 100644 --- a/tpws/tpws_conn.c +++ b/tpws/tpws_conn.c @@ -73,6 +73,7 @@ int check_local_ip(const struct sockaddr *saddr) //Returns 0 if something fails, >0 on success (socket fd). static int connect_remote(struct sockaddr_storage *remote_addr){ int remote_fd = 0, yes = 1; + //Use NONBLOCK to avoid slow connects affecting the performance of other //connections @@ -87,7 +88,12 @@ static int connect_remote(struct sockaddr_storage *remote_addr){ close(remote_fd); 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, remote_addr->ss_family == AF_INET ? sizeof(struct sockaddr_in) : sizeof(struct sockaddr_in6)) < 0){