TcpStream read() method

Hi all,

When TcpStream read() method returns 0, it's not very clear according to the docs. I designed a Rust simple Tcp server and when I close the socket from a Python client, it seems the read() method returns 0.

But it's not really clear why.

Any clue?

If you pass a non-zero length buffer to read into, a read of 0 indicates end of stream (EOS) - the remote has shut down (at least) its sending half of the duplex.

So in other words: its the regular behavior? When the Python client closed the socket, the read() returns 0 ?

Yup - if the remote closes its end gracefully you’ll get a read of 0; if it does it ungracefully (eg sends a RST packet) then you’ll get an Error variant of the Result.

@vitalyd thanks a lot for the clarification !