Move sync_resources logic before insert to clients.

This commit is contained in:
Maxim Khomutov 2023-07-13 18:08:47 +03:00
parent dd2c461581
commit 6afe62b68e
2 changed files with 3 additions and 7 deletions

View File

@ -77,7 +77,7 @@ class Client:
await client.tcp_send(data) await client.tcp_send(data)
return return
self.log.debug(f"tcp_send({data})") # self.log.debug(f"tcp_send({data})")
if len(data) == 10: if len(data) == 10:
data += b"." data += b"."
header = len(data).to_bytes(4, "little", signed=True) header = len(data).to_bytes(4, "little", signed=True)
@ -138,10 +138,6 @@ class Client:
async def sync_resources(self): async def sync_resources(self):
while True: while True:
data = await self.recv() data = await self.recv()
if not data:
await asyncio.sleep(.1)
continue
self.log.debug(f"Received: {data}")
if data.startswith(b"f"): if data.startswith(b"f"):
# TODO: SendFile # TODO: SendFile
file = data[1:].decode("utf-8") file = data[1:].decode("utf-8")
@ -166,8 +162,6 @@ class Client:
async def looper(self): async def looper(self):
# self.is_disconnected() # self.is_disconnected()
await self.tcp_send(b"P" + bytes(f"{self.cid}", "utf-8"))
await self.sync_resources()
while self.alive: while self.alive:
data = await self.recv() data = await self.recv()
if data == b"": if data == b"":

View File

@ -72,6 +72,8 @@ class TCPServer:
return False, None return False, None
else: else:
self.log.info("Identification success") self.log.info("Identification success")
await client.tcp_send(b"P" + bytes(f"{client.cid}", "utf-8"))
await client.sync_resources()
await self.Core.insert_client(client) await self.Core.insert_client(client)
return True, client return True, client