diff --git a/oml/localnodes.py b/oml/localnodes.py index 915d0f0..d61b65d 100644 --- a/oml/localnodes.py +++ b/oml/localnodes.py @@ -8,6 +8,7 @@ import struct import _thread from threading import Thread import time +import select from utils import valid, get_public_ipv6, get_local_ipv4, get_interface from settings import preferences, server, USER_ID, sk @@ -51,7 +52,6 @@ class LocalNodesBase(Thread): _PORT = 9851 _TTL = 1 - _TIMEOUT = 30 def __init__(self, nodes): self._socket = None @@ -85,12 +85,12 @@ class LocalNodesBase(Thread): def receive(self): last = time.mktime(time.localtime()) + s = self.get_socket() + s.bind(('', self._PORT)) while self._active: try: - s = self.get_socket() - s.settimeout(self._TIMEOUT) - s.bind(('', self._PORT)) - while self._active: + r, _, _ = select.select([s], [], [], 3) + if r: data, addr = s.recvfrom(1024) if self._active: while data[-1] == 0: @@ -98,8 +98,6 @@ class LocalNodesBase(Thread): data = self.verify(data) if data: self.update_node(data) - except socket.timeout: - pass except OSError: # no local interface exists self.wait(60) except: