rt: expose io driver fd

This change exposes the IO driver fd, used by our epoll, kqueue, uring, etc instance.

This is exposed so that users can watch it from another epoll/kqueue/io_uring/poll setup, and for no other reason. It is not valid to do anything other than watch this for readiness.
This commit is contained in:
Noah Kennedy 2024-08-28 10:41:29 +01:00
parent 365269adaf
commit 3fb29e3c92
2 changed files with 17 additions and 0 deletions

View File

@ -13,6 +13,7 @@ use crate::runtime::io::{IoDriverMetrics, RegistrationSet, ScheduledIo};
use mio::event::Source;
use std::fmt;
use std::io;
use std::os::fd::AsRawFd;
use std::sync::Arc;
use std::time::Duration;
@ -209,6 +210,11 @@ impl Handle {
self.waker.wake().expect("failed to wake I/O driver");
}
#[cfg(unix)]
pub(crate) fn get_raw_poll_fd(&self) -> std::os::fd::RawFd {
self.registry.as_raw_fd()
}
/// Registers an I/O resource with the reactor for a given `mio::Ready` state.
///
/// The registration token is returned.

View File

@ -475,6 +475,17 @@ impl Runtime {
pub fn metrics(&self) -> crate::runtime::RuntimeMetrics {
self.handle.metrics()
}
/// Gets a raw fd for the IO driver which can be polled.
///
/// Do NOT use this for anything other than watching it with epoll/kqueue/poll.
///
/// # Safety
/// Don't use this after the runtime goes away.
#[cfg(unix)]
pub unsafe fn get_raw_poll_fd(&self) -> Option<std::os::fd::RawFd> {
Some(self.handle.inner.driver().io.as_ref()?.get_raw_poll_fd())
}
}
#[allow(clippy::single_match)] // there are comments in the error branch, so we don't want if-let