[LON-CAPA-cvs] cvs: loncom / loncnew /lonnet/perl lonnet.pm

albertel lon-capa-cvs@mail.lon-capa.org
Wed, 28 Mar 2007 21:44:14 -0000


albertel		Wed Mar 28 17:44:14 2007 EDT

  Modified files:              
    /loncom	loncnew 
    /loncom/lonnet/perl	lonnet.pm 
  Log:
  - eliminate need for lonnet, by having lonnet send all known lonids over the launch channel
  - need to quotemeta on the re now since lonids can have . and -
  
  
Index: loncom/loncnew
diff -u loncom/loncnew:1.81 loncom/loncnew:1.82
--- loncom/loncnew:1.81	Wed Mar 28 16:28:29 2007
+++ loncom/loncnew	Wed Mar 28 17:44:05 2007
@@ -2,7 +2,7 @@
 # The LearningOnline Network with CAPA
 # lonc maintains the connections to remote computers
 #
-# $Id: loncnew,v 1.81 2007/03/28 20:28:29 albertel Exp $
+# $Id: loncnew,v 1.82 2007/03/28 21:44:05 albertel Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -94,6 +94,7 @@
 #
 my $RemoteHost;			# Name of host child is talking to.
 my $RemoteHostId;		# default lonid of host child is talking to.
+my @all_host_ids;
 my $UnixSocketDir= $perlvar{'lonSockDir'};
 my $IdleConnections = Stack->new(); # Set of idle connections
 my %ActiveConnections;		# Connections to the remote lond.
@@ -1161,10 +1162,7 @@
     Debug(4, "Delayed path: ".$path);
     opendir(DIRHANDLE, $path);
 
-    use Apache::lonnet;
-    my @all_host_ids = &Apache::lonnet::machine_ids($RemoteHost);
-
-    my $host_id_re = '(?:'.join('|',@all_host_ids).')';
+    my $host_id_re = '(?:'.join('|',map {quotemeta($_)} (@all_host_ids)).')';
     my @alldelayed = grep(/\.$host_id_re$/, readdir(DIRHANDLE));
     closedir(DIRHANDLE);
     foreach my $dfname (sort(@alldelayed)) {
@@ -1208,6 +1206,7 @@
 	return 0;		# Failure.
     }  else {
 
+	$LondConnecting = 1;	# Connection in progress.
 	# The connection needs to have writability 
 	# monitored in order to send the init sequence
 	# that starts the whole authentication/key
@@ -1238,7 +1237,6 @@
 	}
 	Log("SUCESS", "Created connection ".$ConnectionCount
 	    ." to host ".GetServerHost());
-	$LondConnecting = 1;	# Connection in progress.
 	return 1;		# Return success.
     }
     
@@ -1766,7 +1764,7 @@
 	$RemoteHost = "Parent";
 	$ChildHash{$pid} = $host;
 	sigprocmask(SIG_UNBLOCK, $sigset);
-
+	undef(@all_host_ids);
     } else {			# child.
 	$RemoteHostId = $hostid;
 	ShowStatus("Connected to ".$RemoteHost);
@@ -1809,37 +1807,37 @@
 }
 
 sub get_remote_hostname {
-	my ($event)   = @_;
-	my $watcher   = $event->w;
-	my $socket    = $watcher->fd;
-	
-	my $thisread;
-	my $rv = $socket->recv($thisread, POSIX::BUFSIZ, 0);
-	Debug(8, "rcv:  data length = ".length($thisread)." read =".$thisread);
-	if (!defined($rv) || length($thisread) == 0) {
-	    # Likely eof on socket.
-	    Debug(5,"Client Socket closed on lonc for p_c_c");
-	    close($socket);
-	    $watcher->cancel();
-	    return;
-	}
+    my ($event)   = @_;
+    my $watcher   = $event->w;
+    my $socket    = $watcher->fd;
 
-	my $data    = $watcher->data().$thisread;
-	$watcher->data($data);
-	if($data =~ /\n$/) {	# Request entirely read.
-	    chomp($data);
-	} else {
-	    return;
-	}
-	
-	&Debug(5,"Creating child for $data (parent_client_connection)");
-	my ($hostname,$lonid) = split(':',$data,2);
-	&CreateChild($hostname,$lonid);
-	
-	# Clean up the listen since now the child takes over until it exits.
-	$watcher->cancel();		# Nolonger listening to this event
-	$socket->send("done\n");
-	$socket->close();
+    my $thisread;
+    my $rv = $socket->recv($thisread, POSIX::BUFSIZ, 0);
+    Debug(8, "rcv:  data length = ".length($thisread)." read =".$thisread);
+    if (!defined($rv) || length($thisread) == 0) {
+	# Likely eof on socket.
+	Debug(5,"Client Socket closed on lonc for p_c_c");
+	close($socket);
+	$watcher->cancel();
+	return;
+    }
+
+    my $data    = $watcher->data().$thisread;
+    $watcher->data($data);
+    if($data =~ /\n$/) {	# Request entirely read.
+	chomp($data);
+    } else {
+	return;
+    }
+
+    &Debug(5,"Creating child for $data (parent_client_connection)");
+    (my $hostname,my $lonid,@all_host_ids) = split(':',$data);
+    &CreateChild($hostname,$lonid);
+
+    # Clean up the listen since now the child takes over until it exits.
+    $watcher->cancel();		# Nolonger listening to this event
+    $socket->send("done\n");
+    $socket->close();
 }
 
 # parent_listen:
Index: loncom/lonnet/perl/lonnet.pm
diff -u loncom/lonnet/perl/lonnet.pm:1.853 loncom/lonnet/perl/lonnet.pm:1.854
--- loncom/lonnet/perl/lonnet.pm:1.853	Wed Mar 28 16:28:31 2007
+++ loncom/lonnet/perl/lonnet.pm	Wed Mar 28 17:44:13 2007
@@ -1,7 +1,7 @@
 # The LearningOnline Network
 # TCP networking package
 #
-# $Id: lonnet.pm,v 1.853 2007/03/28 20:28:31 albertel Exp $
+# $Id: lonnet.pm,v 1.854 2007/03/28 21:44:13 albertel Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -53,6 +53,7 @@
 use Math::Random;
 use LONCAPA qw(:DEFAULT :match);
 use LONCAPA::Configuration;
+use Apache::lonhosts;
 
 my $readit;
 my $max_connection_retries = 10;     # Or some such value.
@@ -150,7 +151,7 @@
 				     Type    => SOCK_STREAM,
 				     Timeout => 10);
     return 0 if (!$client);
-    print $client ("$hostname:$lonid\n");
+    print $client (join(':',$hostname,$lonid,&machine_ids($lonid))."\n");
     my $result = <$client>;
     chomp($result);
     return 1 if ($result eq 'done');