Skip to content

Commit

Permalink
Added optional separator argument to TcpIo constructor
Browse files Browse the repository at this point in the history
  • Loading branch information
LeeHudsonDLS committed Sep 30, 2024
1 parent c213d58 commit 66716f8
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 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, separator: str = None) -> None:
self.host = host
self.port = port
self.separator = separator

async def setup(
self, adapter: CommandAdapter, raise_interrupt: RaiseInterrupt
Expand Down Expand Up @@ -79,7 +80,11 @@ 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.separator != None:
data: bytes = await reader.readuntil(separator=self.separator.encode())
else:
data: bytes = await reader.read(1024)

if data == b"":
break
addr = writer.get_extra_info("peername")
Expand Down

0 comments on commit 66716f8

Please sign in to comment.