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

FreeBSD nix::sys::event::Kqueue access to inner type #2183

Closed
eesekaj opened this issue Nov 9, 2023 · 4 comments · Fixed by #2258
Closed

FreeBSD nix::sys::event::Kqueue access to inner type #2183

eesekaj opened this issue Nov 9, 2023 · 4 comments · Fixed by #2258

Comments

@eesekaj
Copy link

eesekaj commented Nov 9, 2023

An important functionality is missing in 0.27 for Kqueue.

  1. "field 0 of Kqueue is private"
    There is no way it is possible to close the fd of the kqueue (OwnedFd should do it but in some cases it a raw fd is needed). as_raw_fd() is needed.
  2. An access to the inner type (a raw fd) is needed otherwise it breaks functionality of programs which depends on this functionality. Some programs uses fd number to identify the instance when there are multiple sources.

pub struct Kqueue(OwnedFd); pub struct Epoll(pub OwnedFd);
It would be great to have the same for KQueue.

@eesekaj eesekaj changed the title FreeBSD nix::sys::event::Kqueue missing Drop and access to inner type FreeBSD nix::sys::event::Kqueue access to inner type Nov 9, 2023
@SteveLauC
Copy link
Member

SteveLauC commented Nov 10, 2023

Kinda similar to #1998

Would implementing AsFd for Kqueue solve the problem for your use case?

impl std::os::fd::AsFd for Kqueue {
    fn as_fd(&self) -> BorrowedFd<'_> {
        self.0.as_fd()
    }
}

Some programs use fd number to identify the instance when there are multiple sources.

BorrowedFd itself is not PartialEq, but we can call as_raw_fd() on it to extract the inner RawFd


Maybe we should also do this to Epoll, cc @JonathanWoollett-Light

@asomers
Copy link
Member

asomers commented Nov 11, 2023

Why is there ever a problem for close? Are you trying to close the underlying file descriptor without dropping the struct? I don't know of any good reasons to do that.

@SteveLauC
Copy link
Member

I believe impl From<Kqueue> for OwnedFd would fix this issue, and why this? To be consistent with the std:

impl From<ChildStderr> for OwnedFd
impl From<ChildStdin> for OwnedFd
impl From<ChildStdout> for OwnedFd
impl From<File> for OwnedFd
impl From<PidFd> for OwnedFd
impl From<TcpListener> for OwnedFd

@eesekaj
Copy link
Author

eesekaj commented Dec 15, 2023

I was away for a while due to some problems.

The developers (including me) decided to stop using nix crate in our projects and use libc crate only, to avoid abstractions like libc -> nix -> own abstraction. Also taking into account that the some implementations in nix crate not what is required.

Thank you.

@eesekaj eesekaj closed this as completed Dec 15, 2023
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 a pull request may close this issue.

3 participants