Skip to content

Commit

Permalink
Merge pull request #101 from Dirk007/ping_timeout
Browse files Browse the repository at this point in the history
Remove double check for keepalive
  • Loading branch information
Lenka42 committed Mar 13, 2020
2 parents 6311c46 + 61d40a6 commit b66193e
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions gmqtt/mqtt/connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand All @@ -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()
Expand Down

0 comments on commit b66193e

Please sign in to comment.