Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add windows NamedPipe #1351

Merged
merged 23 commits into from Oct 2, 2020
Merged
Show file tree
Hide file tree
Changes from 10 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions Cargo.toml
Expand Up @@ -49,6 +49,8 @@ ntapi = "0.3"
[dev-dependencies]
env_logger = { version = "0.6.2", default-features = false }
net2 = "0.2.33"
futures-test = "0.3"
rand = "0.4"

[package.metadata.docs.rs]
all-features = true
Expand Down
10 changes: 10 additions & 0 deletions src/lib.rs
Expand Up @@ -89,6 +89,16 @@ pub mod unix {
pub use crate::sys::SourceFd;
}

#[cfg(all(windows, feature = "os-util"))]
#[cfg_attr(docsrs, doc(cfg(all(windows, feature = "os-util"))))]
pub mod windows {
//! Windows only extensions.

cfg_os_poll! {
pub use crate::sys::named_pipe::NamedPipe;
}
}

// Enable with `cargo doc --features extra-docs`.
#[cfg(feature = "extra-docs")]
pub mod features {
Expand Down
2 changes: 1 addition & 1 deletion src/sys/mod.rs
Expand Up @@ -80,7 +80,7 @@ cfg_os_poll! {
#[cfg(windows)]
cfg_os_poll! {
mod windows;
pub(crate) use self::windows::*;
pub use self::windows::*;
}

cfg_not_os_poll! {
Expand Down
7 changes: 3 additions & 4 deletions src/sys/windows/afd.rs
Expand Up @@ -7,9 +7,7 @@ use std::io;
use std::mem::size_of;
use std::os::windows::io::AsRawHandle;
use std::ptr::null_mut;
use winapi::shared::ntdef::{
HANDLE, LARGE_INTEGER, NTSTATUS, PVOID, ULONG,
};
use winapi::shared::ntdef::{HANDLE, LARGE_INTEGER, NTSTATUS, PVOID, ULONG};
use winapi::shared::ntstatus::{STATUS_NOT_FOUND, STATUS_PENDING, STATUS_SUCCESS};

const IOCTL_AFD_POLL: ULONG = 0x00012024;
Expand Down Expand Up @@ -196,7 +194,8 @@ cfg_net! {
));
}
let fd = File::from_raw_handle(afd_helper_handle as RawHandle);
let token = NEXT_TOKEN.fetch_add(1, Ordering::Relaxed) + 1;
// Increment by 2 to reserve space for other types of handles
let token = NEXT_TOKEN.fetch_add(2, Ordering::Relaxed) + 2;
carllerche marked this conversation as resolved.
Show resolved Hide resolved
let afd = Afd { fd };
cp.add_handle(token, &afd.fd)?;
match SetFileCompletionNotificationModes(
Expand Down
6 changes: 6 additions & 0 deletions src/sys/windows/mod.rs
Expand Up @@ -7,6 +7,9 @@ pub use event::{Event, Events};
mod selector;
pub use selector::{Selector, SelectorInner, SockState};

mod overlapped;
use overlapped::Overlapped;

// Macros must be defined before the modules that use them
cfg_net! {
/// Helper macro to execute a system call that returns an `io::Result`.
Expand All @@ -32,6 +35,9 @@ cfg_udp! {
pub(crate) mod udp;
}

#[cfg(feature = "os-util")]
pub(crate) mod named_pipe;

mod waker;
pub(crate) use waker::Waker;

Expand Down