@@ -10,6 +10,8 @@ use rustix::pipe::{SpliceFlags, fcntl_setpipe_size};
1010#[ cfg( any( target_os = "linux" , target_os = "android" ) ) ]
1111use std:: fs:: File ;
1212#[ cfg( any( target_os = "linux" , target_os = "android" ) ) ]
13+ use std:: io:: { PipeReader , PipeWriter } ;
14+ #[ cfg( any( target_os = "linux" , target_os = "android" ) ) ]
1315use std:: {
1416 io:: { Read , Write } ,
1517 os:: fd:: AsFd ,
@@ -27,17 +29,17 @@ const KERNEL_DEFAULT_PIPE_SIZE: usize = 64 * 1024;
2729/// used for resolving the limitation for splice: one of a input or output should be pipe
2830#[ inline]
2931#[ cfg( any( target_os = "linux" , target_os = "android" ) ) ]
30- pub fn pipe < const SIZE_REQUIRED : bool > ( s : usize ) -> std:: io:: Result < ( File , File ) > {
31- let ( read , write ) = rustix :: pipe :: pipe ( ) ?;
32+ pub fn pipe < const SIZE_REQUIRED : bool > ( s : usize ) -> std:: io:: Result < ( PipeReader , PipeWriter ) > {
33+ let ( pipe_reader , pipe_writer ) = std :: io :: pipe ( ) ?;
3234 // guard unnecessary syscall
3335 if s > KERNEL_DEFAULT_PIPE_SIZE {
34- let r = fcntl_setpipe_size ( & read , s) ;
36+ let r = fcntl_setpipe_size ( & pipe_reader , s) ;
3537 if SIZE_REQUIRED {
3638 r?;
3739 }
3840 }
3941
40- Ok ( ( File :: from ( read ) , File :: from ( write ) ) )
42+ Ok ( ( pipe_reader , pipe_writer ) )
4143}
4244
4345/// Less noisy wrapper around [`rustix::pipe::splice`].
@@ -116,8 +118,8 @@ where
116118 R : Read + AsFd ,
117119 S : AsFd ,
118120{
119- static PIPE_CACHE : OnceLock < Option < ( File , File ) > > = OnceLock :: new ( ) ;
120- let Some ( ( pipe_rd , pipe_wr ) ) = PIPE_CACHE
121+ static PIPE_CACHE : OnceLock < Option < ( PipeReader , PipeWriter ) > > = OnceLock :: new ( ) ;
122+ let Some ( ( pipe_reader , pipe_writer ) ) = PIPE_CACHE
121123 . get_or_init ( || pipe :: < false > ( MAX_ROOTLESS_PIPE_SIZE ) . ok ( ) )
122124 . as_ref ( )
123125 else {
@@ -130,18 +132,18 @@ where
130132 let _ = fcntl_setpipe_size ( & mut * dest, MAX_ROOTLESS_PIPE_SIZE ) ;
131133
132134 loop {
133- match splice ( & source, & pipe_wr , MAX_ROOTLESS_PIPE_SIZE ) {
135+ match splice ( & source, & pipe_writer , MAX_ROOTLESS_PIPE_SIZE ) {
134136 Ok ( 0 ) => return Ok ( false ) ,
135137 Ok ( n) => {
136- if splice_exact ( & pipe_rd , dest, n) . is_err ( ) {
138+ if splice_exact ( & pipe_reader , dest, n) . is_err ( ) {
137139 // If the first splice manages to copy to the intermediate
138140 // pipe, but the second splice to stdout fails for some reason
139141 // we can recover by copying the data that we have from the
140142 // intermediate pipe to stdout using unbuffered read/write. Then
141143 // we tell the caller to fall back.
142144 debug_assert ! ( n <= MAX_ROOTLESS_PIPE_SIZE , "unexpected RAM usage" ) ;
143145 let mut drain = Vec :: with_capacity ( n) ;
144- pipe_rd . take ( n as u64 ) . read_to_end ( & mut drain) ?;
146+ pipe_reader . take ( n as u64 ) . read_to_end ( & mut drain) ?;
145147 crate :: io:: RawWriter ( & dest) . write_all ( & drain) ?;
146148 return Ok ( true ) ;
147149 }
@@ -160,7 +162,7 @@ pub fn send_n_bytes(
160162 mut target : impl Write + AsFd ,
161163 n : u64 ,
162164) -> std:: io:: Result < u64 > {
163- static PIPE_CACHE : OnceLock < Option < ( File , File ) > > = OnceLock :: new ( ) ;
165+ static PIPE_CACHE : OnceLock < Option < ( PipeReader , PipeWriter ) > > = OnceLock :: new ( ) ;
164166 let pipe_size = MAX_ROOTLESS_PIPE_SIZE . min ( n as usize ) ;
165167 let mut n = n;
166168 let mut bytes_written: u64 = 0 ;
0 commit comments