| 1 | macro_rules! os_required { |
| 2 | () => { |
| 3 | panic!("mio must be compiled with `os-poll` to run." ) |
| 4 | }; |
| 5 | } |
| 6 | |
| 7 | mod selector; |
| 8 | pub(crate) use self::selector::{event, Event, Events, Selector}; |
| 9 | |
| 10 | #[cfg (not(target_os = "wasi" ))] |
| 11 | mod waker; |
| 12 | #[cfg (not(target_os = "wasi" ))] |
| 13 | pub(crate) use self::waker::Waker; |
| 14 | |
| 15 | cfg_net! { |
| 16 | pub(crate) mod tcp; |
| 17 | pub(crate) mod udp; |
| 18 | #[cfg (unix)] |
| 19 | pub(crate) mod uds; |
| 20 | } |
| 21 | |
| 22 | cfg_io_source! { |
| 23 | use std::io; |
| 24 | #[cfg (windows)] |
| 25 | use std::os::windows::io::RawSocket; |
| 26 | #[cfg (unix)] |
| 27 | use std::os::unix::io::RawFd; |
| 28 | |
| 29 | #[cfg (any(windows, unix))] |
| 30 | use crate::{Registry, Token, Interest}; |
| 31 | |
| 32 | pub(crate) struct IoSourceState; |
| 33 | |
| 34 | impl IoSourceState { |
| 35 | pub fn new() -> IoSourceState { |
| 36 | IoSourceState |
| 37 | } |
| 38 | |
| 39 | pub fn do_io<T, F, R>(&self, f: F, io: &T) -> io::Result<R> |
| 40 | where |
| 41 | F: FnOnce(&T) -> io::Result<R>, |
| 42 | { |
| 43 | // We don't hold state, so we can just call the function and |
| 44 | // return. |
| 45 | f(io) |
| 46 | } |
| 47 | } |
| 48 | |
| 49 | #[cfg (unix)] |
| 50 | impl IoSourceState { |
| 51 | pub fn register( |
| 52 | &mut self, |
| 53 | _: &Registry, |
| 54 | _: Token, |
| 55 | _: Interest, |
| 56 | _: RawFd, |
| 57 | ) -> io::Result<()> { |
| 58 | os_required!() |
| 59 | } |
| 60 | |
| 61 | pub fn reregister( |
| 62 | &mut self, |
| 63 | _: &Registry, |
| 64 | _: Token, |
| 65 | _: Interest, |
| 66 | _: RawFd, |
| 67 | ) -> io::Result<()> { |
| 68 | os_required!() |
| 69 | } |
| 70 | |
| 71 | pub fn deregister(&mut self, _: &Registry, _: RawFd) -> io::Result<()> { |
| 72 | os_required!() |
| 73 | } |
| 74 | } |
| 75 | |
| 76 | #[cfg (windows)] |
| 77 | impl IoSourceState { |
| 78 | pub fn register( |
| 79 | &mut self, |
| 80 | _: &Registry, |
| 81 | _: Token, |
| 82 | _: Interest, |
| 83 | _: RawSocket, |
| 84 | ) -> io::Result<()> { |
| 85 | os_required!() |
| 86 | } |
| 87 | |
| 88 | pub fn reregister( |
| 89 | &mut self, |
| 90 | _: &Registry, |
| 91 | _: Token, |
| 92 | _: Interest, |
| 93 | ) -> io::Result<()> { |
| 94 | os_required!() |
| 95 | } |
| 96 | |
| 97 | pub fn deregister(&mut self) -> io::Result<()> { |
| 98 | os_required!() |
| 99 | } |
| 100 | } |
| 101 | } |
| 102 | |