mio/sys/unix/
mod.rs

1/// Helper macro to execute a system call that returns an `io::Result`.
2//
3// Macro must be defined before any modules that uses them.
4#[allow(unused_macros)]
5macro_rules! syscall {
6    ($fn: ident ( $($arg: expr),* $(,)* ) ) => {{
7        #[allow(unused_unsafe)]
8        let res = unsafe { libc::$fn($($arg, )*) };
9        if res < 0 {
10            Err(std::io::Error::last_os_error())
11        } else {
12            Ok(res)
13        }
14    }};
15}
16
17cfg_os_poll! {
18    #[cfg_attr(all(
19        not(mio_unsupported_force_poll_poll),
20        any(
21            target_os = "android",
22            target_os = "illumos",
23            target_os = "linux",
24            target_os = "redox",
25        )
26    ), path = "selector/epoll.rs")]
27    #[cfg_attr(all(
28        not(mio_unsupported_force_poll_poll),
29        any(
30            target_os = "dragonfly",
31            target_os = "freebsd",
32            target_os = "ios",
33            target_os = "macos",
34            target_os = "netbsd",
35            target_os = "openbsd",
36            target_os = "tvos",
37            target_os = "visionos",
38            target_os = "watchos",
39        )
40    ), path = "selector/kqueue.rs")]
41    #[cfg_attr(any(
42        mio_unsupported_force_poll_poll,
43        target_os = "espidf",
44        target_os = "fuchsia",
45        target_os = "haiku",
46        target_os = "hermit",
47        target_os = "hurd",
48        target_os = "nto",
49        target_os = "solaris",
50        target_os = "vita",
51    ), path = "selector/poll.rs")]
52    mod selector;
53    pub(crate) use self::selector::*;
54
55    #[cfg_attr(all(
56        not(mio_unsupported_force_waker_pipe),
57        any(
58            target_os = "android",
59            target_os = "espidf",
60            target_os = "fuchsia",
61            target_os = "hermit",
62            target_os = "illumos",
63            target_os = "linux",
64        )
65    ), path = "waker/eventfd.rs")]
66    #[cfg_attr(all(
67        not(mio_unsupported_force_waker_pipe),
68        not(mio_unsupported_force_poll_poll), // `kqueue(2)` based waker doesn't work with `poll(2)`.
69        any(
70            target_os = "freebsd",
71            target_os = "ios",
72            target_os = "macos",
73            target_os = "tvos",
74            target_os = "visionos",
75            target_os = "watchos",
76        )
77    ), path = "waker/kqueue.rs")]
78    #[cfg_attr(any(
79        // NOTE: also add to the list list for the `pipe` module below.
80        mio_unsupported_force_waker_pipe,
81        all(
82            // `kqueue(2)` based waker doesn't work with `poll(2)`.
83            mio_unsupported_force_poll_poll,
84            any(
85                target_os = "freebsd",
86                target_os = "ios",
87                target_os = "macos",
88                target_os = "tvos",
89                target_os = "visionos",
90                target_os = "watchos",
91            ),
92        ),
93        target_os = "aix",
94        target_os = "dragonfly",
95        target_os = "haiku",
96        target_os = "hurd",
97        target_os = "netbsd",
98        target_os = "nto",
99        target_os = "openbsd",
100        target_os = "redox",
101        target_os = "solaris",
102        target_os = "vita",
103    ), path = "waker/pipe.rs")]
104    mod waker;
105    // NOTE: the `Waker` type is expected in the selector module as the
106    // `poll(2)` implementation needs to do some special stuff.
107
108    mod sourcefd;
109    #[cfg(feature = "os-ext")]
110    pub use self::sourcefd::SourceFd;
111
112    cfg_net! {
113        mod net;
114
115        pub(crate) mod tcp;
116        pub(crate) mod udp;
117        #[cfg(not(target_os = "hermit"))]
118        pub(crate) mod uds;
119    }
120
121    #[cfg(all(
122        any(
123            // For the public `pipe` module, must match `cfg_os_ext` macro.
124            feature = "os-ext",
125            // For the `Waker` type based on a pipe.
126            mio_unsupported_force_waker_pipe,
127            all(
128                // `kqueue(2)` based waker doesn't work with `poll(2)`.
129                mio_unsupported_force_poll_poll,
130                any(
131                    target_os = "freebsd",
132                    target_os = "ios",
133                    target_os = "macos",
134                    target_os = "tvos",
135                    target_os = "visionos",
136                    target_os = "watchos",
137                ),
138            ),
139            // NOTE: also add to the list list for the `pipe` module below.
140            target_os = "aix",
141            target_os = "dragonfly",
142            target_os = "haiku",
143            target_os = "hurd",
144            target_os = "netbsd",
145            target_os = "nto",
146            target_os = "openbsd",
147            target_os = "redox",
148            target_os = "solaris",
149            target_os = "vita",
150        ),
151        // Hermit doesn't support pipes.
152        not(target_os = "hermit"),
153    ))]
154    pub(crate) mod pipe;
155}
156
157cfg_not_os_poll! {
158    cfg_any_os_ext! {
159        mod sourcefd;
160        #[cfg(feature = "os-ext")]
161        pub use self::sourcefd::SourceFd;
162    }
163}