[LON-CAPA-cvs] cvs: loncom / LondConnection.pm

foxr foxr@source.lon-capa.org
Tue, 21 Dec 2010 11:17:33 -0000


foxr		Tue Dec 21 11:17:33 2010 EDT

  Modified files:              
    /loncom	LondConnection.pm 
  Log:
  - A bit of formatting.
  - A bit more care when the timeout counter is reset.
  
  
Index: loncom/LondConnection.pm
diff -u loncom/LondConnection.pm:1.49 loncom/LondConnection.pm:1.50
--- loncom/LondConnection.pm:1.49	Thu Nov 11 15:01:13 2010
+++ loncom/LondConnection.pm	Tue Dec 21 11:17:33 2010
@@ -1,7 +1,7 @@
 #   This module defines and implements a class that represents
 #   a connection to a lond daemon.
 #
-# $Id: LondConnection.pm,v 1.49 2010/11/11 15:01:13 raeburn Exp $
+# $Id: LondConnection.pm,v 1.50 2010/12/21 11:17:33 foxr Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -342,6 +342,8 @@
     }
     #  Append the data to the buffer.  And figure out if the read is done:
 
+    $self->{TimeoutRemaining}   = $self->{TimeoutValue}; # getting data resets the timeout period.
+
     &Debug(9,"Received from host: ".$data);
     $self->{TransactionReply} .= $data;
     if($self->{TransactionReply} =~ m/\n$/) {
@@ -501,7 +503,6 @@
 		$self->{InformWritable}     = 1;
 		$self->{InformReadable}     = 0;
 		$self->{Timeoutable}        = 1;
-		$self->{TimeoutRemaining}   = $self->{TimeoutValue};
 		$self->Transition("SendingRequest");
 		return 0;
 	    } else {
@@ -563,42 +564,42 @@
 	($errno == POSIX::EAGAIN)         ||
 	($errno == POSIX::EINTR)          ||
 	($errno ==  0)) {
-    $self->{TimeoutRemaining} = $self->{TimeoutValue};
+	$self->{TimeoutRemaining} = $self->{TimeoutValue};
 	substr($self->{TransactionRequest}, 0, $nwritten) = ""; # rmv written part
-      if(length $self->{TransactionRequest} == 0) {
-         $self->{InformWritable} = 0;
-         $self->{InformReadable} = 1;
-         $self->{TransactionReply} = '';
-         #
-         # Figure out the next state:
-         #
-         if($self->{State} eq "Connected") {
-            $self->Transition("Initialized");
-         } elsif($self->{State} eq "ChallengeReceived") {
-            $self->Transition("ChallengeReplied");
-         } elsif($self->{State} eq "RequestingVersion") {
-            $self->Transition("ReadingVersionString");
-         } elsif ($self->{State} eq "SetHost") {
-            $self->Transition("HostSet");
-         } elsif($self->{State} eq "RequestingKey") {
-            $self->Transition("ReceivingKey");
+	if(length $self->{TransactionRequest} == 0) {
+	    $self->{InformWritable} = 0;
+	    $self->{InformReadable} = 1;
+	    $self->{TransactionReply} = '';
+	    #
+	    # Figure out the next state:
+	    #
+	    if($self->{State} eq "Connected") {
+		$self->Transition("Initialized");
+	    } elsif($self->{State} eq "ChallengeReceived") {
+		$self->Transition("ChallengeReplied");
+	    } elsif($self->{State} eq "RequestingVersion") {
+		$self->Transition("ReadingVersionString");
+	    } elsif ($self->{State} eq "SetHost") {
+		$self->Transition("HostSet");
+	    } elsif($self->{State} eq "RequestingKey") {
+		$self->Transition("ReceivingKey");
 #            $self->{InformWritable} = 0;
 #            $self->{InformReadable} = 1;
 #            $self->{TransactionReply} = '';
-         } 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;
-   }
-	
+	    } 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;
+    }
+    
 }
 =pod
 
@@ -745,6 +746,7 @@
 	    $socket->shutdown(2);
 	}
     }
+    $self->{Timeoutable}   = 0;	# Shutdown sockets can't timeout.
 }
 
 =pod