Fix support for a Windows client connection for IpcClient

This commit is contained in:
Emīls 2018-07-19 09:37:38 +01:00 committed by Emīls Piņķis
parent f483184917
commit b4c4cab666
2 changed files with 16 additions and 1 deletions

View File

@ -14,3 +14,6 @@ mio-named-pipes = { git = "https://github.com/alexcrichton/mio-named-pipes" }
miow = "0.2"
log = "*"
bytes = "0.4"
[target.'cfg(windows)'.dependencies]
winapi = { version = "0.3", features = ["winbase"] }

View File

@ -214,7 +214,19 @@ impl IpcStream {
#[cfg(windows)]
fn connect_inner(path: &Path, handle: &Handle) -> io::Result<NamedPipe> {
NamedPipe::new(&path, &handle)
use std::fs::OpenOptions;
use std::os::windows::fs::OpenOptionsExt;
use std::os::windows::io::{FromRawHandle, IntoRawHandle};
use winapi::um::winbase::FILE_FLAG_OVERLAPPED;
miow::pipe::NamedPipe::wait(path, None)?;
let mut options = OpenOptions::new();
options.read(true)
.write(true)
.custom_flags(FILE_FLAG_OVERLAPPED);
let file = options.open(path)?;
let mio_pipe = unsafe { mio_named_pipes::NamedPipe::from_raw_handle(file.into_raw_handle()) };
let pipe = NamedPipe::from_pipe(mio_pipe, &handle)?;
Ok(pipe)
}
}