Skip to content

Commit

Permalink
Implement the kqueue API (#488)
Browse files Browse the repository at this point in the history
Add an eventvec for kqueue

Remove vscode from gitignore

Replace kqueue with an arbitrary FD

Improve FilterKind ergonomics

Add references to functions

Make kevent unsafe with RawFd

Kickstart my heart!

Empty commit to re-run the CI
  • Loading branch information
notgull authored Mar 2, 2023
1 parent 01b4985 commit 0f1032a
Show file tree
Hide file tree
Showing 3 changed files with 511 additions and 0 deletions.
52 changes: 52 additions & 0 deletions src/backend/libc/io/syscalls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,18 @@ use core::ptr;
#[cfg(all(feature = "fs", feature = "net"))]
use libc_errno::errno;

#[cfg(any(
target_os = "macos",
target_os = "ios",
target_os = "tvos",
target_os = "watchos",
target_os = "freebsd",
target_os = "dragonfly",
target_os = "openbsd",
target_os = "netbsd"
))]
use crate::io::kqueue::Event;

pub(crate) fn read(fd: BorrowedFd<'_>, buf: &mut [u8]) -> io::Result<usize> {
let nread = unsafe {
ret_ssize_t(c::read(
Expand Down Expand Up @@ -450,6 +462,46 @@ pub(crate) fn ioctl_tiocnxcl(fd: BorrowedFd) -> io::Result<()> {
unsafe { ret(c::ioctl(borrowed_fd(fd), c::TIOCNXCL as _)) }
}

#[cfg(any(
target_os = "macos",
target_os = "ios",
target_os = "tvos",
target_os = "watchos",
target_os = "freebsd",
target_os = "dragonfly",
target_os = "openbsd",
target_os = "netbsd"
))]
pub(crate) fn kqueue() -> io::Result<OwnedFd> {
unsafe { ret_owned_fd(c::kqueue()) }
}

#[cfg(any(
target_os = "macos",
target_os = "ios",
target_os = "tvos",
target_os = "watchos",
target_os = "freebsd",
target_os = "dragonfly",
target_os = "openbsd",
target_os = "netbsd"
))]
pub(crate) unsafe fn kevent(
kq: BorrowedFd<'_>,
changelist: &[Event],
eventlist: &mut [MaybeUninit<Event>],
timeout: Option<&c::timespec>,
) -> io::Result<c::c_int> {
ret_c_int(c::kevent(
borrowed_fd(kq),
changelist.as_ptr() as *const _,
changelist.len() as _,
eventlist.as_mut_ptr() as *mut _,
eventlist.len() as _,
timeout.map_or(core::ptr::null(), |t| t as *const _),
))
}

#[cfg(not(target_os = "wasi"))]
pub(crate) fn pipe() -> io::Result<(OwnedFd, OwnedFd)> {
unsafe {
Expand Down
Loading

0 comments on commit 0f1032a

Please sign in to comment.