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 let res = unsafe { libc::$fn($($arg, )*) };
8 if res == -1 {
9 Err(std::io::Error::last_os_error())
10 } else {
11 Ok(res)
12 }
13 }};
14}
15
16cfg_os_poll! {
17 mod selector;
18 pub(crate) use self::selector::{event, Event, Events, Selector};
19
20 mod sourcefd;
21 #[cfg(feature = "os-ext")]
22 pub use self::sourcefd::SourceFd;
23
24 mod waker;
25 pub(crate) use self::waker::Waker;
26
27 cfg_net! {
28 mod net;
29
30 pub(crate) mod tcp;
31 pub(crate) mod udp;
32 pub(crate) mod uds;
33 pub use self::uds::SocketAddr;
34 }
35
36 cfg_io_source! {
37 // Both `kqueue` and `epoll` don't need to hold any user space state.
38 #[cfg(not(any(mio_unsupported_force_poll_poll, target_os = "solaris", target_os = "vita")))]
39 mod stateless_io_source {
40 use std::io;
41 use std::os::unix::io::RawFd;
42 use crate::Registry;
43 use crate::Token;
44 use crate::Interest;
45
46 pub(crate) struct IoSourceState;
47
48 impl IoSourceState {
49 pub fn new() -> IoSourceState {
50 IoSourceState
51 }
52
53 pub fn do_io<T, F, R>(&self, f: F, io: &T) -> io::Result<R>
54 where
55 F: FnOnce(&T) -> io::Result<R>,
56 {
57 // We don't hold state, so we can just call the function and
58 // return.
59 f(io)
60 }
61
62 pub fn register(
63 &mut self,
64 registry: &Registry,
65 token: Token,
66 interests: Interest,
67 fd: RawFd,
68 ) -> io::Result<()> {
69 // Pass through, we don't have any state
70 registry.selector().register(fd, token, interests)
71 }
72
73 pub fn reregister(
74 &mut self,
75 registry: &Registry,
76 token: Token,
77 interests: Interest,
78 fd: RawFd,
79 ) -> io::Result<()> {
80 // Pass through, we don't have any state
81 registry.selector().reregister(fd, token, interests)
82 }
83
84 pub fn deregister(&mut self, registry: &Registry, fd: RawFd) -> io::Result<()> {
85 // Pass through, we don't have any state
86 registry.selector().deregister(fd)
87 }
88 }
89 }
90
91 #[cfg(not(any(mio_unsupported_force_poll_poll, target_os = "solaris",target_os = "vita")))]
92 pub(crate) use self::stateless_io_source::IoSourceState;
93
94 #[cfg(any(mio_unsupported_force_poll_poll, target_os = "solaris", target_os = "vita"))]
95 pub(crate) use self::selector::IoSourceState;
96 }
97
98 #[cfg(any(
99 // For the public `pipe` module, must match `cfg_os_ext` macro.
100 feature = "os-ext",
101 // For the `Waker` type based on a pipe.
102 mio_unsupported_force_waker_pipe,
103 target_os = "aix",
104 target_os = "dragonfly",
105 target_os = "illumos",
106 target_os = "netbsd",
107 target_os = "openbsd",
108 target_os = "redox",
109 target_os = "solaris",
110 target_os = "vita",
111 ))]
112 pub(crate) mod pipe;
113}
114
115cfg_not_os_poll! {
116 cfg_net! {
117 mod uds;
118 pub use self::uds::SocketAddr;
119 }
120
121 cfg_any_os_ext! {
122 mod sourcefd;
123 #[cfg(feature = "os-ext")]
124 pub use self::sourcefd::SourceFd;
125 }
126}
127

Provided by KDAB

Privacy Policy