[LON-CAPA-cvs] cvs: loncom / lonc lond

foxr lon-capa-cvs@mail.lon-capa.org
Wed, 27 Mar 2002 04:07:02 -0000


foxr		Tue Mar 26 23:07:02 2002 EDT

  Modified files:              
    /loncom	lonc lond 
  Log:
  Add DoSelect sub to encapsulate select in the presence of signals.
  
  
  
  
Index: loncom/lonc
diff -u loncom/lonc:1.35 loncom/lonc:1.36
--- loncom/lonc:1.35	Mon Mar 25 23:37:59 2002
+++ loncom/lonc	Tue Mar 26 23:07:02 2002
@@ -5,7 +5,7 @@
 # provides persistent TCP connections to the other servers in the network
 # through multiplexed domain sockets
 #
-# $Id: lonc,v 1.35 2002/03/26 04:37:59 foxr Exp $
+# $Id: lonc,v 1.36 2002/03/27 04:07:02 foxr Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -589,6 +589,36 @@
 
     foreach $client (keys %ready) {
 	handle($client);
+    }
+}
+
+# DoSelect:  does a select with no timeout.  On signal (errno == EINTR), 
+#            the select is retried until there are items in the returned
+#            vectors.  
+#
+# Parameters:
+#   \$readvec   - Reference to a vector of file descriptors to 
+#                 check for readability.
+#   \$writevec  - Reference to a vector of file descriptors to check for
+#                 writability.
+#  On exit, the referents are modified with vectors indicating which 
+#  file handles are readable/writable.
+#
+sub DoSelect {
+    my $readvec = shift;
+    my $writevec= shift;
+    my $outs;
+    my $ins;
+
+    while (1) {
+	my $nfds = select($outs = $$writevec, $ins = $$readvec, undef, undef);
+	if($nfound) {
+	    $$readvec  = $ins;
+	    $$writevec = $outs;
+	    return;
+	} else {
+	    die "Select failed" unless $! == EINTR;
+	}
     }
 }
 
Index: loncom/lond
diff -u loncom/lond:1.74 loncom/lond:1.75
--- loncom/lond:1.74	Sun Mar  3 14:49:00 2002
+++ loncom/lond	Tue Mar 26 23:07:02 2002
@@ -2,7 +2,7 @@
 # The LearningOnline Network
 # lond "LON Daemon" Server (port "LOND" 5663)
 #
-# $Id: lond,v 1.74 2002/03/03 19:49:00 harris41 Exp $
+# $Id: lond,v 1.75 2002/03/27 04:07:02 foxr Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -160,7 +160,7 @@
 
 # global variables
 
-$MAX_CLIENTS_PER_CHILD  = 5;        # number of clients each child should 
+$MAX_CLIENTS_PER_CHILD  = 50;        # number of clients each child should 
                                     # process
 %children               = ();       # keys are current child process IDs
 $children               = 0;        # current number of children
@@ -301,10 +301,10 @@
         if (kill 0 => $loncpid) {
 	    &logthis("lonc at pid $loncpid responding, sending USR1");
             kill USR1 => $loncpid;
-            sleep 1;
+            sleep 5;
             if (-e "$peerfile") { return; }
             &logthis("$peerfile still not there, give it another try");
-            sleep 5;
+            sleep 10;
             if (-e "$peerfile") { return; }
             &logthis(
  "<font color=blue>WARNING: $peerfile still not there, giving up</font>");
@@ -342,6 +342,7 @@
     if ($answer eq 'con_lost') {
 	$answer=subreply("ping",$server);
         if ($answer ne $server) {
+	    &logthis("sub reply: answer != server");
            &reconlonc("$perlvar{'lonSockDir'}/$server");
         }
         $answer=subreply($cmd,$server);
@@ -531,7 +532,8 @@
             }
             if ($clientok) {
 # ---------------- New known client connecting, could mean machine online again
-	      &reconlonc("$perlvar{'lonSockDir'}/$hostid{$clientip}");
+
+	      # &reconlonc("$perlvar{'lonSockDir'}/$hostid{$clientip}");
               &logthis(
        "<font color=green>Established connection: $hostid{$clientip}</font>");
               &status('Will listen to '.$hostid{$clientip});
@@ -554,8 +556,9 @@
 		    }
 		    $userinput=substr($userinput,0,$cmdlength);
                     $wasenc=1;
-		  }
 		}
+	      }
+	  
 # ------------------------------------------------------------- Normal commands
 # ------------------------------------------------------------------------ ping
 		   if ($userinput =~ /^ping/) {
@@ -1421,12 +1424,13 @@
                 $client->close();
                 &logthis("<font color=blue>WARNING: "
                 ."Rejected client $clientip, closing connection</font>");
-            }              
-            &logthis("<font color=red>CRITICAL: "
-                    ."Disconnect from $clientip ($hostid{$clientip})</font>");
+            }
+	}              
+
 # =============================================================================
-        }
-    
+       
+	&logthis("<font color=red>CRITICAL: "
+		 ."Disconnect from $clientip ($hostid{$clientip})</font>");    
         # tidy up gracefully and finish
     
         $server->close();