-
Notifications
You must be signed in to change notification settings - Fork 352
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Move Event and Overlapped to talpid-windows crate
- Loading branch information
Showing
9 changed files
with
191 additions
and
112 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
[package] | ||
name = "talpid-windows" | ||
description = "Nice abstractions for Windows" | ||
version.workspace = true | ||
authors.workspace = true | ||
repository.workspace = true | ||
license.workspace = true | ||
edition.workspace = true | ||
publish.workspace = true | ||
|
||
[target.'cfg(windows)'.dependencies.windows-sys] | ||
workspace = true | ||
features = [ | ||
"Win32_Foundation", | ||
"Win32_Globalization", | ||
"Win32_System_Com", | ||
"Win32_System_IO", | ||
"Win32_Networking_WinSock", | ||
"Win32_NetworkManagement_IpHelper", | ||
"Win32_NetworkManagement_Ndis", | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
use std::{io, mem}; | ||
use windows_sys::Win32::System::IO::OVERLAPPED; | ||
|
||
use crate::sync::Event; | ||
|
||
/// Abstraction over `OVERLAPPED`. | ||
pub struct Overlapped { | ||
overlapped: OVERLAPPED, | ||
event: Option<Event>, | ||
} | ||
|
||
unsafe impl Send for Overlapped {} | ||
unsafe impl Sync for Overlapped {} | ||
|
||
impl Overlapped { | ||
/// Creates an `OVERLAPPED` object with `hEvent` set. | ||
pub fn new(event: Option<Event>) -> io::Result<Self> { | ||
let mut overlapped = Overlapped { | ||
overlapped: unsafe { mem::zeroed() }, | ||
event: None, | ||
}; | ||
overlapped.set_event(event); | ||
Ok(overlapped) | ||
} | ||
|
||
/// Borrows the underlying `OVERLAPPED` object. | ||
pub fn as_mut_ptr(&mut self) -> *mut OVERLAPPED { | ||
&mut self.overlapped | ||
} | ||
|
||
/// Returns a reference to the associated event. | ||
pub fn get_event(&self) -> Option<&Event> { | ||
self.event.as_ref() | ||
} | ||
|
||
/// Sets the event object for the underlying `OVERLAPPED` object (i.e., `hEvent`) | ||
fn set_event(&mut self, event: Option<Event>) { | ||
match event { | ||
Some(event) => { | ||
self.overlapped.hEvent = event.as_raw(); | ||
self.event = Some(event); | ||
} | ||
None => { | ||
self.overlapped.hEvent = 0; | ||
self.event = None; | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
//! Interface with low-level windows specific bits. | ||
#![deny(missing_docs)] | ||
#![deny(rust_2018_idioms)] | ||
|
||
/// Windows I/O | ||
#[cfg(windows)] | ||
pub mod io; | ||
|
||
/// Synchronization (event objects, etc.) | ||
#[cfg(windows)] | ||
pub mod sync; |
Oops, something went wrong.