Skip to content

Commit 808dbb0

Browse files
ecnelisesThomasdezeeuw
authored andcommitted
Implement pipe2 for AIX
AIX does not have pipe2 system call. Use pipe with fcntl instead.
1 parent 605ba78 commit 808dbb0

File tree

2 files changed

+30
-8
lines changed

2 files changed

+30
-8
lines changed

src/sys/unix/pipe.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,7 @@ pub fn new() -> io::Result<(Sender, Receiver)> {
164164
}
165165

166166
#[cfg(any(
167+
target_os = "aix",
167168
target_os = "ios",
168169
target_os = "macos",
169170
target_os = "tvos",

src/sys/unix/waker.rs

Lines changed: 29 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)