diff options
author | Chris Kuethe <chris.kuethe@gmail.com> | 2005-08-05 04:14:52 +0000 |
---|---|---|
committer | Chris Kuethe <chris.kuethe@gmail.com> | 2005-08-05 04:14:52 +0000 |
commit | 6271460e0700823029bc64212be31895612880fd (patch) | |
tree | 88544da554f041164ba28d61ec366d775402759e | |
parent | 06de3b96d2f72540fc5588ff81773bbf46b4b8f5 (diff) | |
download | gpsd-6271460e0700823029bc64212be31895612880fd.tar.gz |
Reconnect if the server goes away.
GPSD might drop the socket if decides to reopen the serial line.
-rwxr-xr-x | contrib/gpxlogger.pl | 16 |
1 files changed, 9 insertions, 7 deletions
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"); ########################################################################### |