@@ -223,14 +223,9 @@ mod pipe {
223223
224224 impl WakerInternal {
225225 pub fn new ( ) -> io:: Result < WakerInternal > {
226- let mut fds = [ -1 ; 2 ] ;
227- #[ cfg( not( target_os = "aix" ) ) ]
228- syscall ! ( pipe2( fds. as_mut_ptr( ) , libc:: O_NONBLOCK | libc:: O_CLOEXEC ) ) ?;
229- #[ cfg( target_os = "aix" ) ]
230- syscall ! ( pipe( fds. as_mut_ptr( ) ) ) ?;
231- let sender = unsafe { File :: from_raw_fd ( fds[ 1 ] ) } ;
232- let receiver = unsafe { File :: from_raw_fd ( fds[ 0 ] ) } ;
233-
226+ let ( receiver, sender) = Self :: pipe2 ( ) ?;
227+ let receiver = unsafe { File :: from_raw_fd ( receiver) } ;
228+ let sender = unsafe { File :: from_raw_fd ( sender) } ;
234229 Ok ( WakerInternal { sender, receiver } )
235230 }
236231
@@ -270,6 +265,32 @@ mod pipe {
270265 }
271266 }
272267 }
268+
269+ #[ cfg( target_os = "aix" ) ]
270+ fn pipe2 ( ) -> io:: Result < ( RawFd , RawFd ) > {
271+ let mut fds = [ -1 ; 2 ] ;
272+ syscall ! ( pipe( fds. as_mut_ptr( ) ) ) ?;
273+ unsafe {
274+ if libc:: fcntl ( fds[ 0 ] , libc:: F_SETFL , libc:: O_NONBLOCK ) != 0
275+ || libc:: fcntl ( fds[ 0 ] , libc:: F_SETFD , libc:: O_CLOEXEC ) != 0
276+ || libc:: fcntl ( fds[ 1 ] , libc:: F_SETFL , libc:: O_NONBLOCK ) != 0
277+ || libc:: fcntl ( fds[ 1 ] , libc:: F_SETFD , libc:: O_CLOEXEC ) != 0
278+ {
279+ let err = io:: Error :: last_os_error ( ) ;
280+ let _ = libc:: close ( fds[ 0 ] ) ;
281+ let _ = libc:: close ( fds[ 1 ] ) ;
282+ return Err ( err) ;
283+ }
284+ }
285+ Ok ( ( fds[ 0 ] , fds[ 1 ] ) )
286+ }
287+
288+ #[ cfg( not( target_os = "aix" ) ) ]
289+ fn pipe2 ( ) -> io:: Result < ( RawFd , RawFd ) > {
290+ let mut fds = [ -1 ; 2 ] ;
291+ syscall ! ( pipe2( fds. as_mut_ptr( ) , libc:: O_NONBLOCK | libc:: O_CLOEXEC ) ) ?;
292+ Ok ( ( fds[ 0 ] , fds[ 1 ] ) )
293+ }
273294 }
274295
275296 impl AsRawFd for WakerInternal {
0 commit comments