summaryrefslogtreecommitdiff
path: root/src/polaris/protocol.py
diff options
context:
space:
mode:
authorEvgeny Zinoviev <me@ch1p.io>2022-07-02 15:28:29 +0300
committerEvgeny Zinoviev <me@ch1p.io>2022-07-02 15:28:29 +0300
commit4848650e3e3e750d0ddeedabfb1d3e23f88e6a6b (patch)
tree5701bad790433be09059ebe03659cd4b89ccb6cf /src/polaris/protocol.py
parent02607d7eb3b9248ba82c19ee0f274f210a9df10b (diff)
polaris_kettle_bot: make READ_TIMEOUT configurable
Diffstat (limited to 'src/polaris/protocol.py')
-rw-r--r--src/polaris/protocol.py8
1 files changed, 5 insertions, 3 deletions
diff --git a/src/polaris/protocol.py b/src/polaris/protocol.py
index 2a78c47..41f0776 100644
--- a/src/polaris/protocol.py
+++ b/src/polaris/protocol.py
@@ -28,7 +28,6 @@ _logger = logging.getLogger(__name__)
PING_FREQUENCY = 3
RESEND_ATTEMPTS = 5
-READ_TIMEOUT = 1
ERROR_TIMEOUT = 15
MESSAGE_QUEUE_REMOVE_DELAY = 13 # after what time to delete (and pass False to handlers, if needed) messages with phase=DONE from queue
DISCONNECT_TIMEOUT = 15
@@ -739,6 +738,7 @@ class UDPConnection(threading.Thread, ConnectionStatusListener):
incoming_time: float
status: ConnectionStatus
reconnect_tries: int
+ read_timeout: int
_addr_lock: threading.Lock
_iml_lock: threading.Lock
@@ -749,7 +749,8 @@ class UDPConnection(threading.Thread, ConnectionStatusListener):
addr: Union[IPv4Address, IPv6Address],
port: int,
device_pubkey: bytes,
- device_token: bytes):
+ device_token: bytes,
+ read_timeout: int = 1):
super().__init__()
self._logger = logging.getLogger(f'{__name__}.{self.__class__.__name__} <{hex(id(self))}>')
self.setName(self.__class__.__name__)
@@ -771,6 +772,7 @@ class UDPConnection(threading.Thread, ConnectionStatusListener):
self.conn_listeners = [self]
self.status = ConnectionStatus.NOT_CONNECTED
self.reconnect_tries = 0
+ self.read_timeout = read_timeout
self._iml_lock = threading.Lock()
self._csl_lock = threading.Lock()
@@ -880,7 +882,7 @@ class UDPConnection(threading.Thread, ConnectionStatusListener):
sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
sock.bind(('0.0.0.0', self.source_port))
- sock.settimeout(READ_TIMEOUT)
+ sock.settimeout(self.read_timeout)
while not self.interrupted:
with self._st_lock: