diff --git a/tokio/src/runtime/io/driver.rs b/tokio/src/runtime/io/driver.rs index 0f7b1e57a..1dd93427f 100644 --- a/tokio/src/runtime/io/driver.rs +++ b/tokio/src/runtime/io/driver.rs @@ -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. diff --git a/tokio/src/runtime/runtime.rs b/tokio/src/runtime/runtime.rs index 16f8718ab..5ac7632d8 100644 --- a/tokio/src/runtime/runtime.rs +++ b/tokio/src/runtime/runtime.rs @@ -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 { + 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