Skip to content

How tokio::io::AsyncWriteExt, shutdown method works on tokio::io::WriteHalf #4382

Answered by Darksonn
Geo-7 asked this question in General
Discussion options

You must be logged in to vote

In general, a TCP stream has two directions of communication, and each direction is closed independently. When you call shutdown, that closes your write direction, and the other end's read call will return with a read of length zero, which indicates that the stream is permanently closed in that direction. The tokio::io::copy method will keep running until it gets a read of length zero, at which point it will make sure to finish writing anything it still hasn't written, then return.

You usually don't close your stream in the read direction — that's the job of the other client, since that's their write direction.

The caller from the docs is whoever called shutdown.

Replies: 1 comment 2 replies

Comment options

You must be logged in to vote
2 replies
@Geo-7
Comment options

@Darksonn
Comment options

Answer selected by Geo-7
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
2 participants