From c68cf9a62b3fcc3bbd334f32cb7cbb74b7ccdc2b Mon Sep 17 00:00:00 2001 From: JurgenR <1249228+JurgenR@users.noreply.github.com> Date: Mon, 28 Oct 2024 22:30:24 +0100 Subject: [PATCH] chore: check on writes --- src/aioslsk/network/connection.py | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/src/aioslsk/network/connection.py b/src/aioslsk/network/connection.py index 9b80772..40c865d 100644 --- a/src/aioslsk/network/connection.py +++ b/src/aioslsk/network/connection.py @@ -444,6 +444,10 @@ def queue_messages(self, *messages: Union[bytes, MessageDataclass]) -> list[asyn ] async def _send(self, data: bytes, timeout: Optional[float] = None): + if not self._writer: + raise ConnectionWriteError( + f"{self.hostname}:{self.port} : cannot send data, connection is not open") + try: self._writer.write(data) if timeout: @@ -477,10 +481,6 @@ async def send_message(self, message: Union[bytes, MessageDataclass]): ) return - if not self._writer: - raise ConnectionWriteError( - f"{self.hostname}:{self.port} : cannot send message, connection is not open") - adapter.debug( "send message : %s", message, @@ -724,9 +724,6 @@ async def receive_file( return async def send_data(self, data: bytes): - if not self._writer: - raise ConnectionWriteError("cannot send data, connection is not open") - await self._send(data, timeout=TRANSFER_TIMEOUT) async def send_file(self, file_handle: AsyncBufferedReader, callback: Optional[Callable[[bytes], None]] = None):