Skip to content

Commit 9169622

Browse files
committed
Move Windows implementation of anon pipe
1 parent a75d2f9 commit 9169622

File tree

2 files changed

+12
-21
lines changed

2 files changed

+12
-21
lines changed

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

+12-4
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,26 @@
1-
use crate::io;
21
use crate::os::windows::io::{
32
AsHandle, AsRawHandle, BorrowedHandle, FromRawHandle, IntoRawHandle, OwnedHandle, RawHandle,
43
};
54
use crate::pipe::{PipeReader, PipeWriter};
65
use crate::process::Stdio;
6+
use crate::sys::c;
77
use crate::sys::handle::Handle;
8-
use crate::sys::pipe::unnamed_anon_pipe;
98
use crate::sys_common::{FromInner, IntoInner};
9+
use crate::{io, ptr};
1010

1111
pub type AnonPipe = Handle;
1212

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

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

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

-17
Original file line numberDiff line numberDiff line change
@@ -36,23 +36,6 @@ pub struct Pipes {
3636
pub theirs: AnonPipe,
3737
}
3838

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

0 commit comments

Comments
 (0)