mod enums;
mod listener;
mod pipeops;
#[macro_use]
mod stream;
pub use enums::*;
pub use listener::*;
pub use stream::*;
#[cfg(any(doc, feature = "tokio_support"))]
#[cfg_attr(feature = "doc_cfg", doc(cfg(feature = "tokio_support")))]
#[cfg_attr(not(feature = "tokio_support"), allow(unused_imports))]
pub mod tokio;
use pipeops::*;
use {
super::imports::*,
std::{
ffi::{OsStr, OsString},
io, ptr,
},
};
fn convert_path(pipe_name: &OsStr, hostname: Option<&OsStr>) -> Vec<u16> {
static PREFIX_LITERAL: &str = r"\\";
static PIPEFS_LITERAL: &str = r"\pipe\";
let hostname = hostname.unwrap_or_else(|| OsStr::new("."));
let mut path = OsString::with_capacity(
PREFIX_LITERAL.len() + hostname.len() + PIPEFS_LITERAL.len() + pipe_name.len(),
);
path.push(PREFIX_LITERAL);
path.push(hostname);
path.push(PIPEFS_LITERAL);
path.push(pipe_name);
let mut path = path.encode_wide().collect::<Vec<u16>>();
path.push(0); path
}
#[cfg(windows)]
unsafe fn set_nonblocking_for_stream(
handle: HANDLE,
read_mode: Option<PipeMode>,
nonblocking: bool,
) -> io::Result<()> {
let read_mode: u32 = read_mode.map_or(0, PipeMode::to_readmode);
let mut mode: u32 = read_mode | nonblocking as u32;
let success = unsafe {
SetNamedPipeHandleState(
handle,
&mut mode as *mut _,
ptr::null_mut(),
ptr::null_mut(),
)
} != 0;
if success {
Ok(())
} else {
Err(io::Error::last_os_error())
}
}