Skip to main content

miow/
lib.rs

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