From 6271460e0700823029bc64212be31895612880fd Mon Sep 17 00:00:00 2001 From: Chris Kuethe Date: Fri, 5 Aug 2005 04:14:52 +0000 Subject: Reconnect if the server goes away. GPSD might drop the socket if decides to reopen the serial line. --- contrib/gpxlogger.pl | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) (limited to 'contrib') diff --git a/contrib/gpxlogger.pl b/contrib/gpxlogger.pl index 5d6153d9..f60ec5c2 100755 --- a/contrib/gpxlogger.pl +++ b/contrib/gpxlogger.pl @@ -36,6 +36,13 @@ getopts ("hi:p:s:vw:", \%opt); usage() if (defined($opt{'h'})); check_options(); +open($out, ">" . $opt{'w'}) or die "Can't open $opt{'w'}: $!\n"; +select((select($out), $| = 1)[0]); +write_header(); + +$SIG{'TERM'} = $SIG{'QUIT'} = $SIG{'HUP'} = $SIG{'INT'} = \&cleanup; + +while (1){ #connect print "Connecting to $opt{'s'}:$opt{'p'}" if ($opt{'v'}); $sock = IO::Socket::INET->new(PeerAddr => $opt{'s'}, @@ -45,12 +52,6 @@ $sock = IO::Socket::INET->new(PeerAddr => $opt{'s'}, or die "\nCouldn't connect to $opt{'s'}:$opt{'p'} - $@\n"; print " OK!\n" if ($opt{'v'}); -open($out, ">" . $opt{'w'}) or die "Can't open $opt{'w'}: $!\n"; -select((select($out), $| = 1)[0]); -write_header(); - -$SIG{'TERM'} = $SIG{'QUIT'} = $SIG{'HUP'} = $SIG{'INT'} = \&cleanup; - print $sock "MSQO\n"; while (defined( $line = <$sock> )){ chomp $line; @@ -72,7 +73,8 @@ while (defined( $line = <$sock> )){ sleep($opt{'i'}); print $sock "MSQO\n"; } - +sleep(1); +} cleanup("PIPE"); ########################################################################### -- cgit v1.2.1