--- loncom/LondConnection.pm 2003/04/18 06:07:27 1.3 +++ loncom/LondConnection.pm 2003/08/26 09:21:01 1.9 @@ -1,7 +1,7 @@ # This module defines and implements a class that represents # a connection to a lond daemon. # -# $Id: LondConnection.pm,v 1.3 2003/04/18 06:07:27 albertel Exp $ +# $Id: LondConnection.pm,v 1.9 2003/08/26 09:21:01 foxr Exp $ # # Copyright Michigan State University Board of Trustees # @@ -37,7 +37,7 @@ use Crypt::IDEA; use LONCAPA::Configuration; use LONCAPA::HashIterator; -my $DebugLevel=4; +my $DebugLevel=0; # Read the configuration file for apache to get the perl # variable set. @@ -145,15 +145,16 @@ sub new { TimeoutCallback => undef, TransitionCallback => undef, Timeoutable => 0, - TimeoutValue => 60, - TimeoutRemaining => 0, + TimeoutValue => 30, + TimeoutRemaining => 0, CipherKey => "", Cipher => undef}; bless($self, $class); unless ($self->{Socket} = IO::Socket::INET->new(PeerHost => $self->{Host}, PeerPort => $self->{Port}, Type => SOCK_STREAM, - Proto => "tcp")) { + Proto => "tcp", + Timeout => 5)) { return undef; # Inidicates the socket could not be made. } # @@ -161,6 +162,7 @@ sub new { # $self->Transition("Connected"); $self->{InformWritable} = 1; # When socket is writable we send init + $self->{Timeoutable} = 1; # Timeout allowed during startup negotiation. $self->{TransactionRequest} = "init\n"; # @@ -215,11 +217,10 @@ sub Readable { my $rv = $socket->recv($data, POSIX::BUFSIZ, 0); my $errno = $! + 0; # Force numeric context. - unless (defined($rv) && length($data)) { # Read failed, + unless (defined($rv) && length $data) {# Read failed, if(($errno == POSIX::EWOULDBLOCK) || ($errno == POSIX::EAGAIN) || - ($errno == POSIX::EINTR) || - ($errno == 0)) { + ($errno == POSIX::EINTR)) { return 0; } @@ -430,7 +431,9 @@ sub InitiateTransaction { my $self = shift; my $data = shift; + Debug(1, "initiating transaction: ".$data); if($self->{State} ne "Idle") { + Debug(0," .. but not idle here\n"); return -1; # Error indicator. } # if the transaction is to be encrypted encrypt the data: @@ -486,6 +489,20 @@ sub SetTimeoutCallback { =pod +=head2 Shutdown: + +Shuts down the socket. + +=cut + +sub Shutdown { + my $self = shift; + my $socket = $self->GetSocket(); + $socket->shutdown(2); +} + +=pod + =head2 GetState selector for the object state. @@ -510,6 +527,7 @@ sub GetSocket { return $self->{Socket}; } + =pod =head2 WantReadable @@ -836,6 +854,10 @@ peer (assumes the text is a command). Decrypts a block of text according to the cipher negotiated with the peer (assumes the block was a reply. +=item Shutdown: + +Shuts off the socket. + =head2 The following are selector member functions: =item GetState: