From 6d1a2542038841e62df40d6d8ea3f743c17e4ec2 Mon Sep 17 00:00:00 2001 From: Matti Aarnio Date: Wed, 26 Mar 2008 17:18:01 +0000 Subject: [PATCH] rx and coresimurx terminate when all connections to target system terminate git-svn-id: http://repo.ham.fi/svn/aprsc/trunk@261 3ce903b1-3385-4e86-93cd-f9a4a239f7ac --- tools/aprs-is-coresimurx | 26 ++++++++++++++++++++------ tools/aprs-is-rx | 29 ++++++++++++++++++++++------- 2 files changed, 42 insertions(+), 13 deletions(-) diff --git a/tools/aprs-is-coresimurx b/tools/aprs-is-coresimurx index e9e3951..108d36e 100644 --- a/tools/aprs-is-coresimurx +++ b/tools/aprs-is-coresimurx @@ -15,6 +15,7 @@ $VERSION = 'APRS-IS-CORESIMRX version-1.0'; +use strict; use POSIX; use IO::Multiplex; @@ -23,6 +24,7 @@ select STDOUT; $| = 1; my $quit = 0; my $APRSIS; my $N = 10; +my $fdcount = 0; my @specdata = simspecs(); # printf "specdata: $#specdata\n"; @@ -30,7 +32,7 @@ my @specdata = simspecs(); ## Now fork me N ways.. if ($N > 1) { - for $n (1..$N) { + foreach my $n (1..$N) { my $pid = fork(); if ($pid == 0) { # Client work($n % $N,$N); @@ -38,7 +40,7 @@ if ($N > 1) { } } - for $n (1..$N) { + foreach my $n (1..$N) { wait; } } else { @@ -53,8 +55,10 @@ sub work { my @APRS = (); my $MUX = new IO::Multiplex; my $u; - my $n = 0; + + $fdcount = 0; + foreach my $l (@specdata) { ++$n; @@ -86,9 +90,12 @@ sub work { } $MUX->add( $APRSIS->sock() ); + ++$fdcount; $u = $APRSIS->socku(); - $MUX->add( $u ) if (defined($u)); + if (defined($u)) { + $MUX->add( $u ); + } push @APRS, $APRSIS; } @@ -122,10 +129,17 @@ sub mux_input { sub mux_eof { my $package = shift; - my $mux = shift; + my $MUX = shift; my $fh = shift; - $MUX->shutdown($fh, 1); + $MUX->close($fh); + $MUX->remove($fh); + + --$fdcount; ## count controls only.. + if ($fdcount == 0) { + $MUX->endloop(); + exit 0; + } } diff --git a/tools/aprs-is-rx b/tools/aprs-is-rx index 4ea61fa..e392e4b 100755 --- a/tools/aprs-is-rx +++ b/tools/aprs-is-rx @@ -17,10 +17,14 @@ my $mycall = 'OH2MQK-RR'; #$filter = 'p/OH'; #$APRSIS = APRS::IS->new('finland.aprs2.net:10152', $mycall, $filter); +#$APRSIS = APRS::IS->new('finland.aprs2.net:10152u', $mycall, $filter); +#$APRSIS = APRS::IS->new('finland.aprs2.net:14580u', $mycall, $filter); #$APRSIS = APRS::IS->new('rotate.aprs.net:23', $mycall, $filter); $APRSIS = APRS::IS->new('first.aprs.net:10152u', $mycall, $filter ); +#$APRSIS = APRS::IS->new('first.aprs.net:24579', $mycall, undef ); #$APRSIS = APRS::IS->new('localhost:10152u', $mycall, $filter ); #$APRSIS = APRS::IS->new('localhost:14580', $mycall, $filter ); +#$APRSIS = APRS::IS->new('localhost:14580u', $mycall, $filter ); if (!defined($APRSIS)) { printf "aprsazel: Failed to open APRS-IS socket!\n"; @@ -43,29 +47,40 @@ exit 0; sub mux_input { my $package = shift; - my $mux = shift; + my $MUX = shift; my $fh = shift; my $data = shift; - if (fileno($fh) == fileno($Uclient)) { + if ($MUX->is_udp($fh)) { printf "%d\t%s\n", time, $$data; $$data = ''; + + } else { + + # Process each line in the input, leaving partial lines + # in the input buffer + while ($$data =~ s/^(.*?)\n//) { + printf "%d\t%s\n", time, $1; + } } - # Process each line in the input, leaving partial lines - # in the input buffer - while ($$data =~ s/^(.*?)\n//) { - printf "%d\t%s\n", time, $1; + if (time > $last) { + $MUX->close($fh); + $MUX->remove($fh); + $MUX->endloop(); + exit 0; } } sub mux_eof { my $package = shift; - my $mux = shift; + my $MUX = shift; my $fh = shift; $MUX->close($fh); + $MUX->remove($fh); + $MUX->endloop(); }