rust-lang / rust-lang/libs-team

Setting a `File` non-blocking

Open
#842 10 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

ACP-accepted api-change-proposal
Dominant language
Rust
Stars
178
Forks
28
Avg merge
15m
Merged PRs (30d)
1

Description

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.

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the proposed std::os::unix::fs::OpenOptionsExt and FileExt APIs and read the linked feature lifecycle guidance. Review the non-blocking use case for /dev/kmsg and the documented limitations for ordinary files, devices, and pipes. This proposal is complete when the libs-api team decides whether the problem and API belong in the standard library; no implementation files or tests are named.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
operating-systems
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.