From bdd42c323cafb4ac054ce902c77d4a39bfe5c425 Mon Sep 17 00:00:00 2001 From: manuel Date: Wed, 25 Dec 2013 19:30:41 +0100 Subject: add icmp timeout support --- python/webiopi/devices/sensor/icmp.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'python') diff --git a/python/webiopi/devices/sensor/icmp.py b/python/webiopi/devices/sensor/icmp.py index 8a4065d..37028fa 100644 --- a/python/webiopi/devices/sensor/icmp.py +++ b/python/webiopi/devices/sensor/icmp.py @@ -36,7 +36,8 @@ class ICMP(Duration): return Duration.__family__(self) def __getMilliseconds__(self): - return self.echo(self.ip, 1) * 1000 + sec = self.echo(self.ip, 1) + return sec * 1000 if sec > 0 else -1 def close(self): pass @@ -79,7 +80,7 @@ class ICMP(Duration): while True: ready = select.select([sock], [], [], timeout) if ready[0] == []: # Timeout - return + return -1 time_received = time() rec_packet, addr = sock.recvfrom(1024) @@ -91,7 +92,7 @@ class ICMP(Duration): timeout -= time_received - time_sent if timeout <= 0: - return + return -1 def echo(self, dest_addr, timeout=1): """ -- cgit v1.2.3