From ef11349956f2cda28a513b32e4da8947e60d3568 Mon Sep 17 00:00:00 2001 From: etienne Date: Thu, 27 Dec 2007 15:33:32 +0000 Subject: Quand un agent ne repond pas au ping ou si le temps de reponse excede 1s, le voyant devient rouge fonce fixe. --- src/IvyIO.pm | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) (limited to 'src') 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); -- cgit v1.1