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 trait AsSocketState: AsFd {
17 fn recv_poll_first(&self) -> bool {
20 false
21 }
22
23 fn accept_poll_first(&self) -> bool {
25 false
26 }
27
28 fn set_recv(&self, extra: &Extra) {
30 let _ = extra;
31 }
32
33 fn set_accept(&self, extra: &Extra) {
35 let _ = extra;
36 }
37}
38
39impl<T: AsSocketState> AsSocketState for crate::SharedFd<T> {
40 fn recv_poll_first(&self) -> bool {
41 (**self).recv_poll_first()
42 }
43
44 fn accept_poll_first(&self) -> bool {
45 (**self).accept_poll_first()
46 }
47
48 fn set_recv(&self, extra: &Extra) {
49 (**self).set_recv(extra)
50 }
51
52 fn set_accept(&self, extra: &Extra) {
53 (**self).set_accept(extra)
54 }
55}
56
57pub mod reexport {}
58
59pub type Multi<T> = SmallVec<[T; 1]>;
61
62#[derive(Debug, Clone, Copy, PartialEq, Eq)]
64pub enum Interest {
65 Readable,
67 Writable,
69}
70
71pub struct CurrentDir;
74
75impl AsRawFd for CurrentDir {
76 fn as_raw_fd(&self) -> RawFd {
77 CWD.as_raw_fd()
78 }
79}
80
81impl AsFd for CurrentDir {
82 fn as_fd(&self) -> BorrowedFd<'_> {
83 unsafe { BorrowedFd::borrow_raw(libc::AT_FDCWD) }
84 }
85}
86
87pub fn poll_io<R, E, F>(mut f: F) -> Poll<io::Result<R>>
90where
91 F: FnMut() -> std::result::Result<R, E>,
92 E: Into<io::Error>,
93{
94 loop {
95 match f().map_err(Into::into) {
96 Ok(res) => break Poll::Ready(Ok(res)),
97 Err(e) => match Errno::from_io_error(&e) {
98 Some(Errno::WOULDBLOCK | Errno::INPROGRESS) => return Poll::Pending,
99 Some(Errno::INTR) => continue,
100 _ => return Poll::Ready(Err(e)),
101 },
102 }
103 }
104}