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 pub use self::sourcefd::SourceFd;
22
23 mod waker;
24 pub(crate) use self::waker::Waker;
25
26 cfg_net! {
27 mod net;
28
29 pub(crate) mod tcp;
30 pub(crate) mod udp;
31 pub(crate) mod uds;
32 pub use self::uds::SocketAddr;
33 }
34
35 cfg_io_source! {
36 use std::io;
37
38 // Both `kqueue` and `epoll` don't need to hold any user space state.
39 pub(crate) struct IoSourceState;
40
41 impl IoSourceState {
42 pub fn new() -> IoSourceState {
43 IoSourceState
44 }
45
46 pub fn do_io<T, F, R>(&self, f: F, io: &T) -> io::Result<R>
47 where
48 F: FnOnce(&T) -> io::Result<R>,
49 {
50 // We don't hold state, so we can just call the function and
51 // return.
52 f(io)
53 }
54 }
55 }
56
57 cfg_os_ext! {
58 pub(crate) mod pipe;
59 }
60}
61
62cfg_not_os_poll! {
63 cfg_net! {
64 mod uds;
65 pub use self::uds::SocketAddr;
66 }
67
68 cfg_any_os_ext! {
69 mod sourcefd;
70 pub use self::sourcefd::SourceFd;
71 }
72}
73