Closed akhi3030 closed 9 months ago
Indeed, io::split
does not work in that way. You must explicitly call shutdown
to close it.
Hi I am a newbie of Tokio and also stuck in this issue.
shutdown
indeed avoid hangs, but what I am trying to do is an echo client that can repeatedly send and receive bytes, the pseudo code is like:
I need to reuse the writer so I can't use shutdown
, what should I do?
I am not sure if this my own bug; expected behaviour; or something can be improved in the tutorial.
When I run the client code reproduced below, the process hangs. I would've expected it to exit after receiving all the payload.
Output:
I would've naively thought that when the writing task above returns, that will close the socket for writing but still keep it open for reading. At least on linux, this can be accomplished by using shutdown. This will cause the echo server to get an
EOF
when it tries to read from the socket and cause it to close the socket which will then cause the client to seen == 0
condition when it calls reads; break; and then the process would exit.Maybe this is not
io::split
works. The smallest change to make might be to add a note to the tutorial to indicate that the client does not exit. A more involved change might be see how to get the client to properly exit.