Skip to content

TcpStream behaviour and shutdown. #5968

Answered by Darksonn
antogilbert asked this question in Q&A
Discussion options

You must be logged in to vote

When you write:

stream = connect();

This will do the following operations:

  1. Call connect().
  2. Run the destructor of the previous socket in stream.
  3. Move the return value of connect() into the stream variable.

Running the destructor is enough to close the socket.


Also, in case I keep calling read_buf on a TcpStream that returned 0, what will the code do?

The read_buf method only returns 0 if the read direction of your TcpStream has been closed. Once that happens, you will never get any more data, so all future calls to read_buf will also return 0. You should stop trying to read from it when you get a read of length zero.


The AsyncWriteExt::shutdown method doesn't do the same thing as dr…

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by antogilbert
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants