--- loncom/LondConnection.pm 2003/10/28 11:15:10 1.15 +++ loncom/LondConnection.pm 2004/01/06 09:35:22 1.23 @@ -1,7 +1,7 @@ # This module defines and implements a class that represents # a connection to a lond daemon. # -# $Id: LondConnection.pm,v 1.15 2003/10/28 11:15:10 foxr Exp $ +# $Id: LondConnection.pm,v 1.23 2004/01/06 09:35:22 foxr Exp $ # # Copyright Michigan State University Board of Trustees # @@ -46,6 +46,13 @@ my %hostshash; my %perlvar; # +# Set debugging level +# +sub SetDebug { + $DebugLevel = shift; +} + +# # The config read is done in this way to support the read of # the non-default configuration file in the # event we are being used outside of loncapa. @@ -60,9 +67,10 @@ sub ReadConfig { my $perlvarref = read_conf('loncapa.conf'); %perlvar = %{$perlvarref}; my $hoststab = read_hosts( - "$perlvar{'lonTabDir'}/hosts.tab") || + "$perlvar{lonTabDir}/hosts.tab") || die "Can't read host table!!"; %hostshash = %{$hoststab}; + $ConfigRead = 1; } @@ -84,11 +92,18 @@ sub ReadForeignConfig { my $MyHost = shift; my $Filename = shift; + &Debug(4, "ReadForeignConfig $MyHost $Filename\n"); + $perlvar{lonHostID} = $MyHost; # Rmember my host. my $hosttab = read_hosts($Filename) || die "Can't read hosts table!!"; - %hostshash = %{$hosttab} - + %hostshash = %{$hosttab}; + if($DebugLevel > 3) { + foreach my $host (keys %hostshash) { + print "host $host => $hostshash{$host}\n"; + } + } + $ConfigRead = 1; } @@ -112,11 +127,11 @@ sub Dump { my $self = shift; my $key; my $value; - print "Dumping LondConnectionObject:\n"; + print STDERR "Dumping LondConnectionObject:\n"; while(($key, $value) = each %$self) { print STDERR "$key -> $value\n"; } - print "-------------------------------\n"; + print STDERR "-------------------------------\n"; } =pod @@ -176,6 +191,7 @@ sub new { # LoncapaHim fields of the object respectively. # if (!exists $hostshash{$Hostname}) { + &Debug(8, "No Such host $Hostname"); return undef; # No such host!!! } my @ConfigLine = @{$hostshash{$Hostname}}; @@ -546,7 +562,15 @@ Shuts down the socket. sub Shutdown { my $self = shift; my $socket = $self->GetSocket(); - $socket->shutdown(2); + Debug(5,"socket is -$socket-"); + if ($socket) { + # Ask lond to exit too. Non blocking so + # there is no cost for failure. + eval { + $socket->send("exit\n", 0); + $socket->shutdown(2); + } + } } =pod @@ -768,6 +792,9 @@ sub read_conf my %perlvar; foreach my $filename (@conf_files,'loncapa_apache.conf') { + if($DebugLevel > 3) { + print("Going to read $confdir.$filename\n"); + } open(CONFIG,'<'.$confdir.$filename) or die("Can't read $confdir$filename"); while (my $configline=) @@ -781,9 +808,15 @@ sub read_conf } close(CONFIG); } + if($DebugLevel > 3) { + print "Dumping perlvar:\n"; + foreach my $var (keys %perlvar) { + print "$var = $perlvar{$var}\n"; + } + } my $perlvarref=\%perlvar; - return ($perlvarref); - } + return $perlvarref; +} #---------------------- Subroutine read_hosts: Read a LON-CAPA hosts.tab # formatted configuration file. @@ -797,7 +830,7 @@ sub read_hosts { my $Filename = shift; my %HostsTab; - open(CONFIG,'<'.$Filename) or die("Can't read $Filename"); + open(CONFIG,'<'.$Filename) or die("Can't read $Filename"); while (my $line = ) { if (!($line =~ /^\s*\#/)) { my @items = split(/:/, $line);