-
Notifications
You must be signed in to change notification settings - Fork 1
Added optional separator argument to TcpIo constructor #209
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from 3 commits
66716f8
a12fd71
c5d3f38
62b74a1
3e62b7c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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 | ||
|
|
@@ -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") | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.