@@ -5,7 +5,7 @@ use crate::io::prelude::*;
5
5
use crate :: cell:: RefCell ;
6
6
use crate :: fmt;
7
7
use crate :: io:: lazy:: Lazy ;
8
- use crate :: io:: { self , Initializer , BufReader , LineWriter } ;
8
+ use crate :: io:: { self , Initializer , BufReader , LineWriter , IoVec , IoVecMut } ;
9
9
use crate :: sync:: { Arc , Mutex , MutexGuard } ;
10
10
use crate :: sys:: stdio;
11
11
use crate :: sys_common:: remutex:: { ReentrantMutex , ReentrantMutexGuard } ;
@@ -75,17 +75,31 @@ fn stderr_raw() -> io::Result<StderrRaw> { stdio::Stderr::new().map(StderrRaw) }
75
75
impl Read for StdinRaw {
76
76
fn read ( & mut self , buf : & mut [ u8 ] ) -> io:: Result < usize > { self . 0 . read ( buf) }
77
77
78
+ fn read_vectored ( & mut self , bufs : & mut [ IoVecMut < ' _ > ] ) -> io:: Result < usize > {
79
+ self . 0 . read_vectored ( bufs)
80
+ }
81
+
78
82
#[ inline]
79
83
unsafe fn initializer ( & self ) -> Initializer {
80
84
Initializer :: nop ( )
81
85
}
82
86
}
83
87
impl Write for StdoutRaw {
84
88
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
+
85
94
fn flush ( & mut self ) -> io:: Result < ( ) > { self . 0 . flush ( ) }
86
95
}
87
96
impl Write for StderrRaw {
88
97
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
+
89
103
fn flush ( & mut self ) -> io:: Result < ( ) > { self . 0 . flush ( ) }
90
104
}
91
105
@@ -102,6 +116,14 @@ impl<W: io::Write> io::Write for Maybe<W> {
102
116
}
103
117
}
104
118
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
+
105
127
fn flush ( & mut self ) -> io:: Result < ( ) > {
106
128
match * self {
107
129
Maybe :: Real ( ref mut w) => handle_ebadf ( w. flush ( ) , ( ) ) ,
@@ -117,6 +139,13 @@ impl<R: io::Read> io::Read for Maybe<R> {
117
139
Maybe :: Fake => Ok ( 0 )
118
140
}
119
141
}
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
+ }
120
149
}
121
150
122
151
fn handle_ebadf < T > ( r : io:: Result < T > , default : T ) -> io:: Result < T > {
@@ -305,6 +334,9 @@ impl Read for Stdin {
305
334
fn read ( & mut self , buf : & mut [ u8 ] ) -> io:: Result < usize > {
306
335
self . lock ( ) . read ( buf)
307
336
}
337
+ fn read_vectored ( & mut self , bufs : & mut [ IoVecMut < ' _ > ] ) -> io:: Result < usize > {
338
+ self . lock ( ) . read_vectored ( bufs)
339
+ }
308
340
#[ inline]
309
341
unsafe fn initializer ( & self ) -> Initializer {
310
342
Initializer :: nop ( )
@@ -325,6 +357,11 @@ impl Read for StdinLock<'_> {
325
357
fn read ( & mut self , buf : & mut [ u8 ] ) -> io:: Result < usize > {
326
358
self . inner . read ( buf)
327
359
}
360
+
361
+ fn read_vectored ( & mut self , bufs : & mut [ IoVecMut < ' _ > ] ) -> io:: Result < usize > {
362
+ self . inner . read_vectored ( bufs)
363
+ }
364
+
328
365
#[ inline]
329
366
unsafe fn initializer ( & self ) -> Initializer {
330
367
Initializer :: nop ( )
@@ -483,6 +520,9 @@ impl Write for Stdout {
483
520
fn write ( & mut self , buf : & [ u8 ] ) -> io:: Result < usize > {
484
521
self . lock ( ) . write ( buf)
485
522
}
523
+ fn write_vectored ( & mut self , bufs : & [ IoVec < ' _ > ] ) -> io:: Result < usize > {
524
+ self . lock ( ) . write_vectored ( bufs)
525
+ }
486
526
fn flush ( & mut self ) -> io:: Result < ( ) > {
487
527
self . lock ( ) . flush ( )
488
528
}
@@ -498,6 +538,9 @@ impl Write for StdoutLock<'_> {
498
538
fn write ( & mut self , buf : & [ u8 ] ) -> io:: Result < usize > {
499
539
self . inner . borrow_mut ( ) . write ( buf)
500
540
}
541
+ fn write_vectored ( & mut self , bufs : & [ IoVec < ' _ > ] ) -> io:: Result < usize > {
542
+ self . inner . borrow_mut ( ) . write_vectored ( bufs)
543
+ }
501
544
fn flush ( & mut self ) -> io:: Result < ( ) > {
502
545
self . inner . borrow_mut ( ) . flush ( )
503
546
}
@@ -636,6 +679,9 @@ impl Write for Stderr {
636
679
fn write ( & mut self , buf : & [ u8 ] ) -> io:: Result < usize > {
637
680
self . lock ( ) . write ( buf)
638
681
}
682
+ fn write_vectored ( & mut self , bufs : & [ IoVec < ' _ > ] ) -> io:: Result < usize > {
683
+ self . lock ( ) . write_vectored ( bufs)
684
+ }
639
685
fn flush ( & mut self ) -> io:: Result < ( ) > {
640
686
self . lock ( ) . flush ( )
641
687
}
@@ -651,6 +697,9 @@ impl Write for StderrLock<'_> {
651
697
fn write ( & mut self , buf : & [ u8 ] ) -> io:: Result < usize > {
652
698
self . inner . borrow_mut ( ) . write ( buf)
653
699
}
700
+ fn write_vectored ( & mut self , bufs : & [ IoVec < ' _ > ] ) -> io:: Result < usize > {
701
+ self . inner . borrow_mut ( ) . write_vectored ( bufs)
702
+ }
654
703
fn flush ( & mut self ) -> io:: Result < ( ) > {
655
704
self . inner . borrow_mut ( ) . flush ( )
656
705
}
0 commit comments