1 //! Module with system specific types.
2 //!
3 //! Required types:
4 //!
5 //! * `Event`: a type alias for the system specific event, e.g. `kevent` or
6 //!            `epoll_event`.
7 //! * `event`: a module with various helper functions for `Event`, see
8 //!            [`crate::event::Event`] for the required functions.
9 //! * `Events`: collection of `Event`s, see [`crate::Events`].
10 //! * `IoSourceState`: state for the `IoSource` type.
11 //! * `Selector`: selector used to register event sources and poll for events,
12 //!               see [`crate::Poll`] and [`crate::Registry`] for required
13 //!               methods.
14 //! * `tcp` and `udp` modules: see the [`crate::net`] module.
15 //! * `Waker`: see [`crate::Waker`].
16 
17 cfg_os_poll! {
18     macro_rules! debug_detail {
19         (
20             $type: ident ($event_type: ty), $test: path,
21             $($(#[$target: meta])* $libc: ident :: $flag: ident),+ $(,)*
22         ) => {
23             struct $type($event_type);
24 
25             impl fmt::Debug for $type {
26                 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
27                     let mut written_one = false;
28                     $(
29                         $(#[$target])*
30                         #[allow(clippy::bad_bit_mask)] // Apparently some flags are zero.
31                         {
32                             // Windows doesn't use `libc` but the `afd` module.
33                             if $test(&self.0, &$libc :: $flag) {
34                                 if !written_one {
35                                     write!(f, "{}", stringify!($flag))?;
36                                     written_one = true;
37                                 } else {
38                                     write!(f, "|{}", stringify!($flag))?;
39                                 }
40                             }
41                         }
42                     )+
43                     if !written_one {
44                         write!(f, "(empty)")
45                     } else {
46                         Ok(())
47                     }
48                 }
49             }
50         };
51     }
52 }
53 
54 #[cfg(unix)]
55 cfg_os_poll! {
56     mod unix;
57     pub use self::unix::SourceFd;
58 
59     pub(crate) use self::unix::{event, Event, Events, Selector, Waker};
60 
61     cfg_tcp! {
62         pub(crate) use self::unix::tcp;
63     }
64 
65     cfg_udp! {
66         pub(crate) use self::unix::udp;
67     }
68 
69     cfg_uds! {
70         pub use self::unix::SocketAddr;
71 
72         pub(crate) use self::unix::uds;
73     }
74 
75     cfg_net! {
76         pub(crate) use self::unix::IoSourceState;
77     }
78 }
79 
80 #[cfg(windows)]
81 cfg_os_poll! {
82     mod windows;
83     pub(crate) use self::windows::*;
84 }
85 
86 cfg_not_os_poll! {
87     mod shell;
88     pub(crate) use self::shell::*;
89 
90     #[cfg(unix)]
91     cfg_any_os_util! {
92         mod unix;
93         pub use self::unix::SourceFd;
94     }
95 
96     #[cfg(unix)]
97     cfg_uds! {
98         pub use self::unix::SocketAddr;
99     }
100 }
101