Skip to content

Clarify which TcpStream methods won't work in non-blocking mode #46597

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

Closed
n-epifanov opened this issue Dec 9, 2017 · 10 comments
Closed

Clarify which TcpStream methods won't work in non-blocking mode #46597

n-epifanov opened this issue Dec 9, 2017 · 10 comments
Labels
A-docs Area: Documentation for any part of the project, including the compiler, standard library, and tools C-enhancement Category: An issue proposing an enhancement or a PR with one. P-medium Medium priority T-libs-api Relevant to the library API team, which will review and decide on the PR/issue.

Comments

@n-epifanov
Copy link

n-epifanov commented Dec 9, 2017

https://doc.rust-lang.org/std/net/struct.TcpStream.html

According to source code, read_to_end(), read_to_string() and read_exact() won't work properly in non-blocking mode (they hit WouldBlock and start misbehaving). If it's an expected behaviour then it should be noted in the docs.

@frewsxcv
Copy link
Member

i did some work on this in #45227 which hasn't landed in stable yet, but can be seen in the nightly docs

@frewsxcv frewsxcv added the A-docs Area: Documentation for any part of the project, including the compiler, standard library, and tools label Dec 11, 2017
@n-epifanov
Copy link
Author

n-epifanov commented Dec 11, 2017

Oh, so it's just done totally another way! Coming from Python I thought right away "ok, these just don't work then for non-blocking" like readline() in Python :)) Thanks!

@jkordish jkordish added C-enhancement Category: An issue proposing an enhancement or a PR with one. T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue. labels Jan 31, 2018
@frewsxcv
Copy link
Member

frewsxcv commented Feb 3, 2018

According to source code

@NickTime when you have a second, can you point out in the source where it says this?

@n-epifanov
Copy link
Author

n-epifanov commented Feb 4, 2018

First I need to say that I don't know Rust well and don't remember clearly the issue. I think I had a problem with read_exact(), my initial thought was to pass it array of u8, since it takes "buf: &mut [u8]". In non-blocking mode it would read some data into array and return an error (https://doc.rust-lang.org/src/std/io/mod.rs.html#689) and I wouldn't know how much data it actually read.
read_to_end() and read_to_string() would work I guess, but one would need to check Vec length to see how much data were received. What puzzled me is that I was supposed to get data length from return value, but was getting just error. And without an example it wasn't clear that I should just call again with same Vec.

@n-epifanov
Copy link
Author

@frewsxcv Does it make sense? :)
Another confusing thing for me was since function (read_to_end()) returns error then data (buf) is in inconsistent state and is not supposed to be used anyhow as I thought.

@Manishearth Manishearth removed the T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue. label Feb 8, 2018
@steveklabnik steveklabnik added the P-medium Medium priority label Dec 27, 2018
@Rua
Copy link
Contributor

Rua commented Jan 1, 2019

I'd like better documentation on read_exact specifically, in the context of non-blocking I/O. If the read fails with an error, is there a guarantee that no data has been read? And if data has been read, where did it go?

@sfackler
Copy link
Member

sfackler commented Jan 1, 2019

If the read fails with an error, is there a guarantee that no data has been read?

That is impossible to guarantee.

And if data has been read, where did it go?

It's in the head of the buffer you passed in.

@DevQps
Copy link
Contributor

DevQps commented Aug 9, 2019

@NickTime Do you still think this is necessary given that the documentation written by @frewsxcv has now landed in stable as well?

@jonas-schievink jonas-schievink added the T-libs-api Relevant to the library API team, which will review and decide on the PR/issue. label Mar 6, 2020
@n-epifanov
Copy link
Author

@DevQps sorry for terribly late reply (had a car crash). I haven't been using Rust and now I have no idea.

@frewsxcv
Copy link
Member

Closing unless there's something else actionable here

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-docs Area: Documentation for any part of the project, including the compiler, standard library, and tools C-enhancement Category: An issue proposing an enhancement or a PR with one. P-medium Medium priority T-libs-api Relevant to the library API team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

9 participants