[LON-CAPA-cvs] cvs: newloncapa /types LondConnection.pm

foxr lon-capa-cvs@mail.lon-capa.org
Sun, 13 Apr 2003 03:23:24 -0000


foxr		Sat Apr 12 23:23:24 2003 EDT

  Modified files:              
    /newloncapa/types	LondConnection.pm 
  Log:
  Added better logic to allow client to figure out the remote host
  disconnected.
  
  
Index: newloncapa/types/LondConnection.pm
diff -u newloncapa/types/LondConnection.pm:1.6 newloncapa/types/LondConnection.pm:1.7
--- newloncapa/types/LondConnection.pm:1.6	Fri Apr 11 22:47:00 2003
+++ newloncapa/types/LondConnection.pm	Sat Apr 12 23:23:24 2003
@@ -11,11 +11,10 @@
 use Fcntl;
 use POSIX;
 use Crypt::IDEA;
-#use LONCAPA::Configuration;
-use Configuration;
+use LONCAPA::Configuration;
 use HashIterator;
 
-my $DebugLevel=1;
+my $DebugLevel=4;
 
 #   Read the configuration file for apache to get the perl
 #   variable set.
@@ -103,7 +102,7 @@
 		     TransitionCallback => undef,
 	             Timeoutable        => 0,
 	             TimeoutValue       => 60,
-	             TimeoutRemaining   => 0,
+             TimeoutRemaining   => 0,
 		     CipherKey          => "",
 		     Cipher             => undef};
     bless($self, $class);
@@ -180,6 +179,12 @@
     if($self->{TransactionReply} =~ /(.*\n)/) {
 	&Debug(8,"Readable End of line detected");
 	if ($self->{State}  eq "Initialized") { # We received the challenge:
+	    if($self->{TransactionReply} eq "refused") {	# Remote doesn't have
+		
+		$self->Transition("Disconnected"); # in host tables.
+		$socket->close();
+		return -1;
+	    }
 
 	    &Debug(8," Transition out of Initialized");
 	    $self->{TransactionRequest} = $self->{TransactionReply};
@@ -190,6 +195,8 @@
 	    return 0;
 	} elsif ($self->{State} eq "ChallengeReplied") { # should be ok.
 	    if($self->{TransactionReply} != "ok\n") {
+		$self->Transition("Disconnected");
+		$socket->close();
 		return -1;
 	    }
 	    $self->Transition("RequestingKey");
@@ -208,6 +215,8 @@
 	    my $cipherkey=pack("H32",$key);
 	    $self->{Cipher} = new IDEA $cipherkey;
 	    if($self->{Cipher} == undef) {
+		$self->Transition("Disconnected");
+		$socket->close();
 		return -1;
 	    } else {
 		$self->Transition("Idle");
@@ -233,8 +242,11 @@
 	    $self->{Timeoutable}        = 0;
 	    $self->Transition("Idle");
 	    return 0;
-	}
-	else {			# Internal error: Invalid state.
+	} elsif ($self->{State} eq "Disconnected") { # No connection.
+	    return -1;
+	} else {			# Internal error: Invalid state.
+	    $self->Transition("Disconnected");
+	    $socket->close();
 	    return -1;
 	}
     }
@@ -260,6 +272,7 @@
     my $errno    = $! + 0;
     unless (defined $nwritten) {
 	if($errno != POSIX::EINTR) {
+	    $self->Transition("Disconnected");
 	    return -1;
 	}
       
@@ -289,10 +302,14 @@
 	    } elsif ($self->{State} eq "SendingRequest") {
 		$self->Transition("ReceivingReply");
 		$self->{TimeoutRemaining} = $self->{TimeoutValue};
+	    } elsif ($self->{State} eq "Disconnected") {
+		return -1;
 	    }
 	    return 0;
 	}
     } else {			# The write failed (e.g. partner disconnected).
+	$self->Transition("Disconnected");
+	$socket->close();
 	return -1;
     }
 	
@@ -544,6 +561,7 @@
 =item Idle:  Connection was negotiated but no requests are active.
 =item SendingRequest: A request is being sent to the peer.
 =item ReceivingReply: Waiting for an entire reply from the peer.
+=item Disconnected:   For whatever reason, the connection was dropped.
 
   When we need to be writing data, we have a writable
 event. When we need to be reading data, a readable event established.