aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Phillips <david@sighup.nz>2019-06-22 20:07:19 +1200
committerDavid Phillips <david@sighup.nz>2019-06-22 20:07:19 +1200
commit4f4ea953a567b1fb883106ff28772e56702a9477 (patch)
treeea680b96afe9531c8774b2f2577b8f41c10a65cd
parentc04858116ef69bbe80d0578cb150d6fb9a4a9ac3 (diff)
downloadidalius-4f4ea953a567b1fb883106ff28772e56702a9477.tar.xz
Add soft-watchdog events to userhost ping
-rwxr-xr-xidalius.pl26
1 files changed, 23 insertions, 3 deletions
diff --git a/idalius.pl b/idalius.pl
index eaaca86..ab6a364 100755
--- a/idalius.pl
+++ b/idalius.pl
@@ -55,6 +55,7 @@ POE::Session->create(
_default
_start
irc_001
+ irc_302
irc_kick
irc_ctcp_action
irc_public
@@ -145,13 +146,32 @@ sub run_command {
@arguments);
}
-# Send an effect-free client->server message as a form of ping to allegedly
-# help POE realise when a connection is down. It otherwise seems to not realise
-# a connection has fallen over otherwise.
+my $watchdog_alarm;
+# Handler for userhost response. We use userhost requests as a crude form
+# of backwards ping/keepalive
+sub irc_302 {
+ my ($poek) = @_;
+ # Cancel the watchdog fail timer
+ $poek->delay_remove($watchdog_alarm) if $watchdog_alarm;
+ log_info "Watchdog received pat";
+}
+
+sub ping_fail {
+ log_info "Error: heartbeat failed to pat watchdog. Exiting";
+ exit(1);
+}
+
+# Send a harmless client->server message as a form of heartbeat to allegedly
+# help POE realise when a connection is down. It seems not to realise a
+# connection has fallen over otherwise.
sub custom_ping {
my ($poek) = $_[KERNEL];
+ # Send a ping and schedule the next one
$irc->yield(userhost => $irc->nick_name());
$poek->delay(custom_ping => $ping_delay);
+
+ # Set a watchdog for twice the ping interval
+ $watchdog_alarm = $poek->delay(ping_fail => 2 * $ping_delay);
}
sub drop_priv {