dealloc async_stream instances in connection termination
- improve close handler - clearify logging on disconnection
This commit is contained in:
@@ -7,21 +7,28 @@ class Proxy:
|
||||
proxy.ClientStream = None
|
||||
|
||||
async def server_loop(proxy, addr):
|
||||
logging.info(f'Accept connection from {addr}')
|
||||
'''Loop for receiving messages from the inverter (server-side)'''
|
||||
logging.info(f'Accept connection from {addr}')
|
||||
await proxy.ServerStream.loop()
|
||||
logging.info(f'Close server connection {addr}')
|
||||
logging.info(f'Server loop stopped for {addr}')
|
||||
|
||||
# if the server connection closes, we also disconnect the connection to te TSUN cloud
|
||||
if proxy.ClientStream:
|
||||
logging.debug ("close client connection")
|
||||
proxy.ClientStream.close()
|
||||
logging.debug ("disconnect client connection")
|
||||
proxy.ClientStream.disc()
|
||||
|
||||
async def client_loop(proxy, addr):
|
||||
'''Loop for receiving messages from the TSUN cloud (client-side)'''
|
||||
await proxy.ClientStream.loop()
|
||||
logging.info(f'Close client connection {addr}')
|
||||
proxy.ServerStream.remoteStream = None
|
||||
logging.info(f'Client loop stopped for {addr}')
|
||||
|
||||
# if the client connection closes, we don't touch the server connection. Instead we erase the client
|
||||
# connection stream, thus on the next received packet from the inverter, we can establish a new connection
|
||||
# to the TSUN cloud
|
||||
proxy.ClientStream = None
|
||||
|
||||
async def CreateClientStream (proxy, stream, host, port):
|
||||
'''Establish a client connection to the TSUN cloud'''
|
||||
addr = (host, port)
|
||||
|
||||
try:
|
||||
|
||||
Reference in New Issue
Block a user