From 61d40a694f4fd2c98ea23d78e417cc41ebe25b85 Mon Sep 17 00:00:00 2001 From: Dirk Faust Date: Wed, 4 Mar 2020 09:54:04 +0100 Subject: [PATCH] Use coefficient with faster keepalive check --- gmqtt/mqtt/connection.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/gmqtt/mqtt/connection.py b/gmqtt/mqtt/connection.py index 19f66c2..b2cc01e 100644 --- a/gmqtt/mqtt/connection.py +++ b/gmqtt/mqtt/connection.py @@ -19,7 +19,7 @@ def __init__(self, transport: asyncio.Transport, protocol: MQTTProtocol, clean_s self._last_data_in = time.monotonic() self._last_data_out = time.monotonic() - self._keep_connection_callback = asyncio.get_event_loop().call_later(self._keepalive, self._keep_connection) + self._keep_connection_callback = asyncio.get_event_loop().call_later(self._keepalive / 2, self._keep_connection) @classmethod async def create_connection(cls, host, port, ssl, clean_session, keepalive, loop=None): @@ -36,9 +36,9 @@ def _keep_connection(self): asyncio.ensure_future(self.close()) return - if time.monotonic() - self._last_data_in >= self._keepalive: + if time.monotonic() - self._last_data_in >= 0.8 * self._keepalive: self._send_ping_request() - self._keep_connection_callback = asyncio.get_event_loop().call_later(self._keepalive, self._keep_connection) + self._keep_connection_callback = asyncio.get_event_loop().call_later(self._keepalive / 2, self._keep_connection) def put_package(self, pkg): self._last_data_in = time.monotonic()