Only run 'startup sequence' on reconnect
When a client loses a connection it will currently need to re-subscribe for symbols and receive a symbol data summary as a first quote response. Only run the provided coroutine on reconnect and call the kwarg `on_reconnect`. The client consuming code is entirely expected at this point to know how the symbol registration protocol works.kivy_mainline_and_py3.8
parent
09ae9f5ef1
commit
186befc704
|
@ -116,11 +116,11 @@ class Client:
|
||||||
"""
|
"""
|
||||||
def __init__(
|
def __init__(
|
||||||
self, sockaddr: tuple,
|
self, sockaddr: tuple,
|
||||||
startup_seq: Coroutine,
|
on_reconnect: Coroutine,
|
||||||
auto_reconnect: bool = True,
|
auto_reconnect: bool = True,
|
||||||
):
|
):
|
||||||
self.sockaddr = sockaddr
|
self.sockaddr = sockaddr
|
||||||
self._startup_seq = startup_seq
|
self._recon_seq = on_reconnect
|
||||||
self._autorecon = auto_reconnect
|
self._autorecon = auto_reconnect
|
||||||
self.squeue = None
|
self.squeue = None
|
||||||
|
|
||||||
|
@ -128,7 +128,6 @@ class Client:
|
||||||
sockaddr = sockaddr or self.sockaddr
|
sockaddr = sockaddr or self.sockaddr
|
||||||
stream = await trio.open_tcp_stream(*sockaddr, **kwargs)
|
stream = await trio.open_tcp_stream(*sockaddr, **kwargs)
|
||||||
self.squeue = StreamQueue(stream)
|
self.squeue = StreamQueue(stream)
|
||||||
await self._startup_seq(self)
|
|
||||||
return stream
|
return stream
|
||||||
|
|
||||||
async def send(self, item):
|
async def send(self, item):
|
||||||
|
@ -168,6 +167,8 @@ class Client:
|
||||||
continue
|
continue
|
||||||
else:
|
else:
|
||||||
log.warn("Stream connection re-established!")
|
log.warn("Stream connection re-established!")
|
||||||
|
# run any reconnection sequence
|
||||||
|
await self._recon_seq(self)
|
||||||
break
|
break
|
||||||
except (OSError, ConnectionRefusedError):
|
except (OSError, ConnectionRefusedError):
|
||||||
if not down:
|
if not down:
|
||||||
|
|
Loading…
Reference in New Issue