Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Chapter 20.1: incorrect statement about TcpStream buffering #2058

Closed
ztlpn opened this issue Aug 16, 2019 · 3 comments
Closed

Chapter 20.1: incorrect statement about TcpStream buffering #2058

ztlpn opened this issue Aug 16, 2019 · 3 comments
Labels
Milestone

Comments

@ztlpn
Copy link

ztlpn commented Aug 16, 2019

The book states:

Finally, flush will wait and prevent the program from continuing until all the bytes are written to the connection; TcpStream contains an internal buffer to minimize calls to the underlying operating system.

But as far as I can see, there is no user-space buffering in TcpStream - it is just a wrapper of an underlying OS handle. Consequently, flush() is a no-op: https://github.com/rust-lang/rust/blob/93b6d9e086c6910118a57e4332c9448ab550931f/src/libstd/net/tcp.rs#L589

@vmedea
Copy link

vmedea commented Sep 5, 2019

Right—and from what I understand the "stream.write" might potentially return before having written all bytes, as documented "Calls to write are not guaranteed to block waiting for data to be written".

Another thing that made me wonder, is the stream.read() which does one read from the socket, this may or may not be an entire HTTP request. I understand that the example is just an example, and maybe handling only good-weather outcomes is good enough, but I've seen people in various channels confused by this when moving on to writing real networking software.

@carols10cents
Copy link
Member

Does anyone participating in this issue have a proposed fix?

@carols10cents carols10cents added this to the ch20 milestone Jul 17, 2021
@aradwann aradwann mentioned this issue Jan 1, 2023
@aradwann
Copy link

this is issue still not completely solved and a solution is proposed in PR #3490

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

No branches or pull requests

4 participants