Browse Source

tpws: prevent hang connection with SO_KEEPALIVE

pull/21/head
bolvan 7 years ago
parent
commit
e106a0c668
  1. BIN
      binaries/armhf/tpws
  2. BIN
      binaries/mips32r1-lsb/tpws
  3. BIN
      binaries/mips32r1-msb/tpws
  4. BIN
      binaries/x86_64/tpws
  5. 6
      tpws/tpws.c
  6. 8
      tpws/tpws_conn.c

BIN
binaries/armhf/tpws

Binary file not shown.

BIN
binaries/mips32r1-lsb/tpws

Binary file not shown.

BIN
binaries/mips32r1-msb/tpws

Binary file not shown.

BIN
binaries/x86_64/tpws

Binary file not shown.

6
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

8
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){

Loading…
Cancel
Save