Fix some problems (on testing) with AGW restarts
authorDirk Koopman <djk@tobit.co.uk>
Tue, 26 Feb 2008 13:12:43 +0000 (13:12 +0000)
committerDirk Koopman <djk@tobit.co.uk>
Tue, 26 Feb 2008 13:12:43 +0000 (13:12 +0000)
I have got a copy of AGW Packet Engine Pro on windows and tested
the code with that. I have also added some commands to enable/disable
the AGW connection on the fly.

cmd/Commands_en.hlp
cmd/set/agwengine.pl [new file with mode: 0644]
cmd/unset/agwengine.pl [new file with mode: 0644]
perl/AGWMsg.pm
perl/Messages
perl/Version.pm

index 4382ba754513a9cec504e809bb2cbb307d723eac..fd27ae402a8cabddee0015e84cb9e5a6088c03eb 100644 (file)
@@ -1375,6 +1375,15 @@ message.
 You can carry on with the message until you are ready to send it. 
 === 0^SET/ADDRESS <your address>^Record your postal address
 
+=== 9^SET/AGWENGINE^Enable the AGW Engine
+=== 9^UNSET/AGWENGINE^Disable the AGW Engine
+These commands assume that /spider/local/AGWConnect.pm has been setup
+correctly and you wish to do some testing or otherwise want to alter
+the default state of your connection to the AGW Engine.
+
+=== 9^SET/AGWMONITOR^Enable Monitoring on the AGW Engine
+=== 9^UNSET/AGWMONITOR^Disable Monitoring on the AGW Engine
+
 === 0^SET/ANNOUNCE^Allow announce messages to come out on your terminal
 === 0^UNSET/ANNOUNCE^Stop announce messages coming out on your terminal
 
diff --git a/cmd/set/agwengine.pl b/cmd/set/agwengine.pl
new file mode 100644 (file)
index 0000000..6d0fa86
--- /dev/null
@@ -0,0 +1,14 @@
+#
+# set AGW engine on
+#
+#
+#
+
+my $self = shift;
+return (1, $self->msg('e5')) if $self->priv < 9;
+unless ($AGWMsg::enable) {
+       $AGWMsg::enable = 1;
+       return (1, $self->msg('agwe'));
+}
+return (1);
+
diff --git a/cmd/unset/agwengine.pl b/cmd/unset/agwengine.pl
new file mode 100644 (file)
index 0000000..1c9e7d7
--- /dev/null
@@ -0,0 +1,14 @@
+#
+# set AGW engine off
+#
+#
+#
+
+my $self = shift;
+return (1, $self->msg('e5')) if $self->priv < 9;
+if ($AGWMsg::enable) {
+       AGWMsg::finish() if $AGWMsg::sock;
+       $AGWMsg::enable = 0;
+       return (1, $self->msg('agwu'));
+}
+return (1);
index 6a36453517f048f4b187f04a6dd774bb4152d402..c167d994a883eb7d0433495b512d03582679060d 100644 (file)
@@ -46,7 +46,7 @@ $hpolltime = 300 unless defined $hpolltime;
 %circuit = ();
 $total_in = $total_out = 0;
 $lastconnect = 0;
-$connectinterval = 30;
+$connectinterval = 60;
 
 sub init
 {
@@ -56,7 +56,7 @@ sub init
        finish();
 
        dbg("AGW initialising and connecting to $addr/$port ...");
-       $sock = IO::Socket::INET->new(PeerAddr => $addr, PeerPort => $port, Proto=>'tcp', Timeout=>15);
+       $sock = IO::Socket::INET->new(PeerAddr => $addr, PeerPort => $port, Proto=>'tcp', Timeout=>3);
        $lastconnect = $main::systime;
        unless ($sock) {
                dbg("Cannot connect to AGW Engine at $addr/$port $!");
@@ -101,7 +101,9 @@ sub finish
                Msg::set_event_handler($sock, read=>undef, write=>undef, error=>undef);
                $sock->close;
                $lastconnect = $main::systime;
+               $sock = undef;
        }
+       $finishing = 0;
 }
 
 sub login
@@ -211,9 +213,10 @@ sub _rcv {                     # Complement to _send
                } 
        } else {
                if (Msg::_err_will_block($!)) {
-                       return; 
+                       return;
                } else {
-                       $bytes_read = 0;
+                       _error();
+                       return;
                }
     }
 
@@ -227,14 +230,17 @@ FINISH:
 
 sub _error
 {
-       dbg("error on AGW connection $addr/$port $!");
+       return if $finishing;
+       $finishing++;
+       dbg("AGW connection error on $addr/$port $!");
        Msg::set_event_handler($sock, read=>undef, write=>undef, error=>undef);
-       $sock = undef;
        for (%circuit) {
                &{$_->{eproc}}() if $_->{eproc};
                $_->disconnect;
        }
+       $sock = undef;
        $lastconnect = $main::systime;
+       $finishing = 0;
 }
 
 sub _decode
@@ -451,7 +457,7 @@ 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) {
+       if ($enable && !$sock && $main::systime >= $lastconnect + $connectinterval) {
                init();
        }
        return unless $sock;
index 3b0db325a752cff45b74b65ccf5ecb855c317788..11c70d52d5d7847dfc12ae5b98b60eec9e58a225 100644 (file)
@@ -10,7 +10,9 @@ package DXM;
 %msgs = (
                 en => {
                                addr => 'Address set to: $_[0]',
-                               already => '$_[0] already connected',
+                               agwe => 'AGW Engine enabled',
+                               agwu => 'AGW Engine disabled',
+                               already => '$_[0] already connected',
                                anns => 'Announces enabled for $_[0]',
                                annu => 'Announces disabled for $_[0]',
                                annts => 'AnnTalk enabled for $_[0]',
index 1c42dfb065fd372c2fb0d1c90ed86230f2a76b5f..d179c7ce06ab1a9455fe14390610f04c7df12d5f 100644 (file)
@@ -11,6 +11,6 @@ use vars qw($version $subversion $build);
 
 $version = '1.54';
 $subversion = '0';
-$build = '207';
+$build = '208';
 
 1;