use std::io;
pub use std::os::fd::{AsFd, AsRawFd, BorrowedFd, FromRawFd, IntoRawFd, OwnedFd, RawFd};
pub use libc::cmsghdr as CmsgHeader;
use rustix::{
fs::{AtFlags, CWD, Stat},
io::Errno,
};
use smallvec::SmallVec;
use crate::sys::prelude::*;
mod_use![stat, pipe, socket];
pub mod reexport {}
pub type Multi<T> = SmallVec<[T; 1]>;
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum Interest {
Readable,
Writable,
}
pub struct CurrentDir;
impl AsRawFd for CurrentDir {
fn as_raw_fd(&self) -> RawFd {
CWD.as_raw_fd()
}
}
impl AsFd for CurrentDir {
fn as_fd(&self) -> BorrowedFd<'_> {
unsafe { BorrowedFd::borrow_raw(libc::AT_FDCWD) }
}
}
pub fn poll_io<R, E, F>(mut f: F) -> Poll<io::Result<R>>
where
F: FnMut() -> std::result::Result<R, E>,
E: Into<io::Error>,
{
loop {
match f().map_err(Into::into) {
Ok(res) => break Poll::Ready(Ok(res)),
Err(e) => match Errno::from_io_error(&e) {
Some(Errno::WOULDBLOCK | Errno::INPROGRESS) => return Poll::Pending,
Some(Errno::INTR) => continue,
_ => return Poll::Ready(Err(e)),
},
}
}
}