@@ -139,12 +139,14 @@ 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+ crate :: io:: write_all_raw (
147+ dest,
148+ rustix:: io:: read ( pipe_rd, & mut * buf. spare_capacity_mut ( ) ) ?. 0 ,
149+ ) ?;
148150 return Ok ( true ) ;
149151 }
150152 }
@@ -210,9 +212,12 @@ pub fn send_n_bytes(
210212 }
211213 } else {
212214 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) ?;
215+ // drain pipe before fallback to raw write
216+ let mut buf = Vec :: with_capacity ( s) ;
217+ crate :: io:: write_all_raw (
218+ & target,
219+ rustix:: io:: read ( broker_r, & mut * buf. spare_capacity_mut ( ) ) ?. 0 ,
220+ ) ?;
216221 break true ;
217222 }
218223 }
0 commit comments