1. Added an efficiency thing for AUTOLOADed accessors from OO Perl by Conway.
[spider.git] / perl / DXMsg.pm
index 0bfdfefbbe3cfaba1a8ae2594ce5bd0d141635ff..5c990177330ddc26c55fd20ccd7a0fcf242e49b1 100644 (file)
@@ -136,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) {
@@ -193,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
@@ -281,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;
                                                        }
                                                }
@@ -506,6 +507,7 @@ sub read_msg_header
        $file = new IO::File "$fn";
        if (!$file) {
            dbg('err', "Error reading $fn $!");
+           Log('err', "Error reading $fn $!");
                return undef;
        }
        $size = -s $fn;
@@ -514,6 +516,7 @@ sub read_msg_header
        $size -= length $line;
        if (! $line =~ /^===/o) {
                dbg('err', "corrupt first line in $fn ($line)");
+               Log('err', "corrupt first line in $fn ($line)");
                return undef;
        }
        $line =~ s/^=== //o;
@@ -525,6 +528,7 @@ sub read_msg_header
        $size -= length $line;
        if (! $line =~ /^===/o) {
            dbg('err', "corrupt second line in $fn ($line)");
+           Log('err', "corrupt second line in $fn ($line)");
                return undef;
        }
        $line =~ s/^=== //o;
@@ -551,6 +555,7 @@ sub read_msg_body
        $file = new IO::File;
        if (!open($file, $fn)) {
                dbg('err' ,"Error reading $fn $!");
+               Log('err' ,"Error reading $fn $!");
                return undef;
        }
        @out = map {chomp; $_} <$file>;
@@ -611,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;
                        }
@@ -1230,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} ;
 }