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 extern crate socket2; 9 extern crate winapi; 10 11 #[cfg(test)] 12 extern crate rand; 13 14 use std::cmp; 15 use std::io; 16 use std::time::Duration; 17 18 use winapi::shared::minwindef::*; 19 use winapi::um::winbase::*; 20 21 #[cfg(test)] 22 macro_rules! t { 23 ($e:expr) => { 24 match $e { 25 Ok(e) => e, 26 Err(e) => panic!("{} failed with {:?}", stringify!($e), e), 27 } 28 }; 29 } 30 31 mod handle; 32 mod overlapped; 33 34 pub mod iocp; 35 pub mod net; 36 pub mod pipe; 37 38 pub use crate::overlapped::Overlapped; 39 cvt(i: BOOL) -> io::Result<BOOL>40fn cvt(i: BOOL) -> io::Result<BOOL> { 41 if i == 0 { 42 Err(io::Error::last_os_error()) 43 } else { 44 Ok(i) 45 } 46 } 47 dur2ms(dur: Option<Duration>) -> u3248fn dur2ms(dur: Option<Duration>) -> u32 { 49 let dur = match dur { 50 Some(dur) => dur, 51 None => return INFINITE, 52 }; 53 let ms = dur.as_secs().checked_mul(1_000); 54 let ms_extra = dur.subsec_nanos() / 1_000_000; 55 ms.and_then(|ms| ms.checked_add(ms_extra as u64)) 56 .map(|ms| cmp::min(u32::max_value() as u64, ms) as u32) 57 .unwrap_or(INFINITE - 1) 58 } 59