diff --git a/src/tickit/adapters/io/tcp_io.py b/src/tickit/adapters/io/tcp_io.py index cfc4cadb0..0b3a74ce4 100644 --- a/src/tickit/adapters/io/tcp_io.py +++ b/src/tickit/adapters/io/tcp_io.py @@ -20,9 +20,10 @@ class TcpIo(AdapterIo[CommandAdapter]): host: str port: int - def __init__(self, host: str, port: int) -> None: + def __init__(self, host: str, port: int, terminator: str | None = None) -> None: self.host = host self.port = port + self.terminator = terminator async def setup( self, adapter: CommandAdapter, raise_interrupt: RaiseInterrupt @@ -79,7 +80,13 @@ async def reply(replies: AsyncIterable[Optional[bytes]]) -> None: tasks.append(asyncio.create_task(reply(on_connect()))) while True: - data: bytes = await reader.read(1024) + if self.terminator is not None: + data: bytes = ( + await reader.readuntil(separator=self.terminator.encode()) + ) + else: + data: bytes = await reader.read(1024) + if data == b"": break addr = writer.get_extra_info("peername")