Skip to content

Commit

Permalink
Move Windows implementation of anon pipe
Browse files Browse the repository at this point in the history
  • Loading branch information
ChrisDenton committed Jul 30, 2024
1 parent 85e4ba0 commit ba65c6c
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 21 deletions.
16 changes: 12 additions & 4 deletions std/src/sys/anonymous_pipe/windows.rs
Original file line number Diff line number Diff line change
@@ -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")]
Expand Down
17 changes: 0 additions & 17 deletions std/src/sys/pal/windows/pipe.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit ba65c6c

Please sign in to comment.