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

Nonblocking I/O #12353

Closed
alexcrichton opened this issue Feb 17, 2014 · 5 comments
Closed

Nonblocking I/O #12353

alexcrichton opened this issue Feb 17, 2014 · 5 comments

Comments

@alexcrichton
Copy link
Member

A frequently requested feature of I/O I've been seeing is some form of nonblocking I/O. This is a vast and broad topic, but I would like to make this concrete proposal:

fn set_nonblocking(&mut self, nonblocking: bool) -> IoResult<()>;

The IoErrorKind enum would also be extended with a value of WouldBlock. This method would be added to only the network streams initially and possibly others as later seen fit.

For libnative, this would do the ioctl thing or whatever the equivalent is to set the file descriptor into nonblocking mode (can this be done on windows?). For librustuv, this could be a little more difficult. To the best of my knowledge libuv doesn't support a nonblocking read. One possible solution would be to schedule a read and then use an idle callback to cancel the read on the next turn of the event loop. This would technically block the task, but it would be for "a short period of time"

Those who desire a form of nonblocking I/O, would this satisfy your needs?

@sfackler
Copy link
Member

This would work for me. This would only affect the result of reads, not writes, correct? The librustuv issue is a bit unfortunate but as long as the event loop is quick, not the end of the world.

@alexcrichton
Copy link
Member Author

Hm, nonblocking writes is indeed a large problem. I don't know of a way to do a nonblocking write with libuv.

@bnoordhuis
Copy link
Contributor

It's not currently possible but it could be made to work if uv_cancel() was taught to cancel uv_write_t requests. Fairly trivial on Unices, maybe less so on Windows.

@bnoordhuis
Copy link
Contributor

Forgot to mention, libuv grew a uv_try_write() function in v0.11.16 but it's currently only implemented on Unices. I don't know how difficult it would be to make it work on Windows.

@alexcrichton
Copy link
Member Author

Closing in favor of #13336

flip1995 pushed a commit to flip1995/rust that referenced this issue Feb 26, 2024
add cargo.toml lint section way of adding lints in the book

changelog: add cargo.toml lint section way of adding lints in the book

as from [discussion on zulip](https://rust-lang.zulipchat.com/#narrow/stream/257328-clippy/topic/.E2.9C.94.20clippy.20config)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants