--- loncom/loncnew	2008/10/06 10:55:46	1.88
+++ loncom/loncnew	2011/01/24 11:02:32	1.95
@@ -2,7 +2,7 @@
 # The LearningOnline Network with CAPA
 # lonc maintains the connections to remote computers
 #
-# $Id: loncnew,v 1.88 2008/10/06 10:55:46 foxr Exp $
+# $Id: loncnew,v 1.95 2011/01/24 11:02:32 foxr Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -85,7 +85,7 @@ my $ClientConnection = 0;	# Uniquifier f
 
 my $DebugLevel = 0;
 my $NextDebugLevel= 2;		# So Sigint can toggle this.
-my $IdleTimeout= 600;		# Wait 10 minutes before pruning connections.
+my $IdleTimeout= 5*60;		# Seconds to wait prior to pruning connections.
 
 my $LogTransactions = 0;	# When True, all transactions/replies get logged.
 my $executable      = $0;	# Get the full path to me.
@@ -441,7 +441,8 @@ Trigger disconnections of idle sockets.
 
 sub SetupTimer {
     Debug(6, "SetupTimer");
-    Event->timer(interval => 1, cb => \&Tick );
+    Event->timer(interval => 1, cb => \&Tick,
+	hard => 1);
 }
 
 =pod
@@ -761,6 +762,7 @@ sub KillSocket {
 	delete ($ActiveTransactions{$Socket});
     }
     if(exists($ActiveConnections{$Socket})) {
+	$ActiveConnections{$Socket}->cancel;
 	delete($ActiveConnections{$Socket});
 	$ConnectionCount--;
 	if ($ConnectionCount < 0) { $ConnectionCount = 0; }
@@ -772,6 +774,7 @@ sub KillSocket {
 	EmptyQueue();
 	CloseAllLondConnections; # Should all already be closed but...
     }
+    UpdateStatus();
 }
 
 =pod
@@ -943,7 +946,8 @@ sub LondReadable {
 	    CompleteTransaction($Socket, 
 				$ActiveTransactions{$Socket});
 	} else {
-	    Log("SUCCESS", "Connection ".$ConnectionCount." to "
+	    my $count = $Socket->GetClientData();
+	    Log("SUCCESS", "Connection ".$count." to "
 		.$RemoteHost." now ready for action");
 	}
 	ServerToIdle($Socket);	# Next work unit or idle.
@@ -1206,7 +1210,7 @@ sub MakeLondConnection {
 					 &GetServerPort(),
 					 &GetHostId());
 
-    if($Connection eq undef) {	# Needs to be more robust later.
+    if($Connection eq undef) {	
 	Log("CRITICAL","Failed to make a connection with lond.");
 	$ConnectionRetriesLeft--;
 	return 0;		# Failure.
@@ -1237,6 +1241,7 @@ sub MakeLondConnection {
 	    &SetupTimer;	# Need to handle timeouts with connections...
 	}
 	$ConnectionCount++;
+	$Connection->SetClientData($ConnectionCount);
 	Debug(4, "Connection count = ".$ConnectionCount);
 	if($ConnectionCount == 1) { # First Connection:
 	    QueueDelayed;
@@ -1348,8 +1353,7 @@ sub QueueTransaction {
     }
 }
 
-#-------------------------- Lonc UNIX socket handling ---------------------
-
+#-------------------------- Lonc UNIX socket handling -------------------
 =pod
 
 =head2 ClientRequest
@@ -1730,6 +1734,13 @@ sub ChildProcess {
 		  cb       => \&ToggleDebug,
 		  data     => "INT");
 
+    # Block the pipe signal we'll get when the socket disconnects.  We detect 
+    # socket disconnection via send/receive failures. On disconnect, the
+    # socket becomes readable .. which will force the disconnect detection.
+
+    my $set = POSIX::SigSet->new(SIGPIPE);
+    sigprocmask(SIG_BLOCK, $set);
+
     #  Figure out if we got passed a socket or need to open one to listen for
     #  client requests.
 
@@ -1773,6 +1784,7 @@ sub CreateChild {
     my $sigset = POSIX::SigSet->new(SIGINT);
     sigprocmask(SIG_BLOCK, $sigset);
     $RemoteHost = $host;
+    ShowStatus('Parent keeping the flock'); # Update time in status message.
     Log("CRITICAL", "Forking server for ".$host);
     my $pid          = fork;
     if($pid) {			# Parent