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 = "aix",
44        target_os = "espidf",
45        target_os = "fuchsia",
46        target_os = "haiku",
47        target_os = "hermit",
48        target_os = "hurd",
49        target_os = "nto",
50        target_os = "solaris",
51        target_os = "vita",
52        target_os = "cygwin",
53    ), path = "selector/poll.rs")]
54    mod selector;
55    pub(crate) use self::selector::*;
56
57    #[cfg_attr(all(
58        not(mio_unsupported_force_waker_pipe),
59        any(
60            target_os = "android",
61            target_os = "espidf",
62            target_os = "fuchsia",
63            target_os = "hermit",
64            target_os = "illumos",
65            target_os = "linux",
66        )
67    ), path = "waker/eventfd.rs")]
68    #[cfg_attr(all(
69        not(mio_unsupported_force_waker_pipe),
70        not(mio_unsupported_force_poll_poll), // `kqueue(2)` based waker doesn't work with `poll(2)`.
71        any(
72            target_os = "freebsd",
73            target_os = "ios",
74            target_os = "macos",
75            target_os = "tvos",
76            target_os = "visionos",
77            target_os = "watchos",
78        )
79    ), path = "waker/kqueue.rs")]
80    #[cfg_attr(any(
81        // NOTE: also add to the list for the `pipe` module below.
82        mio_unsupported_force_waker_pipe,
83        all(
84            // `kqueue(2)` based waker doesn't work with `poll(2)`.
85            mio_unsupported_force_poll_poll,
86            any(
87                target_os = "freebsd",
88                target_os = "ios",
89                target_os = "macos",
90                target_os = "tvos",
91                target_os = "visionos",
92                target_os = "watchos",
93            ),
94        ),
95        target_os = "aix",
96        target_os = "dragonfly",
97        target_os = "haiku",
98        target_os = "hurd",
99        target_os = "netbsd",
100        target_os = "nto",
101        target_os = "openbsd",
102        target_os = "redox",
103        target_os = "solaris",
104        target_os = "vita",
105        target_os = "cygwin",
106    ), path = "waker/pipe.rs")]
107    mod waker;
108    // NOTE: the `Waker` type is expected in the selector module as the
109    // `poll(2)` implementation needs to do some special stuff.
110
111    #[cfg(feature = "os-ext")]
112    mod sourcefd;
113    #[cfg(feature = "os-ext")]
114    pub use self::sourcefd::SourceFd;
115
116    cfg_net! {
117        mod net;
118
119        pub(crate) mod tcp;
120        pub(crate) mod udp;
121        #[cfg(not(target_os = "hermit"))]
122        pub(crate) mod uds;
123    }
124
125    #[cfg(all(
126        any(
127            // For the public `pipe` module, must match `cfg_os_ext` macro.
128            feature = "os-ext",
129            // For the `Waker` type based on a pipe.
130            mio_unsupported_force_waker_pipe,
131            all(
132                // `kqueue(2)` based waker doesn't work with `poll(2)`.
133                mio_unsupported_force_poll_poll,
134                any(
135                    target_os = "freebsd",
136                    target_os = "ios",
137                    target_os = "macos",
138                    target_os = "tvos",
139                    target_os = "visionos",
140                    target_os = "watchos",
141                ),
142            ),
143            // NOTE: also add to the list for the `pipe` module below.
144            target_os = "aix",
145            target_os = "dragonfly",
146            target_os = "haiku",
147            target_os = "hurd",
148            target_os = "netbsd",
149            target_os = "nto",
150            target_os = "openbsd",
151            target_os = "redox",
152            target_os = "solaris",
153            target_os = "vita",
154            target_os = "cygwin",
155        ),
156        // Hermit doesn't support pipes.
157        not(target_os = "hermit"),
158    ))]
159    pub(crate) mod pipe;
160}
161
162cfg_not_os_poll! {
163    cfg_os_ext! {
164        mod sourcefd;
165        pub use self::sourcefd::SourceFd;
166    }
167}