use std::io;
use std::os::fd::{FromRawFd, OwnedFd};
pub struct Pipe {
pub readable: OwnedFd,
pub writable: OwnedFd,
}
impl Pipe {
pub fn new() -> io::Result<Self> {
let mut fds = [-1i32; 2];
let rc = unsafe { libc::pipe2(fds.as_mut_ptr(), libc::O_CLOEXEC) };
if rc != 0 {
return Err(io::Error::last_os_error());
}
Ok(unsafe {
Self {
readable: OwnedFd::from_raw_fd(fds[0]),
writable: OwnedFd::from_raw_fd(fds[1]),
}
})
}
}