Skip to main content

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