@@ -139,12 +139,12 @@ 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 = rustix :: io :: read ( pipe_rd , & mut * buf . spare_capacity_mut ( ) ) ? . 0 ;
147+ crate :: io :: write_all_raw ( dest , buf ) ?;
148148 return Ok ( true ) ;
149149 }
150150 }
@@ -210,9 +210,10 @@ pub fn send_n_bytes(
210210 }
211211 } else {
212212 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) ?;
213+ // drain pipe before fallback to raw write
214+ let mut buf = Vec :: with_capacity ( s) ;
215+ let buf = rustix:: io:: read ( broker_r, & mut * buf. spare_capacity_mut ( ) ) ?. 0 ;
216+ crate :: io:: write_all_raw ( & target, buf) ?;
216217 break true ;
217218 }
218219 }
0 commit comments