From b5b494bfe442d798ed1d9a05fc2c4f9e31f4aa11 Mon Sep 17 00:00:00 2001 From: minima Date: Thu, 10 Jan 2002 23:46:17 +0000 Subject: [PATCH] add KEEPALIVE to TCP connections --- Changes | 5 ++++- perl/Msg.pm | 3 ++- src/client.c | 4 ++++ 3 files changed, 10 insertions(+), 2 deletions(-) diff --git a/Changes b/Changes index ed992bdc..82d90bb4 100644 --- a/Changes +++ b/Changes @@ -1,7 +1,10 @@ 10Jan02======================================================================= 1. set SO_LINGER = 0 to try to prevent the system sending data on a closing -socket. This MAY help some of the hanging problems. +socket. This MAY help some of the hanging problems (but I am now beginning +to doubt this). 2. do the same on the C client (which means DON'T FORGET to make it). +3. set KEEPALIVE on TCP connections for both the node and C Client (you will +have to make the C client again) and you will need to restart. 08Jan02======================================================================= 1. altered sh/qrz to point to the new server 2. alter the character set handling a bit to make it better for spanish diff --git a/perl/Msg.pm b/perl/Msg.pm index 746878e2..f2881c8f 100644 --- a/perl/Msg.pm +++ b/perl/Msg.pm @@ -364,7 +364,8 @@ sub nolinger my ($l, $t) = unpack("ll", $buf); dbg("Linger is: $buf = $l $t"); } - setsockopt($conn->{sock}, SOL_SOCKET, SO_LINGER, pack("ll", 0, 0)) or confess "setsockopt: $!"; + setsockopt($conn->{sock}, SOL_SOCKET, SO_LINGER, pack("ll", 0, 0)) or confess "setsockopt linger: $!"; + setsockopt($conn->{sock}, SOL_SOCKET, SO_KEEPALIVE, 1) or confess "setsockopt keepalive: $!"; if (isdbg('sock') && ($buf = getsockopt($conn->{sock}, SOL_SOCKET, SO_LINGER))) { my ($l, $t) = unpack("ll", $buf); dbg("Linger is: $buf = $l $t"); diff --git a/src/client.c b/src/client.c index 049d64f6..69a8aaeb 100644 --- a/src/client.c +++ b/src/client.c @@ -825,6 +825,7 @@ void connect_to_node() struct hostent *hp, *gethostbyname(); struct sockaddr_in server; int nodef; + int one = 1; sel_t *sp; struct linger lg; @@ -848,6 +849,9 @@ void connect_to_node() if (setsockopt(nodef, SOL_SOCKET, SO_LINGER, &lg, sizeof lg) < 0) { die("Error on SO_LINGER to %s port %d (%d)", node_addr, node_port, errno); } + if (setsockopt(nodef, SOL_SOCKET, SO_KEEPALIVE, &one, sizeof one) < 0) { + die("Error on SO_KEEPALIVE to %s port %d (%d)", node_addr, node_port, errno); + } node = fcb_new(nodef, MSG); node->sp = sel_open(nodef, node, "Msg System", fcb_handler, MSG, SEL_INPUT); -- 2.34.1