@@ -10,8 +10,8 @@ use nix::{
1010} ;
1111use std:: fs:: File ;
1212use std:: io:: { Read , Write } ;
13- use std:: mem:: { ManuallyDrop , MaybeUninit } ;
14- use std:: os:: fd:: { AsFd , AsRawFd , FromRawFd , OwnedFd , RawFd } ;
13+ use std:: mem:: MaybeUninit ;
14+ use std:: os:: fd:: { AsFd , AsRawFd , FromRawFd , RawFd } ;
1515use std:: sync:: atomic:: { AtomicBool , Ordering } ;
1616
1717static SHOULD_USE_SPLICE : AtomicBool = AtomicBool :: new ( true ) ;
@@ -50,7 +50,7 @@ fn pump_via_copy(mut fd_in: &File, mut fd_out: &File) -> LoggedResult<()> {
5050 Ok ( ( ) )
5151}
5252
53- fn pump_via_splice ( fd_in : & File , fd_out : & File , pipe : & ( OwnedFd , OwnedFd ) ) -> LoggedResult < ( ) > {
53+ fn pump_via_splice ( fd_in : & File , fd_out : & File , pipe : & ( File , File ) ) -> LoggedResult < ( ) > {
5454 if !SHOULD_USE_SPLICE . load ( Ordering :: Relaxed ) {
5555 return pump_via_copy ( fd_in, fd_out) ;
5656 }
@@ -64,10 +64,10 @@ fn pump_via_splice(fd_in: &File, fd_out: &File, pipe: &(OwnedFd, OwnedFd)) -> Lo
6464 if len == 0 {
6565 return Ok ( ( ) ) ;
6666 }
67- if let Err ( _ ) = splice ( & pipe. 0 , fd_out, len) {
67+ if splice ( & pipe. 0 , fd_out, len) . is_err ( ) {
6868 // If splice failed, stop using splice and fallback to userspace copy
6969 SHOULD_USE_SPLICE . store ( false , Ordering :: Relaxed ) ;
70- return pump_via_copy ( & ManuallyDrop :: new ( unsafe { File :: from_raw_fd ( pipe. 0 . as_raw_fd ( ) ) } ) , fd_out) ;
70+ return pump_via_copy ( & pipe. 0 , fd_out) ;
7171 }
7272 Ok ( ( ) )
7373}
@@ -132,6 +132,7 @@ fn pump_tty_impl(ptmx: File, pump_stdin: bool) -> LoggedResult<()> {
132132
133133 // Open a pipe to bypass userspace copy with splice
134134 let pipe_fd = pipe2 ( OFlag :: O_CLOEXEC ) . into_os_result ( "pipe2" , None , None ) ?;
135+ let pipe_fd = ( File :: from ( pipe_fd. 0 ) , File :: from ( pipe_fd. 1 ) ) ;
135136
136137 ' poll: loop {
137138 // Wait for event
0 commit comments