Skip to content

Commit 3904535

Browse files
committed
Add a way to get the global poller's fd
1 parent a587acb commit 3904535

File tree

4 files changed

+40
-1
lines changed

4 files changed

+40
-1
lines changed

src/lib.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,8 @@ use crate::reactor::{Reactor, Source};
8888
mod driver;
8989
mod reactor;
9090

91+
pub mod os;
92+
9193
pub use driver::block_on;
9294
pub use reactor::{Readable, ReadableOwned, Writable, WritableOwned};
9395

src/os.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
//! Platform-specific functionality.
2+
3+
#[cfg(unix)]
4+
pub mod unix;

src/os/unix.rs

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
//! Functionality that is only available for `unix` platforms.
2+
3+
#[cfg(not(async_io_no_io_safety))]
4+
use std::os::unix::io::BorrowedFd;
5+
6+
/// Get a file descriptor that can be used to wait for readiness in an external runtime.
7+
#[cfg(not(async_io_no_io_safety))]
8+
pub fn reactor_fd() -> Option<BorrowedFd<'static>> {
9+
cfg_if::cfg_if! {
10+
if #[cfg(all(
11+
any(
12+
target_os = "linux",
13+
target_os = "android",
14+
target_os = "illumos",
15+
target_os = "solaris",
16+
target_os = "macos",
17+
target_os = "ios",
18+
target_os = "tvos",
19+
target_os = "watchos",
20+
target_os = "freebsd",
21+
target_os = "netbsd",
22+
target_os = "openbsd",
23+
target_os = "dragonfly",
24+
),
25+
not(polling_test_poll_backend),
26+
))] {
27+
use std::os::unix::io::AsFd;
28+
Some(crate::Reactor::get().poller.as_fd())
29+
} else {
30+
None
31+
}
32+
}
33+
}

src/reactor.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ pub(crate) struct Reactor {
3232
/// Portable bindings to epoll/kqueue/event ports/IOCP.
3333
///
3434
/// This is where I/O is polled, producing I/O events.
35-
poller: Poller,
35+
pub(crate) poller: Poller,
3636

3737
/// Ticker bumped before polling.
3838
///

0 commit comments

Comments
 (0)