X-Git-Url: http://dxcluster.org/gitweb/gitweb.cgi?a=blobdiff_plain;f=perl%2FDXMsg.pm;h=5c990177330ddc26c55fd20ccd7a0fcf242e49b1;hb=4e5b3de7a26563d94678fb790b8a1e2c4daaac8d;hp=9e4893b23485c386f00f3cda79931247b0a5d2f0;hpb=de987b900c04d852acec5e1af9a4326b16533253;p=spider.git diff --git a/perl/DXMsg.pm b/perl/DXMsg.pm index 9e4893b2..5c990177 100644 --- a/perl/DXMsg.pm +++ b/perl/DXMsg.pm @@ -28,7 +28,6 @@ use DXDebug; use DXLog; use IO::File; use Fcntl; -use Carp; use strict; use vars qw(%work @msg $msgdir %valid %busy $maxage $last_clean @@ -137,7 +136,7 @@ sub process # this is periodic processing if (!$self || !$line) { - if ($main::systime > $lastq + $queueinterval) { + if ($main::systime >= $lastq + $queueinterval) { # wander down the work queue stopping any messages that have timed out for (keys %busy) { @@ -194,6 +193,7 @@ sub process $ref->{stream} = $stream; $ref->{count} = 0; # no of lines between PC31s dbg('msg', "new message from $f[4] to $f[3] '$f[8]' stream $stream\n"); + Log('msg', "Incoming message $f[4] to $f[3] '$f[8]'" ); $work{"$f[2]$stream"} = $ref; # store in work $busy{$f[2]} = $ref; # set interlock $self->send(DXProt::pc30($f[2], $f[1], $stream)); # send ack @@ -282,8 +282,8 @@ sub process if ($ref->{subject} eq $m->{subject} && $ref->{t} == $m->{t} && $ref->{from} eq $m->{from} && $ref->{to} eq $m->{to}) { $ref->stop_msg($self->call); my $msgno = $m->{msgno}; - dbg('msg', "duplicate message to $msgno\n"); - Log('msg', "duplicate message to $msgno"); + dbg('msg', "duplicate message from $ref->{from} -> $ref->{to} to $msgno"); + Log('msg', "duplicate message from $ref->{from} -> $ref->{to} to $msgno"); return; } } @@ -504,9 +504,10 @@ sub read_msg_header my @f; my $size; - $file = new IO::File; - if (!open($file, $fn)) { - print "Error reading $fn $!\n"; + $file = new IO::File "$fn"; + if (!$file) { + dbg('err', "Error reading $fn $!"); + Log('err', "Error reading $fn $!"); return undef; } $size = -s $fn; @@ -514,7 +515,8 @@ sub read_msg_header chomp $line; $size -= length $line; if (! $line =~ /^===/o) { - print "corrupt first line in $fn ($line)\n"; + dbg('err', "corrupt first line in $fn ($line)"); + Log('err', "corrupt first line in $fn ($line)"); return undef; } $line =~ s/^=== //o; @@ -525,7 +527,8 @@ sub read_msg_header chomp $line; $size -= length $line; if (! $line =~ /^===/o) { - print "corrupt second line in $fn ($line)\n"; + dbg('err', "corrupt second line in $fn ($line)"); + Log('err', "corrupt second line in $fn ($line)"); return undef; } $line =~ s/^=== //o; @@ -551,7 +554,8 @@ sub read_msg_body $file = new IO::File; if (!open($file, $fn)) { - print "Error reading $fn $!\n"; + dbg('err' ,"Error reading $fn $!"); + Log('err' ,"Error reading $fn $!"); return undef; } @out = map {chomp; $_} <$file>; @@ -612,7 +616,7 @@ sub queue_msg next if $ref->{'read'}; # if it is read, it is stuck here $clref = DXCluster->get_exact($ref->{to}); unless ($clref) { # otherwise look for a homenode - my $uref = DXUser->get($ref->{to}); + my $uref = DXUser->get_current($ref->{to}); my $hnode = $uref->homenode if $uref; $clref = DXCluster->get_exact($hnode) if $hnode; } @@ -740,9 +744,9 @@ sub init my $ref; # load various control files - print "load badmsg: ", (load_badmsg() or "Ok"), "\n"; - print "load forward: ", (load_forward() or "Ok"), "\n"; - print "load swop: ", (load_swop() or "Ok"), "\n"; + dbg('err', "load badmsg: " . (load_badmsg() or "Ok")); + dbg('err', "load forward: " . (load_forward() or "Ok")); + dbg('err', "load swop: " . (load_swop() or "Ok")); # read in the directory opendir($dir, $msgdir) or confess "can't open $msgdir $!"; @@ -1231,6 +1235,9 @@ sub AUTOLOAD $name =~ s/.*:://o; confess "Non-existant field '$AUTOLOAD'" if !$valid{$name}; + # this clever line of code creates a subroutine which takes over from autoload + # from OO Perl - Conway + *{$AUTOLOAD} = sub {@_ > 1 ? $_[0]->{$name} = $_[1] : $_[0]->{$name}} ; @_ ? $self->{$name} = shift : $self->{$name} ; }