X-Git-Url: http://dxcluster.org/gitweb/gitweb.cgi?a=blobdiff_plain;f=perl%2FAGWMsg.pm;h=7582e2c723be8d45e0e3b0f23293e3d6f72174a3;hb=95345d68a5a8ac618021c0786c7234258b903f6e;hp=5e583d25bdbd4c7ff312a70cf001695d15e5c465;hpb=a2fc02fa7ad04e42be78783a4aa38a771b7d1ec3;p=spider.git diff --git a/perl/AGWMsg.pm b/perl/AGWMsg.pm index 5e583d25..7582e2c7 100644 --- a/perl/AGWMsg.pm +++ b/perl/AGWMsg.pm @@ -30,7 +30,7 @@ use AGWConnect; use DXDebug; use vars qw(@ISA $sock @outqueue $send_offset $inmsg $rproc $noports $lastytime - $lasthtime $ypolltime $hpolltime); + $lasthtime $ypolltime $hpolltime %circuit); @ISA = qw(Msg ExtMsg); $sock = undef; @@ -41,7 +41,8 @@ $rproc = undef; $noports = 0; $lastytime = $lasthtime = time; $ypolltime = 10 unless defined $ypolltime; -$hpolltime = 120 unless defined $hpolltime; +$hpolltime = 300 unless defined $hpolltime; +%circuit = (); sub init { @@ -50,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; @@ -75,12 +76,16 @@ sub init _sendf('m') if $monitor; } +my $finishing = 0; + sub finish { + return if $finishing; if ($sock) { + $finishing = 1; dbg('err', "AGW ending..."); - for (values %Msg::conns) { - next unless $_->isa('AGWMsg'); + for (values %circuit) { + &{$_->{eproc}}() if $_->{eproc}; $_->disconnect; } # say we are going @@ -200,8 +205,8 @@ sub _error dbg('agw', "error on AGW connection $addr/$port $!"); Msg::set_event_handler($sock, read=>undef, write=>undef, error=>undef); $sock = undef; - for (values %Msg::conns) { - next unless $_->isa('AGWMsg'); + for (%circuit) { + &{$_->{eproc}}() if $_->{eproc}; $_->disconnect; } } @@ -299,6 +304,7 @@ sub _decode $conn->{lineend} = "\cM"; $conn->{incoming} = 1; $conn->{agwcall} = $call; + $circuit{$call} = $conn; if ($call =~ /^(\w+)-(\d\d?)$/) { my $c = $1; my $s = $2; @@ -314,16 +320,19 @@ sub _decode } elsif ($sort eq 'd') { dbg('agw', "AGW '$from'->'$to' port: $port Disconnected"); my $conn = _find($from eq $main::mycall ? $to : $from); - $conn->in_disconnect if $conn; + if ($conn) { + &{$conn->{eproc}}() if $conn->{eproc}; + $conn->in_disconnect; + } } elsif ($sort eq 'y') { my ($frames) = unpack "V", $data; dbg('agwpollans', "AGW Frames Outstanding on port $port = $frames"); - my $conn = Msg->conns($from); + my $conn = _find($from); $conn->{oframes} = $frames if $conn; } elsif ($sort eq 'Y') { my ($frames) = unpack "V", $data; dbg('agw', "AGW Frames Outstanding on circuit '$from'->'$to' = $frames"); - my $conn = Msg->conns($from eq $main::mycall ? $to : $from); + my $conn = _find($from eq $main::mycall ? $to : $from); $conn->{oframes} = $frames if $conn; } elsif ($sort eq 'H') { unless ($from =~ /^\s+$/) { @@ -360,12 +369,7 @@ sub _decode sub _find { my $call = shift; - for (values %Msg::conns) { - if ($_->isa('AGWMsg') && $call eq $_->{agwcall}) { - return $_; - } - } - return undef; + return $circuit{$call}; } sub connect @@ -379,6 +383,7 @@ sub connect $conn->{incoming} = 0; $conn->{csort} = 'ax25'; $conn->{agwcall} = uc $call; + $circuit{$conn->{agwcall}} = $conn; _sendf('C', $main::mycall, $conn->{agwcall}, $conn->{agwport}, $conn->{agwpid}); $conn->{state} = 'WC'; @@ -389,13 +394,14 @@ sub connect sub in_disconnect { my $conn = shift; - _sendf('d', $conn->{agwcall}, $main::mycall, $conn->{agwport}, $conn->{agwpid}); + delete $circuit{$conn->{agwcall}}; $conn->SUPER::disconnect; } sub disconnect { my $conn = shift; + delete $circuit{$conn->{agwcall}}; if ($conn->{incoming}) { _sendf('d', $conn->{agwcall}, $main::mycall, $conn->{agwport}, $conn->{agwpid}); } else { @@ -411,6 +417,8 @@ sub enqueue $msg =~ s/^[-\w]+\|//; # _sendf('Y', $main::mycall, $conn->{call}, $conn->{agwport}, $conn->{agwpid}); _sendf('D', $main::mycall, $conn->{agwcall}, $conn->{agwport}, $conn->{agwpid}, $msg . $conn->{lineend}); + my $len = length($msg) + 1; + dbg('agw', "AGW Data Out port: $conn->{agwport} pid: $conn->{agwpid} '$main::mycall'->'$conn->{agwcall}' length: $len \"$msg\""); } } @@ -430,5 +438,6 @@ sub process $lasthtime = $main::systime; } } + 1;