Diff for /loncom/loncnew between versions 1.3 and 1.4

version 1.3, 2003/04/18 03:10:36 version 1.4, 2003/04/24 10:56:55
Line 100  my %ActiveClients;  # Serial numbers of Line 100  my %ActiveClients;  # Serial numbers of
 my $WorkQueue       = Queue->new(); # Queue of pending transactions.  my $WorkQueue       = Queue->new(); # Queue of pending transactions.
 my $ClientQueue     = Queue->new(); # Queue of clients causing xactinos.  my $ClientQueue     = Queue->new(); # Queue of clients causing xactinos.
 my $ConnectionCount = 0;  my $ConnectionCount = 0;
   my $IdleSeconds     = 0; # Number of seconds idle.
   
 #  #
   
Line 163  Invoked  each timer tick. Line 163  Invoked  each timer tick.
   
 sub Tick {  sub Tick {
     my $client;      my $client;
       $0 = 'lonc: '.GetServerHost()." Connection count: ".$ConnectionCount;
     Debug(6, "Tick");      Debug(6, "Tick");
     Debug(6, "    Current connection count: ".$ConnectionCount);      Debug(6, "    Current connection count: ".$ConnectionCount);
     foreach $client (keys %ActiveClients) {      foreach $client (keys %ActiveClients) {
  Debug(7, "    Have client:  with id: ".$ActiveClients{$client});   Debug(7, "    Have client:  with id: ".$ActiveClients{$client});
     }      }
       # Is it time to prune connection count:
   
   
       if($IdleConnections->Count()  && 
          ($WorkQueue->Count() == 0)) { # Idle connections and nothing to do?
    $IdleSeconds++;
    if($IdleSeconds > $IdleTimeout) { # Prune a connection...
       $Socket = $IdleConnections->pop();
       KillSocket($Socket, 0);
    }
       } else {
    $IdleSeconds = 0; # Reset idle count if not idle.
       }
 }  }
   
 =pod  =pod
Line 348  sub CompleteTransaction { Line 362  sub CompleteTransaction {
       cb       => \&ClientWritable,        cb       => \&ClientWritable,
       data     => $data);        data     => $data);
 }  }
   =pod
   =head2 FailTransaction
   
     Finishes a transaction with failure because the associated lond socket
     disconnected.  It is up to our client to retry if desired.  
   
   Parameters:
   
   =item client  
    
      The UNIX domain socket open on our client.
   
   =cut
   
   sub FailTransaction {
       my $client = shift;
   
       &Debug(8, "Failing transaction due to disconnect");
       my $Serial = $ActiveClients{$client};
       my $desc   = sprintf("Connection to lonc client %d", $Serial);
       my $data   = "error: Connection to lond lost\n";
   
       Event->io(fd     => $client,
         poll   => "w",
         desc   => $desc,
         cb     => \&ClientWritable,
         data   => $data);
   
   }
   
   =pod
   
   =head2 KillSocket
    
   Destroys a socket.  This function can be called either when a socket
   has died of 'natural' causes or because a socket needs to be pruned due to
   idleness.  If the socket has died naturally, if there are no longer any 
   live connections a new connection is created (in case there are transactions
   in the queue).  If the socket has been pruned, it is never re-created.
   
   Parameters:
   
   =item Socket
    
     The socket to kill off.
   
   =item Restart
   
   nonzero if we are allowed to create a new connection.
   
   
   =cut
   sub KillSocket {
       my $Socket = shift;
       my $Restart= shift;
   
       #  If the socket came from the active connection set, delete it.
       # otherwise it came from the idle set and has already been destroyed:
       
       if(exists($ActiveTransactions{$Socket})) {
    delete ($ActiveTransactions{$Socket});
       }
       if(exists($ActiveConnections{$Socket})) {
    delete($ActiveConnections{$Socket});
       }
       $ConnectionCount--;
       if( ($ConnectionCount = 0) && ($Restart)) {
    MakeLondConnection();
       }
   
   }
   
 =pod  =pod
   
Line 421  sub LondReadable { Line 505  sub LondReadable {
     SocketDump(6, $Socket);      SocketDump(6, $Socket);
   
     if($Socket->Readable() != 0) {      if($Socket->Readable() != 0) {
  # bad return from socket read.   # bad return from socket read. Currently this means that
    # The socket has become disconnected. We fail the transaction.
   
    if(exists($ActiveTransactions{$Socket})) {
       Debug(3,"Lond connection lost failing transaction");
       FailTransaction($ActiveTransactions{$Socket});
    }
    $Watcher->cancel();
    KillSocket($Socket, 1);
    return;
     }      }
     SocketDump(6,$Socket);      SocketDump(6,$Socket);
   
Line 557  sub LondWritable { Line 650  sub LondWritable {
     SocketDump(6,$Socket);      SocketDump(6,$Socket);
   
     if      ($State eq "Connected")         {      if      ($State eq "Connected")         {
  #  "init" is being sent...  
   
  if ($Socket->Writable() != 0) {   if ($Socket->Writable() != 0) {
     #  The write resulted in an error.      #  The write resulted in an error.
       # We'll treat this as if the socket got disconnected:
       if(exists($ActiveTransactions{$Socket})) {
    Debug(3, "Lond connection lost, failing transactions");
    FailTransaction($ActiveTransactions{$Socket});
       }
       $Watcher->cancel();
       KillSocket($Socket, 1);
       return;
  }   }
    #  "init" is being sent...
   
   
     } elsif ($State eq "Initialized")       {      } elsif ($State eq "Initialized")       {
   
Line 672  sub MakeLondConnection { Line 774  sub MakeLondConnection {
        cb       => \&LondWritable,         cb       => \&LondWritable,
        data     => ($Connection, undef),         data     => ($Connection, undef),
        desc => 'Connection to lond server');         desc => 'Connection to lond server');
     $ActiveConnections{$Lond} = $event;      $ActiveConnections{$Connection} = $event;
   
     $ConnectionCount++;      $ConnectionCount++;
         

Removed from v.1.3  
changed lines
  Added in v.1.4


FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>