[LON-CAPA-cvs] cvs: modules /gerd/maxima lonmaxima

albertel lon-capa-cvs@mail.lon-capa.org
Fri, 03 Mar 2006 23:31:09 -0000


albertel		Fri Mar  3 18:31:09 2006 EDT

  Modified files:              
    /modules/gerd/maxima	lonmaxima 
  Log:
  - some style police
  
  
Index: modules/gerd/maxima/lonmaxima
diff -u modules/gerd/maxima/lonmaxima:1.3 modules/gerd/maxima/lonmaxima:1.4
--- modules/gerd/maxima/lonmaxima:1.3	Fri Mar  3 18:25:47 2006
+++ modules/gerd/maxima/lonmaxima	Fri Mar  3 18:31:06 2006
@@ -3,7 +3,7 @@
 # The LearningOnline Network with CAPA
 # Connect to MAXIMA CAS
 #
-# $Id: lonmaxima,v 1.3 2006/03/03 23:25:47 albertel Exp $
+# $Id: lonmaxima,v 1.4 2006/03/03 23:31:06 albertel Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -55,7 +55,7 @@
 	    );
  
 sub maximareply {
-    my $cmd=shift;
+    my ($cmd) = @_;
     my $reply='';
     my $error='';
     my $exitstatus='';
@@ -115,7 +115,7 @@
 # --------------------------------------------------------------------- Logging
  
 sub logthis {
-    my $message=shift;
+    my ($message)=@_;
     my $execdir=$perlvar{'lonDaemons'};
     my $fh=IO::File->new(">>$execdir/logs/lonmaxima.log");
     my $now=time;
@@ -127,7 +127,7 @@
 # -------------------------------------------------------------- Status setting
  
 sub status {
-    my $what=shift;
+    my ($what)=@_;
     my $now=time;
     my $local=localtime($now);
     $status=$local.': '.$what;
@@ -137,7 +137,7 @@
 # -------------------------------------------------------- Escape Special Chars
  
 sub escape {
-    my $str=shift;
+    my ($str)=@_;
     $str =~ s/(\W)/"%".unpack('H2',$1)/eg;
     return $str;
 }
@@ -145,7 +145,7 @@
 # ----------------------------------------------------- Un-Escape Special Chars
  
 sub unescape {
-    my $str=shift;
+    my ($str)=@_;
     $str =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C",hex($1))/eg;
     return $str;
 }
@@ -240,7 +240,7 @@
      
 # Fork off our children.
 for (1 .. $PREFORK) {
-    make_new_child( );
+    &make_new_child();
 }
  
 # Install signal handlers.
@@ -253,20 +253,18 @@
     sleep;                          # wait for a signal (i.e., child's death)
     for (my $i = $children; $i < $PREFORK; $i++) {
         &status('Parent process, starting child');
-        make_new_child( );           # top up the child pool
+        &make_new_child();           # top up the child pool
     }
 }
                                                                                 
 sub make_new_child {
-    my $pid;
-    my $sigset;
-     
+
     # block signal for fork
-    $sigset = POSIX::SigSet->new(SIGINT);
+    my $sigset = POSIX::SigSet->new(SIGINT);
     sigprocmask(SIG_BLOCK, $sigset)
         or die "Can't block SIGINT for fork: $!\n";
      
-    die "fork: $!" unless defined ($pid = fork);
+    die "fork: $!" unless defined (my $pid = fork);
      
     if ($pid) {
         # Parent records the child's birth and returns.
@@ -282,17 +280,9 @@
         # unblock signals
         sigprocmask(SIG_UNBLOCK, $sigset)
             or die "Can't unblock SIGINT for fork: $!\n";
-         
-        # handle connections until we've reached $MAX_CLIENTS_PER_CHILD
-        for (my $i=0; $i < $MAX_CLIENTS_PER_CHILD; $i++) {
-	    &status('Accepting connections');     
-            $client = $server->accept( )     or last;
-            while ($cmd=<$client>) {
-		&status('Processing command');
-		print $client &escape((&maximareply(&unescape($cmd)))[0])."\n";
-	    }
-        }
-     
+
+	&process_requests();
+
         # tidy up gracefully and finish
 
         # this exit is VERY important, otherwise the child will become
@@ -301,3 +291,15 @@
         exit;
     }
 }
+
+sub process_requests {
+    # handle connections until we've reached $MAX_CLIENTS_PER_CHILD
+    for (my $i=0; $i < $MAX_CLIENTS_PER_CHILD; $i++) {
+	&status('Accepting connections');     
+	$client = $server->accept( )     or last;
+	while ($cmd=<$client>) {
+	    &status('Processing command');
+	    print $client &escape((&maximareply(&unescape($cmd)))[0])."\n";
+	}
+    }    
+}