@@ -5,7 +5,7 @@ use crate::io::prelude::*;
55use crate :: cell:: RefCell ;
66use crate :: fmt;
77use crate :: io:: lazy:: Lazy ;
8- use crate :: io:: { self , Initializer , BufReader , LineWriter } ;
8+ use crate :: io:: { self , Initializer , BufReader , LineWriter , IoVec , IoVecMut } ;
99use crate :: sync:: { Arc , Mutex , MutexGuard } ;
1010use crate :: sys:: stdio;
1111use crate :: sys_common:: remutex:: { ReentrantMutex , ReentrantMutexGuard } ;
@@ -75,17 +75,31 @@ fn stderr_raw() -> io::Result<StderrRaw> { stdio::Stderr::new().map(StderrRaw) }
7575impl Read for StdinRaw {
7676 fn read ( & mut self , buf : & mut [ u8 ] ) -> io:: Result < usize > { self . 0 . read ( buf) }
7777
78+ fn read_vectored ( & mut self , bufs : & mut [ IoVecMut < ' _ > ] ) -> io:: Result < usize > {
79+ self . 0 . read_vectored ( bufs)
80+ }
81+
7882 #[ inline]
7983 unsafe fn initializer ( & self ) -> Initializer {
8084 Initializer :: nop ( )
8185 }
8286}
8387impl Write for StdoutRaw {
8488 fn write ( & mut self , buf : & [ u8 ] ) -> io:: Result < usize > { self . 0 . write ( buf) }
89+
90+ fn write_vectored ( & mut self , bufs : & [ IoVec < ' _ > ] ) -> io:: Result < usize > {
91+ self . 0 . write_vectored ( bufs)
92+ }
93+
8594 fn flush ( & mut self ) -> io:: Result < ( ) > { self . 0 . flush ( ) }
8695}
8796impl Write for StderrRaw {
8897 fn write ( & mut self , buf : & [ u8 ] ) -> io:: Result < usize > { self . 0 . write ( buf) }
98+
99+ fn write_vectored ( & mut self , bufs : & [ IoVec < ' _ > ] ) -> io:: Result < usize > {
100+ self . 0 . write_vectored ( bufs)
101+ }
102+
89103 fn flush ( & mut self ) -> io:: Result < ( ) > { self . 0 . flush ( ) }
90104}
91105
@@ -102,6 +116,14 @@ impl<W: io::Write> io::Write for Maybe<W> {
102116 }
103117 }
104118
119+ fn write_vectored ( & mut self , bufs : & [ IoVec < ' _ > ] ) -> io:: Result < usize > {
120+ let total = bufs. iter ( ) . map ( |b| b. len ( ) ) . sum ( ) ;
121+ match self {
122+ Maybe :: Real ( w) => handle_ebadf ( w. write_vectored ( bufs) , total) ,
123+ Maybe :: Fake => Ok ( total) ,
124+ }
125+ }
126+
105127 fn flush ( & mut self ) -> io:: Result < ( ) > {
106128 match * self {
107129 Maybe :: Real ( ref mut w) => handle_ebadf ( w. flush ( ) , ( ) ) ,
@@ -117,6 +139,13 @@ impl<R: io::Read> io::Read for Maybe<R> {
117139 Maybe :: Fake => Ok ( 0 )
118140 }
119141 }
142+
143+ fn read_vectored ( & mut self , bufs : & mut [ IoVecMut < ' _ > ] ) -> io:: Result < usize > {
144+ match self {
145+ Maybe :: Real ( r) => handle_ebadf ( r. read_vectored ( bufs) , 0 ) ,
146+ Maybe :: Fake => Ok ( 0 )
147+ }
148+ }
120149}
121150
122151fn handle_ebadf < T > ( r : io:: Result < T > , default : T ) -> io:: Result < T > {
@@ -305,6 +334,9 @@ impl Read for Stdin {
305334 fn read ( & mut self , buf : & mut [ u8 ] ) -> io:: Result < usize > {
306335 self . lock ( ) . read ( buf)
307336 }
337+ fn read_vectored ( & mut self , bufs : & mut [ IoVecMut < ' _ > ] ) -> io:: Result < usize > {
338+ self . lock ( ) . read_vectored ( bufs)
339+ }
308340 #[ inline]
309341 unsafe fn initializer ( & self ) -> Initializer {
310342 Initializer :: nop ( )
@@ -325,6 +357,11 @@ impl Read for StdinLock<'_> {
325357 fn read ( & mut self , buf : & mut [ u8 ] ) -> io:: Result < usize > {
326358 self . inner . read ( buf)
327359 }
360+
361+ fn read_vectored ( & mut self , bufs : & mut [ IoVecMut < ' _ > ] ) -> io:: Result < usize > {
362+ self . inner . read_vectored ( bufs)
363+ }
364+
328365 #[ inline]
329366 unsafe fn initializer ( & self ) -> Initializer {
330367 Initializer :: nop ( )
@@ -483,6 +520,9 @@ impl Write for Stdout {
483520 fn write ( & mut self , buf : & [ u8 ] ) -> io:: Result < usize > {
484521 self . lock ( ) . write ( buf)
485522 }
523+ fn write_vectored ( & mut self , bufs : & [ IoVec < ' _ > ] ) -> io:: Result < usize > {
524+ self . lock ( ) . write_vectored ( bufs)
525+ }
486526 fn flush ( & mut self ) -> io:: Result < ( ) > {
487527 self . lock ( ) . flush ( )
488528 }
@@ -498,6 +538,9 @@ impl Write for StdoutLock<'_> {
498538 fn write ( & mut self , buf : & [ u8 ] ) -> io:: Result < usize > {
499539 self . inner . borrow_mut ( ) . write ( buf)
500540 }
541+ fn write_vectored ( & mut self , bufs : & [ IoVec < ' _ > ] ) -> io:: Result < usize > {
542+ self . inner . borrow_mut ( ) . write_vectored ( bufs)
543+ }
501544 fn flush ( & mut self ) -> io:: Result < ( ) > {
502545 self . inner . borrow_mut ( ) . flush ( )
503546 }
@@ -636,6 +679,9 @@ impl Write for Stderr {
636679 fn write ( & mut self , buf : & [ u8 ] ) -> io:: Result < usize > {
637680 self . lock ( ) . write ( buf)
638681 }
682+ fn write_vectored ( & mut self , bufs : & [ IoVec < ' _ > ] ) -> io:: Result < usize > {
683+ self . lock ( ) . write_vectored ( bufs)
684+ }
639685 fn flush ( & mut self ) -> io:: Result < ( ) > {
640686 self . lock ( ) . flush ( )
641687 }
@@ -651,6 +697,9 @@ impl Write for StderrLock<'_> {
651697 fn write ( & mut self , buf : & [ u8 ] ) -> io:: Result < usize > {
652698 self . inner . borrow_mut ( ) . write ( buf)
653699 }
700+ fn write_vectored ( & mut self , bufs : & [ IoVec < ' _ > ] ) -> io:: Result < usize > {
701+ self . inner . borrow_mut ( ) . write_vectored ( bufs)
702+ }
654703 fn flush ( & mut self ) -> io:: Result < ( ) > {
655704 self . inner . borrow_mut ( ) . flush ( )
656705 }
0 commit comments