Skip to content

Commit eaf7c41

Browse files
committed
Move Windows implementation of anon pipe
1 parent 5f49faa commit eaf7c41

File tree

2 files changed

+14
-20
lines changed

2 files changed

+14
-20
lines changed

library/std/src/sys/anonymous_pipe/windows.rs

+14-3
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,25 @@ use crate::os::windows::io::{
44
};
55
use crate::pipe::{PipeReader, PipeWriter};
66
use crate::process::Stdio;
7-
use crate::sys::{handle::Handle, pipe::unnamed_anon_pipe};
7+
use crate::sys::c;
8+
use crate::sys::handle::Handle;
89
use crate::sys_common::{FromInner, IntoInner};
910

11+
use core::ptr;
12+
1013
pub type AnonPipe = Handle;
1114

12-
#[inline]
1315
pub fn pipe() -> io::Result<(AnonPipe, AnonPipe)> {
14-
unnamed_anon_pipe().map(|(rx, wx)| (rx.into_inner(), wx.into_inner()))
16+
let mut read_pipe = c::INVALID_HANDLE_VALUE;
17+
let mut write_pipe = c::INVALID_HANDLE_VALUE;
18+
19+
let ret = unsafe { c::CreatePipe(&mut read_pipe, &mut write_pipe, ptr::null_mut(), 0) };
20+
21+
if ret == 0 {
22+
Err(io::Error::last_os_error())
23+
} else {
24+
unsafe { Ok((Handle::from_raw_handle(read_pipe), Handle::from_raw_handle(write_pipe))) }
25+
}
1526
}
1627

1728
#[unstable(feature = "anonymous_pipe", issue = "127154")]

library/std/src/sys/pal/windows/pipe.rs

-17
Original file line numberDiff line numberDiff line change
@@ -39,23 +39,6 @@ pub struct Pipes {
3939
pub theirs: AnonPipe,
4040
}
4141

42-
/// Create true unnamed anonymous pipe.
43-
pub fn unnamed_anon_pipe() -> io::Result<(AnonPipe, AnonPipe)> {
44-
let mut read_pipe = c::INVALID_HANDLE_VALUE;
45-
let mut write_pipe = c::INVALID_HANDLE_VALUE;
46-
47-
let ret = unsafe { c::CreatePipe(&mut read_pipe, &mut write_pipe, ptr::null_mut(), 0) };
48-
49-
if ret == 0 {
50-
Err(io::Error::last_os_error())
51-
} else {
52-
Ok((
53-
AnonPipe::from_inner(unsafe { Handle::from_raw_handle(read_pipe) }),
54-
AnonPipe::from_inner(unsafe { Handle::from_raw_handle(write_pipe) }),
55-
))
56-
}
57-
}
58-
5942
/// Although this looks similar to `anon_pipe` in the Unix module it's actually
6043
/// subtly different. Here we'll return two pipes in the `Pipes` return value,
6144
/// but one is intended for "us" where as the other is intended for "someone

0 commit comments

Comments
 (0)