X-Git-Url: http://www.dxcluster.org/gitweb/gitweb.cgi?a=blobdiff_plain;f=perl%2FAGWMsg.pm;h=910d32cc4c94c50c1f75b023f1666014fcfcb352;hb=refs%2Fheads%2Fstaging;hp=6a36453517f048f4b187f04a6dd774bb4152d402;hpb=7a74bbb4aa72509078b38eff21f06857648cfd42;p=spider.git diff --git a/perl/AGWMsg.pm b/perl/AGWMsg.pm index 6a364535..910d32cc 100644 --- a/perl/AGWMsg.pm +++ b/perl/AGWMsg.pm @@ -51,12 +51,15 @@ $connectinterval = 30; sub init { return unless $enable; - $rproc = shift; + # only set $rproc if there is something to set rproc from! + my $rp = shift; + $rproc = $rp if defined $rp; + finish(); dbg("AGW initialising and connecting to $addr/$port ..."); - $sock = IO::Socket::INET->new(PeerAddr => $addr, PeerPort => $port, Proto=>'tcp', Timeout=>15); + $sock = IO::Socket::INET->new(PeerAddr => $addr, PeerPort => $port, Proto=>'tcp', Timeout=>3); $lastconnect = $main::systime; unless ($sock) { dbg("Cannot connect to AGW Engine at $addr/$port $!"); @@ -101,7 +104,9 @@ sub finish Msg::set_event_handler($sock, read=>undef, write=>undef, error=>undef); $sock->close; $lastconnect = $main::systime; + $sock = undef; } + $finishing = 0; } sub login @@ -123,6 +128,8 @@ sub _sendf my $pid = shift || 0; my $data = shift || ''; my $len = 0; + + return unless $sock; $len = length $data; if ($sort eq 'y' || $sort eq 'H') { @@ -211,9 +218,10 @@ sub _rcv { # Complement to _send } } else { if (Msg::_err_will_block($!)) { - return; + return; } else { - $bytes_read = 0; + _error(); + return; } } @@ -227,14 +235,17 @@ FINISH: sub _error { - dbg("error on AGW connection $addr/$port $!"); + return if $finishing; + $finishing++; + dbg("AGW connection error on $addr/$port $!"); Msg::set_event_handler($sock, read=>undef, write=>undef, error=>undef); - $sock = undef; for (%circuit) { &{$_->{eproc}}() if $_->{eproc}; $_->disconnect; } + $sock = undef; $lastconnect = $main::systime; + $finishing = 0; } sub _decode @@ -398,6 +409,13 @@ sub _find return $circuit{$call}; } +sub peerhost +{ + my $conn = shift; + $conn->{peerhost} ||= 'ax25'; + return $conn->{peerhost}; +} + sub connect { my ($conn, $line) = @_; @@ -451,7 +469,7 @@ sub enqueue sub process { # try to reconnect to AGW if we could not previously or there was an error - if ($enable && !$sock && ($lastconnect + $connectinterval) >= $main::systime) { + if ($enable && !$sock && $main::systime >= $lastconnect + $connectinterval) { init(); } return unless $sock;