Diff for /loncom/lonmaxima between versions 1.14 and 1.15

version 1.14, 2006/03/08 14:22:14 version 1.15, 2006/03/08 15:58:03
Line 37  use IO::Socket; Line 37  use IO::Socket;
 use IO::File;  use IO::File;
 use Symbol;  use Symbol;
 use POSIX;  use POSIX;
 use Fcntl;  
 use Socket;  
 use lib '/home/httpd/lib/perl/';  use lib '/home/httpd/lib/perl/';
 use LONCAPA::Configuration;  use LONCAPA::Configuration;
     
Line 131  sub catchexception { Line 129  sub catchexception {
     die("Signal abend");      die("Signal abend");
 }  }
   
 # -------------------------------------------------- make a socket non-blocking  
 sub nonblock {  
     my $socket = shift;  
     my $flags;  
     if (ref($socket)) {   
        $flags = fcntl($socket, F_GETFL, 0)  
             or die "Can't get flags for socket: $!\n";  
        fcntl($socket, F_SETFL, $flags | O_NONBLOCK)  
             or die "Can't make socket nonblocking: $!\n";  
     }  
 }  
   
 # ---------------------------------------------------------------- Main program  # ---------------------------------------------------------------- Main program
 # -------------------------------- Set signal handlers to record abnormal exits  # -------------------------------- Set signal handlers to record abnormal exits
     
Line 277  sub make_new_child { Line 263  sub make_new_child {
                                               Reuse     => 1,                                                Reuse     => 1,
                                               Listen    => 10 )                                                Listen    => 10 )
                         or die "making socket: $@\n";                          or die "making socket: $@\n";
         &nonblock($maximaserver);  
         my $maximaselect=IO::Select->new($maximaserver);          my $maximaselect=IO::Select->new($maximaserver);
         sleep(2);          sleep(1);
   
         # open MAXIMA to talk to that port          # open MAXIMA to talk to that port
         my ($cmd_in, $cmd_out, $cmd_err);          my ($cmd_in, $cmd_out, $cmd_err);
Line 291  sub make_new_child { Line 276  sub make_new_child {
         # hopefully, MAXIMA calls us back          # hopefully, MAXIMA calls us back
         &status("Waiting $maximapid on $maximaport");          &status("Waiting $maximapid on $maximaport");
         my $maximaclient=$maximaserver->accept();          my $maximaclient=$maximaserver->accept();
           $maximaclient->blocking(0);
         $maximaselect->add($maximaclient);          $maximaselect->add($maximaclient);
         &nonblock($maximaclient);  
         &status("$maximapid on $maximaport connected.");          &status("$maximapid on $maximaport connected.");
         &logthis("Maxima $maximapid on port $maximaport connected.");          &logthis("Maxima $maximapid on port $maximaport connected.");
           sleep(2);
   
         &logthis('Initial reply: '.&maximareply($maximaselect));          &logthis('Initial reply: '.&maximareply($maximaselect));
         # handle connections until we've reached $MAX_CLIENTS_PER_CHILD          # handle connections until we've reached $MAX_CLIENTS_PER_CHILD
         for (my $i=0; $i < $MAX_CLIENTS_PER_CHILD; $i++) {          for (my $i=0; $i < $MAX_CLIENTS_PER_CHILD; $i++) {
Line 302  sub make_new_child { Line 289  sub make_new_child {
             my $client = $server->accept()     or last;              my $client = $server->accept()     or last;
             while (my $cmd=<$client>) {              while (my $cmd=<$client>) {
                 &status('Processing command by '.$maximapid.' on '.$maximaport);                  &status('Processing command by '.$maximapid.' on '.$maximaport);
                 print $maximaclient &unescape($cmd).";\n";                  &maximawrite($maximaselect,&unescape($cmd).";\n");
                 print $client &escape(&maximareply($maximaselect))."\n";                  print $client &escape(&maximareply($maximaselect))."\n";
             }              }
         }          }
Line 323  sub make_new_child { Line 310  sub make_new_child {
 sub maximareply {  sub maximareply {
    my ($maximaselect)=@_;     my ($maximaselect)=@_;
    my $output='';     my $output='';
      
    foreach my $ready ($maximaselect->can_read(1)) {     foreach my $ready ($maximaselect->can_read(1)) {
        my $data = '';         my $data = '';
        my $rv   = $ready->recv($data, POSIX::BUFSIZ, 0);         my $rv   = $ready->recv($data, POSIX::BUFSIZ, 0);
Line 331  sub maximareply { Line 319  sub maximareply {
    return $output;     return $output;
 }  }
   
   sub maximawrite {
      my ($maximaselect,$cmd)=@_;
      my $ready=($maximaselect->can_write(1));
      if (ref($ready)) {
         print $ready $cmd;
      } else {
         &logthis("Cannot write: ".&maximareply($maximaselect));
      }
   }
   
   

Removed from v.1.14  
changed lines
  Added in v.1.15


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