--- loncom/Attic/lonManage 2003/11/04 11:23:37 1.23 +++ loncom/Attic/lonManage 2003/11/04 11:36:04 1.24 @@ -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 $ServerPort; # Port used to connect my $TransitionTimeout = 5; # Poll timeout in seconds. -LondConnection::SetDebug(10); +# LondConnection::SetDebug(10); # @@ -195,11 +195,61 @@ sub NegotiateStartup { 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.