add more debuging,
[spider.git] / perl / AGWMsg.pm
index 6afcbcba18416aac52cee63e5d10b605edd4c09b..41f23702abd7ab5b79ea6fcd1fa82012867c89ca 100644 (file)
@@ -51,7 +51,7 @@ sub init
        
        finish();
        dbg('err', "AGW initialising and connecting to $addr/$port ...");
-       $sock = IO::Socket::INET->new(PeerAddr => $addr, PeerPort => $port, Proto=>'tcp', Timeout => 30);
+       $sock = IO::Socket::INET->new(PeerAddr => $addr, PeerPort => $port, Proto=>'tcp', Timeout=>15);
        unless ($sock) {
                dbg('err', "Cannot connect to AGW Engine at $addr/$port $!");
                return;
@@ -157,6 +157,9 @@ sub _send
                     return 0; # fail. Message remains in queue ..
                 }
             }
+                       if (isdbg('raw')) {
+                               dbgdump('raw', "send $bytes_written: ", $msg);
+                       }
             $offset         += $bytes_written;
             $bytes_to_write -= $bytes_written;
         }
@@ -183,6 +186,9 @@ sub _rcv {                     # Complement to _send
        if (defined ($bytes_read)) {
                if ($bytes_read > 0) {
                        $inmsg .= $msg;
+                       if (isdbg('raw')) {
+                               dbgdump('raw', "read $bytes_read: ", $msg);
+                       }
                } 
        } else {
                if (Msg::_err_will_block($!)) {
@@ -196,7 +202,7 @@ FINISH:
     if (defined $bytes_read && $bytes_read == 0) {
                finish();
     } else {
-               _decode() if length $inmsg > 36;
+               _decode() if length $inmsg >= 36;
        }
 }
 
@@ -206,7 +212,7 @@ sub _error
        Msg::set_event_handler($sock, read=>undef, write=>undef, error=>undef);
        $sock = undef;
        for (%circuit) {
-               next unless $_->isa('AGWMsg');
+               &{$_->{eproc}}() if $_->{eproc};
                $_->disconnect;
        }
 }
@@ -358,7 +364,8 @@ sub _decode
                        dbg('agw', "AGW Port: $_");
                }
                for (my $i = 0; $i < $noports; $i++) {
-                       _sendf('y', undef, undef, $i );
+                       _sendf('y', undef, undef, $i);
+                       _sendf('g', undef, undef, $i);
                }
        } else {
                my $d = unpack "Z*", $data;