compio_driver/sys/pal/unix/
mod.rs1use std::io;
2pub use std::os::fd::{AsFd, AsRawFd, BorrowedFd, FromRawFd, IntoRawFd, OwnedFd, RawFd};
3
4pub use libc::cmsghdr as CmsgHeader;
5use rustix::{
6 fs::{AtFlags, CWD, Stat},
7 io::Errno,
8};
9use smallvec::SmallVec;
10
11use crate::sys::prelude::*;
12
13mod_use![stat, pipe, socket];
14
15pub mod reexport {}
16
17pub type Multi<T> = SmallVec<[T; 1]>;
19
20#[derive(Debug, Clone, Copy, PartialEq, Eq)]
22pub enum Interest {
23 Readable,
25 Writable,
27}
28
29pub struct CurrentDir;
32
33impl AsRawFd for CurrentDir {
34 fn as_raw_fd(&self) -> RawFd {
35 CWD.as_raw_fd()
36 }
37}
38
39impl AsFd for CurrentDir {
40 fn as_fd(&self) -> BorrowedFd<'_> {
41 unsafe { BorrowedFd::borrow_raw(libc::AT_FDCWD) }
42 }
43}
44
45pub fn poll_io<R, E, F>(mut f: F) -> Poll<io::Result<R>>
48where
49 F: FnMut() -> std::result::Result<R, E>,
50 E: Into<io::Error>,
51{
52 loop {
53 match f().map_err(Into::into) {
54 Ok(res) => break Poll::Ready(Ok(res)),
55 Err(e) => match Errno::from_io_error(&e) {
56 Some(Errno::WOULDBLOCK | Errno::INPROGRESS) => return Poll::Pending,
57 Some(Errno::INTR) => continue,
58 _ => return Poll::Ready(Err(e)),
59 },
60 }
61 }
62}