[LON-CAPA-cvs] cvs: loncom / lonManage

foxr lon-capa-cvs@mail.lon-capa.org
Tue, 04 Nov 2003 11:36:04 -0000


foxr		Tue Nov  4 06:36:04 2003 EDT

  Modified files:              
    /loncom	lonManage 
  Log:
  Complete the process of peeling it away from lonc... debugged the transaction
  logic
  
  
Index: loncom/lonManage
diff -u loncom/lonManage:1.23 loncom/lonManage:1.24
--- loncom/lonManage:1.23	Tue Nov  4 06:23:37 2003
+++ loncom/lonManage	Tue Nov  4 06:36:04 2003
@@ -3,9 +3,9 @@
 #
 #  lonManage supports remote management of nodes in a LonCAPA cluster.
 #
-#  $Id: lonManage,v 1.23 2003/11/04 11:23:37 foxr Exp $
+#  $Id: lonManage,v 1.24 2003/11/04 11:36:04 foxr Exp $
 #
-# $Id: lonManage,v 1.23 2003/11/04 11:23:37 foxr Exp $
+# $Id: lonManage,v 1.24 2003/11/04 11:36:04 foxr Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -80,7 +80,7 @@
 my $TransitionTimeout = 5;	# Poll timeout in seconds.
 
 
-LondConnection::SetDebug(10);
+# LondConnection::SetDebug(10);
 
 
 #
@@ -195,11 +195,61 @@
     
     return $returnstatus;
 }
+#
+#   Perform a transaction with the remote lond.
+#   Paramters:
+#      connection - the connection object that represents
+#                   a LondConnection to the remote lond.
+#      command    - The request to send to the remote system.
+#   Returns:
+#       The 'reaction' of the lond to this command.
+#       However if the connection to lond is lost during the transaction
+#       or some other error occurs, the text "error:con_lost" is returned.
+#    
 sub PerformTransaction {
     my $connection  = shift;
     my $command     = shift;
+    my $retval;                          # What we'll returnl.
+   
+    #  Set up the connection to do the transaction then
+    #  do the I/O until idle or error.
+    #
+    $connection->InitiateTransaction($command);
+    my $error      = 0;
+    my $Socket    = $connection->GetSocket;
+    my $state;
+
+    while (($connection->GetState ne "Idle") && (!$error)) {
+	#
+	#   Wait for the socket to get into the appropriate state:
+	#
+	my $wantread = $connection->WantReadable; 
+	my $poll     = new IO::Poll;
+	$poll->mask($Socket => $wantread ? POLLIN : POLLOUT);
+	$poll->poll($TransitionTimeout);
+	my $done     = $poll->handles();
+	if(scalar($done) == 0) {                       # Timeout!!!
+	    print "Error: Timeout in state : $state negotiating connection\n";
+	    $retval = "error";
+	    $error = 1;
+	} else {
+	    my $status;
+	    $status = $wantread ? $connection->Readable : $connection->Writable;
+	    if ($status != 0) {
+		print "Error: I/O failed in state : $state negotiating connection\n";
+		$retval = "error";
+		$error = 1;
+	    }
+	}
+    }
+    #
+    #  Fetch the reply from the transaction
+    #
+    if(! $error) {
+	$retval = $connection->GetReply;
+    }
 
-    return "ok";
+    return $retval;
 }
 #
 # Performs a transaction direct to a remote lond.