summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authoretienne2007-12-27 15:33:32 +0000
committeretienne2007-12-27 15:33:32 +0000
commitef11349956f2cda28a513b32e4da8947e60d3568 (patch)
tree52b90ba23b3a280a7698cc1e034fc2327ffd4d86 /src
parent798da97069621c35e6549bcc3f5b6570894e718f (diff)
downloadivycontrolpanel-ef11349956f2cda28a513b32e4da8947e60d3568.zip
ivycontrolpanel-ef11349956f2cda28a513b32e4da8947e60d3568.tar.gz
ivycontrolpanel-ef11349956f2cda28a513b32e4da8947e60d3568.tar.bz2
ivycontrolpanel-ef11349956f2cda28a513b32e4da8947e60d3568.tar.xz
Quand un agent ne repond pas au ping ou si le temps de reponse excede
1s, le voyant devient rouge fonce fixe.
Diffstat (limited to 'src')
-rw-r--r--src/IvyIO.pm17
1 files changed, 15 insertions, 2 deletions
diff --git a/src/IvyIO.pm b/src/IvyIO.pm
index 76dc968..a08a12a 100644
--- a/src/IvyIO.pm
+++ b/src/IvyIO.pm
@@ -7,13 +7,18 @@ use Tk;
my $ivy;
+my $MW;
my %appNameByhostAndPort = ();
my %diedApp = ();
my $pingcallback;
+my %timerId = ();
+my $pingdelay = 3000;
+my $pongtimeout = 1000;
# init an ivy bus
sub init {
my ($appname, $bus, $conncb, $disconncb, $pingcb, $mw) = @_;
+ $MW = $mw;
Ivy->init(-loopMode => 'TK',
-appName => $appname,
-ivyBus => $bus,
@@ -23,7 +28,7 @@ sub init {
$ivy = Ivy->new(-statusFunc => sub {&_status($conncb, $disconncb, @_);});
$ivy->start;
- $mw->repeat (3000 ,[\&sendPings]) if defined $pingcb;
+ $mw->repeat ($pingdelay ,\&sendPings) if defined $pingcb;
} # end init
@@ -141,6 +146,14 @@ sub sendPings ()
my $appf;
foreach $appf (keys (%appNameByhostAndPort)) {
next if exists $diedApp{$appf};
+ # gestion de timeout : si le pong n'est toujours pas reçu au bout de 500ms
+ # on force l'appel à &$pingcallback avec un timestamp égal à -1
+ $timerId{$appf} =
+ $MW->after($pongtimeout, sub {
+ print "pong timeout on agent $appNameByhostAndPort{$appf} ($pongtimeout ms)\n";
+ &$pingcallback($appNameByhostAndPort{$appf}, $appf, -1);
+ delete $timerId{$appf};
+ });
$ivy->ping ($appf, \&receivePongCb);
}
} # end sendPings
@@ -150,7 +163,7 @@ sub sendPings ()
sub receivePongCb($$)
{
my ($time, $appf) = @_; # time = ping/pong duration in ms
-
+ $MW->afterCancel($timerId{$appf}) if $timerId{$appf};
#printf ("DBG> :$received: $appf [$time]".$appNameByhostAndPort{$appf}."\n");
&$pingcallback($appNameByhostAndPort{$appf}, $appf, $time);