Skip to content

Commit

Permalink
chore: check on writes
Browse files Browse the repository at this point in the history
  • Loading branch information
JurgenR committed Oct 28, 2024
1 parent e7187ac commit c68cf9a
Showing 1 changed file with 4 additions and 7 deletions.
11 changes: 4 additions & 7 deletions src/aioslsk/network/connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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):
Expand Down

0 comments on commit c68cf9a

Please sign in to comment.