self-service keepalives
authorivan <ivan>
Mon, 6 Sep 2004 12:44:17 +0000 (12:44 +0000)
committerivan <ivan>
Mon, 6 Sep 2004 12:44:17 +0000 (12:44 +0000)
FS/bin/freeside-selfservice-server
fs_selfservice/FS-SelfService/freeside-selfservice-clientd

index d34e841..a83664d 100644 (file)
@@ -8,7 +8,8 @@
 # Proc::Daemon or somesuch
 
 use strict;
 # Proc::Daemon or somesuch
 
 use strict;
-use vars qw( $Debug %kids $kids $max_kids $shutdown $log_file $ssh_pid );
+use vars qw( $Debug %kids $kids $max_kids $shutdown $log_file $ssh_pid
+             $keepalives );
 use subs qw( lock_write unlock_write );
 use Fcntl qw(:flock);
 use POSIX qw(:sys_wait_h setsid);
 use subs qw( lock_write unlock_write );
 use Fcntl qw(:flock);
 use POSIX qw(:sys_wait_h setsid);
@@ -29,6 +30,7 @@ $Debug = 1; # >= 2 will log packet contents, including potentially compromising
 
 $shutdown = 0;
 $max_kids = '10'; #?
 
 $shutdown = 0;
 $max_kids = '10'; #?
+$keepalives = 0; #let clientd turn it on, so we don't barf on old ones
 $kids = 0;
 
 my $user = shift or die &usage;
 $kids = 0;
 
 my $user = shift or die &usage;
@@ -58,6 +60,7 @@ while (1) {
 
   warn "entering main loop\n" if $Debug;
   my $undisp = 0;
 
   warn "entering main loop\n" if $Debug;
   my $undisp = 0;
+  my $keepalive_count = 0;
   my $s = IO::Select->new( $reader );
   while (1) {
 
   my $s = IO::Select->new( $reader );
   while (1) {
 
@@ -68,6 +71,10 @@ while (1) {
     my @handles = $s->can_read(5);
     unless ( @handles ) {
       &shutdown if $shutdown;
     my @handles = $s->can_read(5);
     unless ( @handles ) {
       &shutdown if $shutdown;
+      if ( $keepalives && $keepalive_count++ > 10 ) {
+        $keepalive_count = 0;
+        nstore_fd( { _token => '_keepalive' }, $writer );
+      }
       next;
     }
 
       next;
     }
 
@@ -91,6 +98,12 @@ while (1) {
          join('', map { " $_=>$packet->{$_}\n" } keys %$packet )
       if $Debug > 1;
 
          join('', map { " $_=>$packet->{$_}\n" } keys %$packet )
       if $Debug > 1;
 
+    if ( $packet->{_packet} eq '_enable_keepalive' ) {
+      warn "enabling keep alives\n" if $Debug;
+      $keepalives=1;
+      next;
+    }
+
     #prevent runaway forking
     my $warnkids = 0;
     while ( $kids >= $max_kids ) {
     #prevent runaway forking
     my $warnkids = 0;
     while ( $kids >= $max_kids ) {
index ce9e14d..95e9b9b 100644 (file)
@@ -20,7 +20,8 @@ my $tag = scalar(@ARGV) ? '.'.shift : '';
 
 use vars qw( $Debug );
 $Debug = 2; #2 will turn on child logging, 3 will log packet contents,
 
 use vars qw( $Debug );
 $Debug = 2; #2 will turn on child logging, 3 will log packet contents,
-            #including potentially compromising information
+            #including potentially compromising information, 4 will log
+            #receipts of all packets from server including keepalives (big!)
 
 my $socket = "/usr/local/freeside/selfservice_socket$tag";
 my $pid_file = "$socket.pid";
 
 my $socket = "/usr/local/freeside/selfservice_socket$tag";
 my $pid_file = "$socket.pid";
@@ -65,6 +66,9 @@ close PIDFILE;
 #sub REAPER { $waitedpid = wait; $SIG{CHLD} = \&REAPER; }
 #$SIG{CHLD} =  \&REAPER;
 
 #sub REAPER { $waitedpid = wait; $SIG{CHLD} = \&REAPER; }
 #$SIG{CHLD} =  \&REAPER;
 
+warn "enabling keep alives\n" if $Debug;
+nstore_fd( { _packet => '_enable_keepalive' } , \*STDOUT );
+
 warn "entering main loop\n" if $Debug;
 
 my %kids;
 warn "entering main loop\n" if $Debug;
 
 my %kids;
@@ -101,10 +105,16 @@ while (1) {
 
     if ( $handle == \*STDIN ) {
 
 
     if ( $handle == \*STDIN ) {
 
-      warn "receiving packet from server\n" if $Debug;
+      warn "receiving packet from server\n" if $Debug > 3;
 
       my $packet = fd_retrieve(\*STDIN);
       my $token = $packet->{'_token'};
 
       my $packet = fd_retrieve(\*STDIN);
       my $token = $packet->{'_token'};
+
+      if ( $token eq '_keepalive' ) {
+        $undisp = 1;
+        next;
+      }
+
       warn "received packet from server with token $token\n".
            ( $Debug > 2
              ? join('', map { " $_=>$packet->{$_}\n" } keys %$packet )
       warn "received packet from server with token $token\n".
            ( $Debug > 2
              ? join('', map { " $_=>$packet->{$_}\n" } keys %$packet )