]> git.proxmox.com Git - rustc.git/blame - vendor/miow/src/lib.rs
New upstream version 1.67.1+dfsg1
[rustc.git] / vendor / miow / src / lib.rs
CommitLineData
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
8use std::cmp;
9use std::io;
10use std::time::Duration;
11
12use windows_sys::Win32::Foundation::BOOL;
13use windows_sys::Win32::System::WindowsProgramming::INFINITE;
14
15#[cfg(test)]
16macro_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
25mod handle;
26mod overlapped;
27
28pub mod iocp;
29pub mod net;
30pub mod pipe;
31
32pub use crate::overlapped::Overlapped;
33pub(crate) const TRUE: BOOL = 1;
34pub(crate) const FALSE: BOOL = 0;
35
36fn 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
44fn 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}