Skip to content

Commit

Permalink
feat: expose the inner fd of Kqueue (#2258)
Browse files Browse the repository at this point in the history
* feat: expose the inner fd of Kqueue

* changelog
  • Loading branch information
SteveLauC committed Jan 8, 2024
1 parent c505277 commit f55dee9
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
4 changes: 4 additions & 0 deletions changelog/2258.added.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Expose the inner fd of `Kqueue` through:

* impl AsFd for Kqueue
* impl From\<Kqueue\> for OwnedFd
13 changes: 13 additions & 0 deletions src/sys/event.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ use libc::{c_int, c_long, intptr_t, time_t, timespec, uintptr_t};
use libc::{c_long, intptr_t, size_t, time_t, timespec, uintptr_t};
use std::convert::TryInto;
use std::mem;
use std::os::fd::{AsFd, BorrowedFd};
use std::os::unix::io::{AsRawFd, FromRawFd, OwnedFd};
use std::ptr;

Expand All @@ -29,6 +30,18 @@ pub struct KEvent {
#[derive(Debug)]
pub struct Kqueue(OwnedFd);

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

impl From<Kqueue> for OwnedFd {
fn from(value: Kqueue) -> Self {
value.0
}
}

impl Kqueue {
/// Create a new kernel event queue.
pub fn new() -> Result<Self> {
Expand Down

0 comments on commit f55dee9

Please sign in to comment.