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