]>
Commit | Line | Data |
---|---|---|
487cf647 FG |
1 | //! A zero overhead Windows I/O library |
2 | ||
3 | #![cfg(windows)] | |
4 | #![deny(missing_docs)] | |
5 | #![allow(bad_style)] | |
6 | #![doc(html_root_url = "https://docs.rs/miow/0.3/x86_64-pc-windows-msvc/")] | |
7 | ||
8 | use std::cmp; | |
9 | use std::io; | |
10 | use std::time::Duration; | |
11 | ||
12 | use windows_sys::Win32::Foundation::BOOL; | |
13 | use windows_sys::Win32::System::WindowsProgramming::INFINITE; | |
14 | ||
15 | #[cfg(test)] | |
16 | macro_rules! t { | |
17 | ($e:expr) => { | |
18 | match $e { | |
19 | Ok(e) => e, | |
20 | Err(e) => panic!("{} failed with {:?}", stringify!($e), e), | |
21 | } | |
22 | }; | |
23 | } | |
24 | ||
25 | mod handle; | |
26 | mod overlapped; | |
27 | ||
28 | pub mod iocp; | |
29 | pub mod net; | |
30 | pub mod pipe; | |
31 | ||
32 | pub use crate::overlapped::Overlapped; | |
33 | pub(crate) const TRUE: BOOL = 1; | |
34 | pub(crate) const FALSE: BOOL = 0; | |
35 | ||
36 | fn cvt(i: BOOL) -> io::Result<BOOL> { | |
37 | if i == 0 { | |
38 | Err(io::Error::last_os_error()) | |
39 | } else { | |
40 | Ok(i) | |
41 | } | |
42 | } | |
43 | ||
44 | fn dur2ms(dur: Option<Duration>) -> u32 { | |
45 | let dur = match dur { | |
46 | Some(dur) => dur, | |
47 | None => return INFINITE, | |
48 | }; | |
49 | let ms = dur.as_secs().checked_mul(1_000); | |
50 | let ms_extra = dur.subsec_nanos() / 1_000_000; | |
51 | ms.and_then(|ms| ms.checked_add(ms_extra as u64)) | |
52 | .map(|ms| cmp::min(u32::max_value() as u64, ms) as u32) | |
53 | .unwrap_or(INFINITE - 1) | |
54 | } |