diff options
| author | manuel <manuel@mausz.at> | 2013-12-25 19:30:41 +0100 |
|---|---|---|
| committer | manuel <manuel@mausz.at> | 2013-12-25 19:30:41 +0100 |
| commit | bdd42c323cafb4ac054ce902c77d4a39bfe5c425 (patch) | |
| tree | 2b8dc37a60fa870a69f8123b1c189cccb2611dcf /python | |
| parent | d70072c2f4c348ba2f6a562fa31e3245209cf21f (diff) | |
| download | webiopi-bdd42c323cafb4ac054ce902c77d4a39bfe5c425.tar.gz webiopi-bdd42c323cafb4ac054ce902c77d4a39bfe5c425.tar.bz2 webiopi-bdd42c323cafb4ac054ce902c77d4a39bfe5c425.zip | |
add icmp timeout support
Diffstat (limited to 'python')
| -rw-r--r-- | python/webiopi/devices/sensor/icmp.py | 7 |
1 files changed, 4 insertions, 3 deletions
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): | |||
| 36 | return Duration.__family__(self) | 36 | return Duration.__family__(self) |
| 37 | 37 | ||
| 38 | def __getMilliseconds__(self): | 38 | def __getMilliseconds__(self): |
| 39 | return self.echo(self.ip, 1) * 1000 | 39 | sec = self.echo(self.ip, 1) |
| 40 | return sec * 1000 if sec > 0 else -1 | ||
| 40 | 41 | ||
| 41 | def close(self): | 42 | def close(self): |
| 42 | pass | 43 | pass |
| @@ -79,7 +80,7 @@ class ICMP(Duration): | |||
| 79 | while True: | 80 | while True: |
| 80 | ready = select.select([sock], [], [], timeout) | 81 | ready = select.select([sock], [], [], timeout) |
| 81 | if ready[0] == []: # Timeout | 82 | if ready[0] == []: # Timeout |
| 82 | return | 83 | return -1 |
| 83 | 84 | ||
| 84 | time_received = time() | 85 | time_received = time() |
| 85 | rec_packet, addr = sock.recvfrom(1024) | 86 | rec_packet, addr = sock.recvfrom(1024) |
| @@ -91,7 +92,7 @@ class ICMP(Duration): | |||
| 91 | 92 | ||
| 92 | timeout -= time_received - time_sent | 93 | timeout -= time_received - time_sent |
| 93 | if timeout <= 0: | 94 | if timeout <= 0: |
| 94 | return | 95 | return -1 |
| 95 | 96 | ||
| 96 | def echo(self, dest_addr, timeout=1): | 97 | def echo(self, dest_addr, timeout=1): |
| 97 | """ | 98 | """ |
