Proposal
Problem statement
While ordinary files don't typically have non-blocking support, File can also work for device files and similar (as well as other kinds of devices put into a File via File::from), and in this case, it can make sense to open them in non-blocking mode, or toggle them in and out of that mode.
I'd like to be able to do this without using a third-party crate like rustix to perform the open, and without having to use custom_flags (and define the target-specific constant for the flag).
Motivating examples or use cases
In a test program I'm writing, I'd like to open /dev/kmsg. That file needs to be opened in non-blocking mode if you want to detect the end of the current available messages, because it never produces EOF; it will block indefinitely waiting for more messages, or return EAGAIN if in non-blocking mode.
Solution sketch
// In std::os::unix::fs::OpenOptionsExt:
fn nonblocking(&mut self, nonblocking: bool) -> &mut Self;
// In std::os::unix::fs::FileExt:
pub fn set_nonblocking(&self, nonblocking: bool) -> Result<()>;
These should have appropriate documentation stating that they don't typically work on ordinary files the way people would expect, and primarily have use for things like devices, pipes, and similar.
What happens now?
This issue contains an API change proposal (or ACP) and is part of the libs-api team feature lifecycle. Once this issue is filed, the libs-api team will review open proposals as capability becomes available. Current response times do not have a clear estimate, but may be up to several months.
Possible responses
The libs team may respond in various different ways. First, the team will consider the problem (this doesn't require any concrete solution or alternatives to have been proposed):
- We think this problem seems worth solving, and the standard library might be the right place to solve it.
- We think that this probably doesn't belong in the standard library.
Second, if there's a concrete solution:
- We think this specific solution looks roughly right, approved, you or someone else should implement this. (Further review will still happen on the subsequent implementation PR.)
- We're not sure this is the right solution, and the alternatives or other materials don't give us enough information to be sure about that. Here are some questions we have that aren't answered, or rough ideas about alternatives we'd want to see discussed.
Proposal
Problem statement
While ordinary files don't typically have non-blocking support,
Filecan also work for device files and similar (as well as other kinds of devices put into aFileviaFile::from), and in this case, it can make sense to open them in non-blocking mode, or toggle them in and out of that mode.I'd like to be able to do this without using a third-party crate like rustix to perform the open, and without having to use
custom_flags(and define the target-specific constant for the flag).Motivating examples or use cases
In a test program I'm writing, I'd like to open
/dev/kmsg. That file needs to be opened in non-blocking mode if you want to detect the end of the current available messages, because it never produces EOF; it will block indefinitely waiting for more messages, or returnEAGAINif in non-blocking mode.Solution sketch
These should have appropriate documentation stating that they don't typically work on ordinary files the way people would expect, and primarily have use for things like devices, pipes, and similar.
What happens now?
This issue contains an API change proposal (or ACP) and is part of the libs-api team feature lifecycle. Once this issue is filed, the libs-api team will review open proposals as capability becomes available. Current response times do not have a clear estimate, but may be up to several months.
Possible responses
The libs team may respond in various different ways. First, the team will consider the problem (this doesn't require any concrete solution or alternatives to have been proposed):
Second, if there's a concrete solution: