Skip to content

Cleanup sys module to match house style #128162

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

Merged
merged 3 commits into from
Aug 1, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Move Windows implementation of anon pipe
  • Loading branch information
ChrisDenton committed Jul 30, 2024
commit 9169622027f1dcb702f789076da1b8b98c01a215
16 changes: 12 additions & 4 deletions library/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 library/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
Loading