@@ -139,12 +139,13 @@ where
139139 // If the first splice manages to copy to the intermediate
140140 // pipe, but the second splice to stdout fails for some reason
141141 // we can recover by copying the data that we have from the
142- // intermediate pipe to stdout using normal read/write. Then
142+ // intermediate pipe to stdout using raw read/write syscalls . Then
143143 // we tell the caller to fall back.
144144 debug_assert ! ( n <= MAX_ROOTLESS_PIPE_SIZE , "unexpected RAM usage" ) ;
145- let mut drain = Vec :: with_capacity ( n) ;
146- pipe_rd. take ( n as u64 ) . read_to_end ( & mut drain) ?;
147- dest. write_all ( & drain) ?;
145+ let mut buf = Vec :: with_capacity ( n) ;
146+ let buf = buf. spare_capacity_mut ( ) ;
147+ let ( buf, _) = rustix:: io:: read ( pipe_rd, & mut * buf) ?;
148+ crate :: io:: write_all_raw ( dest, buf) ?;
148149 return Ok ( true ) ;
149150 }
150151 }
@@ -210,9 +211,11 @@ pub fn send_n_bytes(
210211 }
211212 } else {
212213 debug_assert ! ( s <= MAX_ROOTLESS_PIPE_SIZE , "unexpected RAM usage" ) ;
213- let mut drain = Vec :: with_capacity ( s) ;
214- broker_r. take ( s as u64 ) . read_to_end ( & mut drain) ?;
215- target. write_all ( & drain) ?;
214+ // drain pipe before fallback to raw write
215+ let mut buf = Vec :: with_capacity ( s) ;
216+ let buf = buf. spare_capacity_mut ( ) ;
217+ let ( buf, _) = rustix:: io:: read ( broker_r, & mut * buf) ?;
218+ crate :: io:: write_all_raw ( & target, buf) ?;
216219 break true ;
217220 }
218221 }
0 commit comments