Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions src/tickit/adapters/io/tcp_io.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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")
Expand Down
Loading