Skip to content
Open
Changes from 3 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, separator: str = None) -> None:
self.host = host
self.port = port
self.separator = separator
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: I'm not sure the name separator is completely right, maybe terminator? Or just add a comment explaining what it does, it's not immediately obvious to me from the name (unlike host and port). Not bothered by that enough to block merge though.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks Callum, i'm not too sure about this name either, the reason I chose separator is because that's the name of the parameter in StreamReader.readUntil. I guess in this context it really is a terminator though. It probably makes sense to change it, i'll do that now


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.separator is not 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