Move Windows implementation of anon pipe

This commit is contained in:
Chris Denton 2024-07-24 22:22:09 +00:00
parent a75d2f9d38
commit 9169622027
No known key found for this signature in database
GPG Key ID: 713472F2F45627DE
2 changed files with 12 additions and 21 deletions

View File

@ -1,18 +1,26 @@
use crate::io;
use crate::os::windows::io::{
AsHandle, AsRawHandle, BorrowedHandle, FromRawHandle, IntoRawHandle, OwnedHandle, RawHandle,
};
use crate::pipe::{PipeReader, PipeWriter};
use crate::process::Stdio;
use crate::sys::c;
use crate::sys::handle::Handle;
use crate::sys::pipe::unnamed_anon_pipe;
use crate::sys_common::{FromInner, IntoInner};
use crate::{io, ptr};
pub type AnonPipe = Handle;
#[inline]
pub fn pipe() -> io::Result<(AnonPipe, AnonPipe)> {
unnamed_anon_pipe().map(|(rx, wx)| (rx.into_inner(), wx.into_inner()))
let mut read_pipe = c::INVALID_HANDLE_VALUE;
let mut write_pipe = c::INVALID_HANDLE_VALUE;
let ret = unsafe { c::CreatePipe(&mut read_pipe, &mut write_pipe, ptr::null_mut(), 0) };
if ret == 0 {
Err(io::Error::last_os_error())
} else {
unsafe { Ok((Handle::from_raw_handle(read_pipe), Handle::from_raw_handle(write_pipe))) }
}
}
#[unstable(feature = "anonymous_pipe", issue = "127154")]

View File

@ -36,23 +36,6 @@ pub struct Pipes {
pub theirs: AnonPipe,
}
/// Create true unnamed anonymous pipe.
pub fn unnamed_anon_pipe() -> io::Result<(AnonPipe, AnonPipe)> {
let mut read_pipe = c::INVALID_HANDLE_VALUE;
let mut write_pipe = c::INVALID_HANDLE_VALUE;
let ret = unsafe { c::CreatePipe(&mut read_pipe, &mut write_pipe, ptr::null_mut(), 0) };
if ret == 0 {
Err(io::Error::last_os_error())
} else {
Ok((
AnonPipe::from_inner(unsafe { Handle::from_raw_handle(read_pipe) }),
AnonPipe::from_inner(unsafe { Handle::from_raw_handle(write_pipe) }),
))
}
}
/// Although this looks similar to `anon_pipe` in the Unix module it's actually
/// subtly different. Here we'll return two pipes in the `Pipes` return value,
/// but one is intended for "us" where as the other is intended for "someone