Skip to content

Commit

Permalink
- Added a command-line option for disabling TCP-level keepalives. Not…
Browse files Browse the repository at this point in the history
… 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
  • Loading branch information
deveiant committed May 26, 2004
1 parent 610d230 commit 93b766c
Showing 1 changed file with 16 additions and 12 deletions.
28 changes: 16 additions & 12 deletions ddlockd
Expand Up @@ -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;

Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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};
Expand Down Expand Up @@ -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");
Expand Down

0 comments on commit 93b766c

Please sign in to comment.