Retry connection to AGW to every 30 seconds on fail
authorDirk Koopman <djk@tobit.co.uk>
Mon, 25 Feb 2008 19:02:25 +0000 (19:02 +0000)
committerDirk Koopman <djk@tobit.co.uk>
Mon, 25 Feb 2008 19:02:25 +0000 (19:02 +0000)
If the connection to AGW goes away or AGW is not loaded when dxspider starts
up, then there was no retry mechanism for restarting the connection. Now
it will try to connect every 30 seconds if AGW is enabled and there is no
connection present.

Changes
perl/AGWMsg.pm
perl/Version.pm

diff --git a/Changes b/Changes
index 48c17ba80836a8848a311f35b2d73ad43a7df342..8e15eddd51e427a8f2eddd6da03dc96372f3c3a4 100644 (file)
--- a/Changes
+++ b/Changes
@@ -1,3 +1,6 @@
+25Feb08=======================================================================
+1. Arrange for AGWMsg to retry connection either if the AGW engine isn't
+loaded on startup or it disappears for some reason and restarts.
 19Feb08=======================================================================
 1. Added CTY-1801 cty.dat data.
 2. Fix problem with entering non-ascii data and then executing commands that
index 771551430a99b7d7b1bf704ba330dd0ffc02efc0..6a36453517f048f4b187f04a6dd774bb4152d402 100644 (file)
@@ -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,6 +45,8 @@ $ypolltime = 10 unless defined $ypolltime;
 $hpolltime = 300 unless defined $hpolltime;
 %circuit = ();
 $total_in = $total_out = 0;
+$lastconnect = 0;
+$connectinterval = 30;
 
 sub init
 {
@@ -51,8 +54,10 @@ sub init
        $rproc = shift;
        
        finish();
+
        dbg("AGW initialising and connecting to $addr/$port ...");
        $sock = IO::Socket::INET->new(PeerAddr => $addr, PeerPort => $port, Proto=>'tcp', Timeout=>15);
+       $lastconnect = $main::systime;
        unless ($sock) {
                dbg("Cannot connect to AGW Engine at $addr/$port $!");
                return;
@@ -95,6 +100,7 @@ sub finish
                Msg->sleep(2);
                Msg::set_event_handler($sock, read=>undef, write=>undef, error=>undef);
                $sock->close;
+               $lastconnect = $main::systime;
        }
 }
 
@@ -228,6 +234,7 @@ sub _error
                &{$_->{eproc}}() if $_->{eproc};
                $_->disconnect;
        }
+       $lastconnect = $main::systime;
 }
 
 sub _decode
@@ -443,7 +450,12 @@ sub enqueue
 
 sub process
 {
+       # try to reconnect to AGW if we could not previously or there was an error
+       if ($enable && !$sock && ($lastconnect + $connectinterval) >= $main::systime) {
+               init();
+       }
        return unless $sock;
+
        if ($ypolltime && $main::systime - $lastytime >= $ypolltime) {
                for (my $i = 0; $i < $noports; $i++) {
                        _sendf('y', undef, undef, $i );
index 4c97d8866f4d78a1519c2404eba22f7ac5daa647..1c42dfb065fd372c2fb0d1c90ed86230f2a76b5f 100644 (file)
@@ -11,6 +11,6 @@ use vars qw($version $subversion $build);
 
 $version = '1.54';
 $subversion = '0';
-$build = '206';
+$build = '207';
 
 1;