Skip to content
This repository has been archived by the owner on Sep 9, 2023. It is now read-only.

should net.JSONStream.aclose use stream.send_eof? #3

Open
math2001 opened this issue Apr 27, 2019 · 1 comment
Open

should net.JSONStream.aclose use stream.send_eof? #3

math2001 opened this issue Apr 27, 2019 · 1 comment

Comments

@math2001
Copy link
Owner

I originally implemented net.JSONStream.aclose by just closing the underlying stream because I had forgotten about send_eof, but now I'm not sure what are the benefits of it.

What do I gain by being polite? Less angry error messages? Letting the other one know that we're willingly closing, and not crashing? Could that result in a different behavior from the server? Should net.JSONStream raise a different error?

@math2001
Copy link
Owner Author

import trio

async def handler(stream: trio.SocketStream) -> None:
    while True:
        data = await stream.receive_some(1024)
        if not data:
            print("no more data")
            return
        print(repr(data))


async def client() -> None:
    stream = await trio.open_tcp_stream("localhost", 9999)
    await stream.send_all(b"Bye...\n")
    # await stream.send_eof() # toggle
    await stream.aclose()


async def main() -> None:
    async with trio.open_nursery() as nursery:
        nursery.start_soon(trio.serve_tcp, handler, 9999)
        nursery.start_soon(client)

trio.run(main)

I don't see any difference...

Relevant docs: https://trio.readthedocs.io/en/latest/reference-io.html#trio.abc.HalfCloseableStream.send_eof

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant