5555{
5656 // If we're on Linux or Android, try to use the splice() system call
5757 // for faster writing. If it works, we're done.
58- let result = splice_write ( src, & dest. as_fd ( ) ) ?;
59- if !result. 1 {
58+ if !splice_write ( src, & dest. as_fd ( ) ) ? {
6059 return Ok ( ( ) ) ;
6160 }
6261
@@ -79,13 +78,12 @@ where
7978/// - `source` - source handle
8079/// - `dest` - destination handle
8180#[ inline]
82- pub ( crate ) fn splice_write < R , S > ( source : & R , dest : & S ) -> UResult < ( u64 , bool ) >
81+ pub ( crate ) fn splice_write < R , S > ( source : & R , dest : & S ) -> UResult < bool >
8382where
8483 R : Read + AsFd + AsRawFd ,
8584 S : AsRawFd + AsFd ,
8685{
8786 let ( pipe_rd, pipe_wr) = pipe ( ) ?;
88- let mut bytes: u64 = 0 ;
8987 // improve throughput
9088 // no need to increase pipe size of input fd since
9189 // - sender with splice probably increased size already
@@ -94,25 +92,19 @@ where
9492
9593 loop {
9694 match splice ( & source, & pipe_wr, MAX_ROOTLESS_PIPE_SIZE ) {
95+ Ok ( 0 ) => return Ok ( false ) ,
9796 Ok ( n) => {
98- if n == 0 {
99- return Ok ( ( bytes, false ) ) ;
100- }
10197 if splice_exact ( & pipe_rd, dest, n) . is_err ( ) {
10298 // If the first splice manages to copy to the intermediate
10399 // pipe, but the second splice to stdout fails for some reason
104100 // we can recover by copying the data that we have from the
105101 // intermediate pipe to stdout using normal read/write. Then
106102 // we tell the caller to fall back.
107103 copy_exact ( & pipe_rd, dest, n) ?;
108- return Ok ( ( bytes , true ) ) ;
104+ return Ok ( true ) ;
109105 }
110-
111- bytes += n as u64 ;
112- }
113- Err ( _) => {
114- return Ok ( ( bytes, true ) ) ;
115106 }
107+ Err ( _) => return Ok ( true ) ,
116108 }
117109 }
118110}
0 commit comments