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