--- loncom/loncnew 2004/06/01 10:02:13 1.47 +++ loncom/loncnew 2004/08/26 12:35:10 1.51 @@ -2,7 +2,7 @@ # The LearningOnline Network with CAPA # lonc maintains the connections to remote computers # -# $Id: loncnew,v 1.47 2004/06/01 10:02:13 foxr Exp $ +# $Id: loncnew,v 1.51 2004/08/26 12:35:10 albertel Exp $ # # Copyright Michigan State University Board of Trustees # @@ -82,7 +82,7 @@ my $ClientConnection = 0; # Uniquifier f my $DebugLevel = 0; my $NextDebugLevel= 2; # So Sigint can toggle this. -my $IdleTimeout= 3600; # Wait an hour before pruning connections. +my $IdleTimeout= 600; # Wait 10 minutes before pruning connections. my $LogTransactions = 0; # When True, all transactions/replies get logged. @@ -103,7 +103,12 @@ my $RecentLogEntry = ""; my $ConnectionRetries=2; # Number of connection retries allowed. my $ConnectionRetriesLeft=2; # Number of connection retries remaining. my $LondVersion = "unknown"; # Version of lond we talk with. +my $KeyMode = ""; # e.g. ssl, local, insecure from last connect. +my $LongTickLength = 10000000; #Tick Frequency when Idle +my $ShortTickLength = 1; #Tick Frequency when Active (many places in + # the code assume this is one) +my $TickLength = $ShortTickLength;#number of seconds to wait until ticking # # The hash below gives the HTML format for log messages # given a severity. @@ -232,7 +237,7 @@ sub SocketDump { my ($level, $socket) = @_; if($level <= $DebugLevel) { - $socket->Dump(); + $socket->Dump(-1); # Ensure it will get dumped. } } @@ -265,7 +270,7 @@ sub SocketTimeout { my $Socket = shift; Log("WARNING", "A socket timeout was detected"); Debug(0, " SocketTimeout called: "); - $Socket->Dump(); + $Socket->Dump(0); if(exists($ActiveTransactions{$Socket})) { FailTransaction($ActiveTransactions{$Socket}); } @@ -292,7 +297,8 @@ sub Tick { my $client; if($ConnectionRetriesLeft > 0) { ShowStatus(GetServerHost()." Connection count: ".$ConnectionCount - ." Retries remaining: ".$ConnectionRetriesLeft); + ." Retries remaining: ".$ConnectionRetriesLeft + ." ($KeyMode)"); } else { ShowStatus(GetServerHost()." >> DEAD <<"); } @@ -301,10 +307,13 @@ sub Tick { if($IdleConnections->Count() && ($WorkQueue->Count() == 0)) { # Idle connections and nothing to do? - $IdleSeconds++; + $IdleSeconds+=$TickLength; if($IdleSeconds > $IdleTimeout) { # Prune a connection... my $Socket = $IdleConnections->pop(); KillSocket($Socket); + if ($IdleConnections->Count() == 0) { + &SetupTimer($LongTickLength); + } } } else { $IdleSeconds = 0; # Reset idle count if not idle. @@ -347,6 +356,9 @@ sub Tick { } } + if ($ConnectionCount == 0) { + $KeyMode = ""; + } } =pod @@ -365,9 +377,13 @@ Trigger disconnections of idle sockets. =cut +my $timer; sub SetupTimer { - Debug(6, "SetupTimer"); - Event->timer(interval => 1, cb => \&Tick ); + my ($newLength)=@_; + Debug(6, "SetupTimer $TickLength->$newLength"); + $TickLength=$newLength; + if ($timer) { $timer->cancel; } + $timer=Event->timer(interval => $TickLength, cb => \&Tick ); } =pod @@ -387,6 +403,7 @@ long enough, it will be shut down and re sub ServerToIdle { my $Socket = shift; # Get the socket. + $KeyMode = $Socket->{AuthenticationMode}; delete($ActiveTransactions{$Socket}); # Server has no transaction &Debug(5, "Server to idle"); @@ -1226,6 +1243,7 @@ sub QueueTransaction { EmptyQueue(); # Fail transactions, can't make connection. CloseAllLondConnections; # Should all be closed but... } + &SetupTimer($ShortTickLength); } else { ShowStatus(GetServerHost()." >>> DEAD !!!! <<<"); EmptyQueue(); # It's worse than that ... he's dead Jim. @@ -1441,7 +1459,7 @@ sub ChildStatus { my $state = $Socket->GetState(); print $fh "Connection $i State: $state\n"; print STDERR "---------------------- Connection $i \n"; - $Socket->Dump(); + $Socket->Dump(-1); # Ensure it gets dumped.. $i++; } } @@ -1515,7 +1533,7 @@ sub ChildProcess { cb => \&ToggleDebug, data => "INT"); - SetupTimer(); + SetupTimer($LongTickLength); SetupLoncListener();