From 93b766c2f743ce3bf560a2c1856668e46827df0b Mon Sep 17 00:00:00 2001 From: deveiant Date: Wed, 26 May 2004 18:24:29 +0000 Subject: [PATCH] - Added a command-line option for disabling TCP-level keepalives. Not suitable for production, but good for developing on non-Linux machines for now. git-svn-id: http://code.sixapart.com/svn/ddlockd/trunk@6 75bc8fc0-0210-0410-8e5e-a32055405bc5 --- ddlockd | 28 ++++++++++++++++------------ 1 file changed, 16 insertions(+), 12 deletions(-) diff --git a/ddlockd b/ddlockd index b40f594..36644f5 100755 --- a/ddlockd +++ b/ddlockd @@ -24,14 +24,16 @@ $DEBUG = 0; my ( $daemonize, + $nokeepalive, ); my $conf_port = 7002; Getopt::Long::GetOptions( - 'd|daemon' => \$daemonize, - 'p|port' => \$conf_port, - 'debug=i' => \$DEBUG, - ); + 'd|daemon' => \$daemonize, + 'p|port' => \$conf_port, + 'debug=i' => \$DEBUG, + 'n|no-keepalive' => \$nokeepalive, + ); daemonize() if $daemonize; @@ -60,12 +62,14 @@ my $accept_handler = sub { setsockopt($csock, IPPROTO_TCP, TCP_NODELAY, pack("l", 1)) or die; # Enable keep alive - (setsockopt($csock, SOL_SOCKET, SO_KEEPALIVE, pack("l", 1)) && - setsockopt($csock, IPPROTO_TCP, TCP_KEEPIDLE, pack("l", 30)) && - setsockopt($csock, IPPROTO_TCP, TCP_KEEPCNT, pack("l", 10)) && - setsockopt($csock, IPPROTO_TCP, TCP_KEEPINTVL, pack("l", 30)) && - 1 - ) || die "Couldn't set keep-alive settings on socket (Not on Linux?)"; + unless ( $nokeepalive ) { + (setsockopt($csock, SOL_SOCKET, SO_KEEPALIVE, pack("l", 1)) && + setsockopt($csock, IPPROTO_TCP, TCP_KEEPIDLE, pack("l", 30)) && + setsockopt($csock, IPPROTO_TCP, TCP_KEEPCNT, pack("l", 10)) && + setsockopt($csock, IPPROTO_TCP, TCP_KEEPINTVL, pack("l", 30)) && + 1 + ) || die "Couldn't set keep-alive settings on socket (Not on Linux?)"; + } my $client = Client->new($csock); $client->watch_read(1); @@ -175,7 +179,7 @@ sub close { sub _release_lock { my Client $self = shift; my $lock = shift; - + # TODO: notify waiters delete $self->{locks}{$lock}; delete $holder{$lock}; @@ -220,7 +224,7 @@ sub cmd_releaselock { sub cmd_locks { my Client $self = shift; my $args = shift; - + $self->write("LOCKS:\n"); foreach my $k (sort keys %holder) { $self->write(" $k = " . $holder{$k}->as_string . "\n");