summaryrefslogtreecommitdiffstats
path: root/library/std/src/sys/windows/pipe.rs
diff options
context:
space:
mode:
Diffstat (limited to 'library/std/src/sys/windows/pipe.rs')
-rw-r--r--library/std/src/sys/windows/pipe.rs24
1 files changed, 23 insertions, 1 deletions
diff --git a/library/std/src/sys/windows/pipe.rs b/library/std/src/sys/windows/pipe.rs
index 7b25edaa5..0780b2958 100644
--- a/library/std/src/sys/windows/pipe.rs
+++ b/library/std/src/sys/windows/pipe.rs
@@ -1,7 +1,7 @@
use crate::os::windows::prelude::*;
use crate::ffi::OsStr;
-use crate::io::{self, IoSlice, IoSliceMut, Read};
+use crate::io::{self, BorrowedCursor, IoSlice, IoSliceMut, Read};
use crate::mem;
use crate::path::Path;
use crate::ptr;
@@ -252,6 +252,28 @@ impl AnonPipe {
}
}
+ pub fn read_buf(&self, mut buf: BorrowedCursor<'_>) -> io::Result<()> {
+ let result = unsafe {
+ let len = crate::cmp::min(buf.capacity(), c::DWORD::MAX as usize) as c::DWORD;
+ self.alertable_io_internal(c::ReadFileEx, buf.as_mut().as_mut_ptr() as _, len)
+ };
+
+ match result {
+ // The special treatment of BrokenPipe is to deal with Windows
+ // pipe semantics, which yields this error when *reading* from
+ // a pipe after the other end has closed; we interpret that as
+ // EOF on the pipe.
+ Err(ref e) if e.kind() == io::ErrorKind::BrokenPipe => Ok(()),
+ Err(e) => Err(e),
+ Ok(n) => {
+ unsafe {
+ buf.advance(n);
+ }
+ Ok(())
+ }
+ }
+ }
+
pub fn read_vectored(&self, bufs: &mut [IoSliceMut<'_>]) -> io::Result<usize> {
self.inner.read_vectored(bufs)
}