X-Git-Url: http://gb7djk.dxcluster.net/gitweb/gitweb.cgi?a=blobdiff_plain;f=perl%2FAGWMsg.pm;h=910d32cc4c94c50c1f75b023f1666014fcfcb352;hb=f63d598af3f797b56b8d5e23ec4ff5254192eee9;hp=f6fc50747f9a5fa005099630777770e4cdec2986;hpb=5bc87856bb191e42d91628a5a4d9579a242b9541;p=spider.git diff --git a/perl/AGWMsg.pm b/perl/AGWMsg.pm index f6fc5074..910d32cc 100644 --- a/perl/AGWMsg.pm +++ b/perl/AGWMsg.pm @@ -16,7 +16,7 @@ # because I have the 'power of perl' available that avoids me getting # terminally bored sorting out other people's sloppyness. # -# $Id$ +# # # Copyright (c) 2001 - Dirk Koopman G1TLH # @@ -30,7 +30,8 @@ use AGWConnect; use DXDebug; use vars qw(@ISA $sock @outqueue $send_offset $inmsg $rproc $noports $lastytime - $lasthtime $ypolltime $hpolltime %circuit $total_in $total_out); + $lasthtime $ypolltime $hpolltime %circuit $total_in $total_out + $lastconnect $connectinterval); @ISA = qw(Msg ExtMsg); $sock = undef; @@ -44,21 +45,22 @@ $ypolltime = 10 unless defined $ypolltime; $hpolltime = 300 unless defined $hpolltime; %circuit = (); $total_in = $total_out = 0; - -use vars qw($VERSION $BRANCH); -$VERSION = sprintf( "%d.%03d", q$Revision$ =~ /(\d+)\.(\d+)/ ); -$BRANCH = sprintf( "%d.%03d", q$Revision$ =~ /\d+\.\d+\.(\d+)\.(\d+)/ || (0,0)); -$main::build += $VERSION; -$main::branch += $BRANCH; +$lastconnect = 0; +$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 $!"); return; @@ -101,7 +103,15 @@ sub finish Msg->sleep(2); Msg::set_event_handler($sock, read=>undef, write=>undef, error=>undef); $sock->close; + $lastconnect = $main::systime; + $sock = undef; } + $finishing = 0; +} + +sub login +{ + goto &main::login; # save some writing, this was the default } sub active @@ -118,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') { @@ -206,9 +218,10 @@ sub _rcv { # Complement to _send } } else { if (Msg::_err_will_block($!)) { - return; + return; } else { - $bytes_read = 0; + _error(); + return; } } @@ -222,13 +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 @@ -392,6 +409,13 @@ sub _find return $circuit{$call}; } +sub peerhost +{ + my $conn = shift; + $conn->{peerhost} ||= 'ax25'; + return $conn->{peerhost}; +} + sub connect { my ($conn, $line) = @_; @@ -444,7 +468,12 @@ sub enqueue sub process { + # try to reconnect to AGW if we could not previously or there was an error + if ($enable && !$sock && $main::systime >= $lastconnect + $connectinterval) { + init(); + } return unless $sock; + if ($ypolltime && $main::systime - $lastytime >= $ypolltime) { for (my $i = 0; $i < $noports; $i++) { _sendf('y', undef, undef, $i );