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

device: Use OwnedFd type and bump MSRV to 1.66 #75

Open
wants to merge 2 commits into
base: next
Choose a base branch
from

Conversation

MarijnS95
Copy link
Collaborator

The first new commit 22a2365 on next switches to the RawFd type from the std::os::fd module which is only available since Rust 1.66. This module also provides an OwnedFd type which already has a close() call in the Drop implementation, and implements the desired AsRawFd (and AsFd and IntoRawFd) traits.

Note that these types were already stabilized in Rust 1.63 under std::os::unix::io, which is now merely a reexport of std::os::fd.

This also replaces the forgotten .fd() calls with .as_raw_fd() from from commit 17c2871.

Comment on lines -364 to +377
#[derive(Debug, Clone)]
pub struct Handle(RawFd);
#[derive(Debug)]
pub struct Handle(OwnedFd);
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This type always wrongly derived Clone, causing drop() close() the same fd multiple times...

Instead I'd argue this trait should be available on Device which holds on to an Arc<Handle> exactly to allow sharing of the fd without cloning it.

Additionally Handle could provide try_clone() to duplicate the file descriptor?


Also, Device currently has an fn handle() to clone this Arc<Handle> but thus far seems to mostly be used to distribute the Fd around. Hence:

  • Should we implement As(Raw)Fd for Device so that it's easier to borrow its (raw) file descriptor?
  • Should various implementations like io::Queue store a Device directly so that it's more obvious that it's not just a wrapper around OwnedFd but really a wrapper around a Device?

Comment on lines 380 to +383
/// Wraps an existing file descriptor
///
/// The caller must ensure that `fd` is a valid, open file descriptor for a V4L device.
pub unsafe fn new(fd: RawFd) -> Self {
pub fn new(fd: OwnedFd) -> Self {
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These docs, while still true, are a bit less relevant now (see also the removal of unsafe) because the caller already has to guarantee this when constructing an OwnedFd.

@MarijnS95
Copy link
Collaborator Author

@raymanfx should I target this to main? It looks like next currently isn't really in a ready state, as for example 384e7fb uses v4l2_sys unconditionally which fails the --no-default-features test. I assume next is your personal test ground rather than a branch you expect folks to send their contributions to?

@MarijnS95
Copy link
Collaborator Author

@raymanfx ping?

@raymanfx
Copy link
Owner

Hi guys, sorry for being MIA. I've been working on other projects and there's only so many hours in a day. I definately want to return to working on this crate and finish the overhaul of the I/O memory API.

@MarijnS95 as you have been involved for quite a bit now, what do you think about taking over maintainership of this crate temporarily? I'm still available for reviews, but don't feel like I can dedicate enough time to API changes / architecture right now.

@MarijnS95
Copy link
Collaborator Author

@raymanfx I figured you'd ask; same problems for me, there's only so much time in a day. And I'm not even using this crate yet, that's still on a soon™ project list somewhere™.

That said I do somehow have a sweet-spot for low-level (typically kernel/OS related) binding crates (ndk, ash, windows-rs, drm-rs, probably forgot a few more), all the way from expressive APIs to complete Rust'y documentation. I'd gladly be more involved!

On that note, there's still an unfinished Media API in one of my branches :)

The first new commit 22a2365 on `next` switches to the `RawFd` type from
the `std::os::fd` module which is only available since Rust 1.66.  This
module also provides an `OwnedFd` type which already has a `close()`
call in the `Drop` implementation, and implements the desired `AsRawFd`
(and `AsFd` and `IntoRawFd`) traits.

Note that these types were already stabilized in Rust 1.63 under
`std::os::unix::io`, which is now merely a reexport of `std::os::fd`.

This also replaces the forgotten `.fd()` calls with `.as_raw_fd()` from
from commit 17c2871.
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

Successfully merging this pull request may close these issues.

2 participants