summaryrefslogtreecommitdiffstats
path: root/third_party/rust/miow-0.2.1/src/lib.rs
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-28 14:29:10 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-28 14:29:10 +0000
commit2aa4a82499d4becd2284cdb482213d541b8804dd (patch)
treeb80bf8bf13c3766139fbacc530efd0dd9d54394c /third_party/rust/miow-0.2.1/src/lib.rs
parentInitial commit. (diff)
downloadfirefox-2aa4a82499d4becd2284cdb482213d541b8804dd.tar.xz
firefox-2aa4a82499d4becd2284cdb482213d541b8804dd.zip
Adding upstream version 86.0.1.upstream/86.0.1upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'third_party/rust/miow-0.2.1/src/lib.rs')
-rw-r--r--third_party/rust/miow-0.2.1/src/lib.rs57
1 files changed, 57 insertions, 0 deletions
diff --git a/third_party/rust/miow-0.2.1/src/lib.rs b/third_party/rust/miow-0.2.1/src/lib.rs
new file mode 100644
index 0000000000..58643ffae5
--- /dev/null
+++ b/third_party/rust/miow-0.2.1/src/lib.rs
@@ -0,0 +1,57 @@
+//! A zero overhead Windows I/O library
+
+#![cfg(windows)]
+#![deny(missing_docs)]
+#![allow(bad_style)]
+#![doc(html_root_url = "https://docs.rs/miow/0.1/x86_64-pc-windows-msvc/")]
+
+extern crate kernel32;
+extern crate net2;
+extern crate winapi;
+extern crate ws2_32;
+
+#[cfg(test)] extern crate rand;
+
+use std::cmp;
+use std::io;
+use std::time::Duration;
+
+use winapi::*;
+
+macro_rules! t {
+ ($e:expr) => (match $e {
+ Ok(e) => e,
+ Err(e) => panic!("{} failed with {:?}", stringify!($e), e),
+ })
+}
+
+mod handle;
+mod overlapped;
+
+pub mod iocp;
+pub mod net;
+pub mod pipe;
+
+pub use overlapped::Overlapped;
+
+fn cvt(i: BOOL) -> io::Result<BOOL> {
+ if i == 0 {
+ Err(io::Error::last_os_error())
+ } else {
+ Ok(i)
+ }
+}
+
+fn dur2ms(dur: Option<Duration>) -> u32 {
+ let dur = match dur {
+ Some(dur) => dur,
+ None => return INFINITE,
+ };
+ let ms = dur.as_secs().checked_mul(1_000);
+ let ms_extra = dur.subsec_nanos() / 1_000_000;
+ ms.and_then(|ms| {
+ ms.checked_add(ms_extra as u64)
+ }).map(|ms| {
+ cmp::min(u32::max_value() as u64, ms) as u32
+ }).unwrap_or(INFINITE - 1)
+}