|
4 | 4 | use std::os::unix::io::BorrowedFd;
|
5 | 5 |
|
6 | 6 | /// Get a file descriptor that can be used to wait for readiness in an external runtime.
|
| 7 | +/// |
| 8 | +/// This file descriptor is equivalent to the one used by the underlying epoll/kqueue/event ports |
| 9 | +/// instance for polling. The intention is that this file descriptor can be registered into an |
| 10 | +/// external runtime (like [`calloop`] or GLib) so that `async-io` can be seamlessly polled |
| 11 | +/// alongside the other runtime. |
| 12 | +/// |
| 13 | +/// Not every backend used on `unix` has an associated file descriptor, however. While epoll, |
| 14 | +/// kqueue and event ports have a file descriptor as a backend, on some Unix systems `async-io` |
| 15 | +/// will use the `poll()` system call instead. Since there are no file descriptors intrinsically |
| 16 | +/// associated with `poll()`, this function will return `None`. |
| 17 | +/// |
| 18 | +/// There is presently no way to stop the "`async-io`" thread from being launched, so the reactor |
| 19 | +/// will still be continiously polled on that thread. This fact should be kept in mind by anyone |
| 20 | +/// looking to integrate `async-io` into another runtime using this function. |
| 21 | +/// |
| 22 | +/// It is possible to use this function to call raw system calls on the underlying event source. |
| 23 | +/// This is generally not recommended, since registered event sources may conflict with `async-io`'s |
| 24 | +/// existing scheme for managing sources. The behavior resulting from this is not specified, but |
| 25 | +/// will not result in undefined behavior. This could include panics, incorrect results, aborts, |
| 26 | +/// memory leaks, and non-termination. |
| 27 | +/// |
| 28 | +/// ## Example |
| 29 | +/// |
| 30 | +/// ``` |
| 31 | +/// #![cfg(unix)] |
| 32 | +/// |
| 33 | +/// use async_io::os::unix::reactor_fd; |
| 34 | +/// |
| 35 | +/// my_runtime::register(reactor_fd()); |
| 36 | +/// # mod my_runtime { |
| 37 | +/// # use std::os::unix::io::BorrowedFd; |
| 38 | +/// # fn register(_: BorrowedFd<'_>) {} |
| 39 | +/// # } |
| 40 | +/// ``` |
7 | 41 | #[cfg(not(async_io_no_io_safety))]
|
8 | 42 | pub fn reactor_fd() -> Option<BorrowedFd<'static>> {
|
9 | 43 | cfg_if::cfg_if! {
|
|
0 commit comments