summaryrefslogtreecommitdiff
path: root/src/IvyIO.pm
diff options
context:
space:
mode:
Diffstat (limited to 'src/IvyIO.pm')
-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);