CommonClient: reduce blind sleep time of keep_alive

This commit is contained in:
Fabian Dill 2021-09-12 21:15:03 +02:00
parent 8cc045f370
commit 0c57d35402
1 changed files with 9 additions and 5 deletions

View File

@ -224,13 +224,17 @@ class CommonContext():
pass
async def keep_alive(ctx: CommonContext):
""" some ISPs/network configurations drop TCP connections if no payload is sent (ignore TCP-keep-alive)
so we send a payload to prevent drop and if we were dropped anyway this will cause a reconnect."""
async def keep_alive(ctx: CommonContext, seconds_between_checks=100):
"""some ISPs/network configurations drop TCP connections if no payload is sent (ignore TCP-keep-alive)
so we send a payload to prevent drop and if we were dropped anyway this will cause an auto-reconnect."""
seconds_elapsed = 0
while not ctx.exit_event.is_set():
await asyncio.sleep(100)
await asyncio.sleep(1) # short sleep to not block program shutdown
if ctx.server and ctx.slot:
await ctx.send_msgs([{"cmd": "Bounce", "slots": [ctx.slot]}])
seconds_elapsed += 1
if seconds_elapsed > seconds_between_checks:
await ctx.send_msgs([{"cmd": "Bounce", "slots": [ctx.slot]}])
seconds_elapsed = 0
async def server_loop(ctx: CommonContext, address=None):