Skip to content

Commit 0f1032a

Browse files
authored
Implement the kqueue API (#488)
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
1 parent 01b4985 commit 0f1032a

File tree

3 files changed

+511
-0
lines changed

3 files changed

+511
-0
lines changed

src/backend/libc/io/syscalls.rs

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,18 @@ use core::ptr;
2727
#[cfg(all(feature = "fs", feature = "net"))]
2828
use libc_errno::errno;
2929

30+
#[cfg(any(
31+
target_os = "macos",
32+
target_os = "ios",
33+
target_os = "tvos",
34+
target_os = "watchos",
35+
target_os = "freebsd",
36+
target_os = "dragonfly",
37+
target_os = "openbsd",
38+
target_os = "netbsd"
39+
))]
40+
use crate::io::kqueue::Event;
41+
3042
pub(crate) fn read(fd: BorrowedFd<'_>, buf: &mut [u8]) -> io::Result<usize> {
3143
let nread = unsafe {
3244
ret_ssize_t(c::read(
@@ -450,6 +462,46 @@ pub(crate) fn ioctl_tiocnxcl(fd: BorrowedFd) -> io::Result<()> {
450462
unsafe { ret(c::ioctl(borrowed_fd(fd), c::TIOCNXCL as _)) }
451463
}
452464

465+
#[cfg(any(
466+
target_os = "macos",
467+
target_os = "ios",
468+
target_os = "tvos",
469+
target_os = "watchos",
470+
target_os = "freebsd",
471+
target_os = "dragonfly",
472+
target_os = "openbsd",
473+
target_os = "netbsd"
474+
))]
475+
pub(crate) fn kqueue() -> io::Result<OwnedFd> {
476+
unsafe { ret_owned_fd(c::kqueue()) }
477+
}
478+
479+
#[cfg(any(
480+
target_os = "macos",
481+
target_os = "ios",
482+
target_os = "tvos",
483+
target_os = "watchos",
484+
target_os = "freebsd",
485+
target_os = "dragonfly",
486+
target_os = "openbsd",
487+
target_os = "netbsd"
488+
))]
489+
pub(crate) unsafe fn kevent(
490+
kq: BorrowedFd<'_>,
491+
changelist: &[Event],
492+
eventlist: &mut [MaybeUninit<Event>],
493+
timeout: Option<&c::timespec>,
494+
) -> io::Result<c::c_int> {
495+
ret_c_int(c::kevent(
496+
borrowed_fd(kq),
497+
changelist.as_ptr() as *const _,
498+
changelist.len() as _,
499+
eventlist.as_mut_ptr() as *mut _,
500+
eventlist.len() as _,
501+
timeout.map_or(core::ptr::null(), |t| t as *const _),
502+
))
503+
}
504+
453505
#[cfg(not(target_os = "wasi"))]
454506
pub(crate) fn pipe() -> io::Result<(OwnedFd, OwnedFd)> {
455507
unsafe {

0 commit comments

Comments
 (0)