oscall 0.1.1

Low-level cross-platform interface to operating system services: files, memory mapping, networking and more, with no libc on Linux
Documentation
//! `event` without a system: there is nothing to wait for, and every call
//! fails with `Unsupported`.

use core::time::Duration;

use crate::event::{Interest, Readiness};
use crate::sys::RawHandle;
use crate::{ErrorKind, Result};

/// The entry of a poll that cannot be made.
#[derive(Clone, Copy)]
pub(crate) struct PollFd {
    fd: RawHandle,
    interest: Interest,
}

impl PollFd {
    pub(crate) fn new(fd: RawHandle, interest: Interest) -> Self {
        Self { fd, interest }
    }

    pub(crate) fn raw(&self) -> RawHandle {
        self.fd
    }

    pub(crate) fn interest(&self) -> Interest {
        self.interest
    }

    pub(crate) fn readiness(&self) -> Readiness {
        Readiness::empty()
    }

    pub(crate) fn clear(&mut self) {}
}

pub(crate) fn poll(_: &mut [PollFd], _: Option<Duration>) -> Result<usize> {
    Err(ErrorKind::Unsupported.into())
}

#[cfg(feature = "alloc")]
pub(crate) use poller::{Poller, RawEvent};

#[cfg(feature = "alloc")]
mod poller {
    use core::time::Duration;

    use crate::event::timers::Op;
    use crate::event::{Interest, ModeKind, Readiness};
    use crate::sys::RawHandle;
    use crate::{ErrorKind, Result};

    /// The event of a poller that cannot be made.
    #[derive(Clone, Copy)]
    pub(crate) struct RawEvent;

    impl RawEvent {
        pub(crate) const EMPTY: Self = Self;

        pub(crate) fn token(&self) -> usize {
            0
        }

        pub(crate) fn is_wake(&self) -> bool {
            false
        }

        pub(crate) fn is_timer(&self) -> bool {
            false
        }

        pub(crate) fn expirations(&self) -> u64 {
            0
        }

        pub(crate) fn readiness(&self) -> Readiness {
            Readiness::empty()
        }
    }

    /// There is no such thing: `new` fails.
    pub(crate) struct Poller;

    fn unsupported<T>() -> Result<T> {
        Err(ErrorKind::Unsupported.into())
    }

    impl Poller {
        pub(crate) fn new() -> Result<Self> {
            unsupported()
        }

        pub(crate) fn register(
            &self,
            _: RawHandle,
            _: usize,
            _: Interest,
            _: ModeKind,
        ) -> Result<()> {
            unsupported()
        }

        pub(crate) fn modify(
            &self,
            _: RawHandle,
            _: usize,
            _: Interest,
            _: ModeKind,
        ) -> Result<()> {
            unsupported()
        }

        pub(crate) fn deregister(&self, _: RawHandle) -> Result<()> {
            unsupported()
        }

        pub(crate) fn wait(&self, _: &mut [RawEvent], _: Option<Duration>) -> Result<usize> {
            unsupported()
        }

        pub(crate) fn wake(&self) -> Result<()> {
            unsupported()
        }

        pub(crate) fn timer(&self, _: usize, _: Op) -> Result<()> {
            unsupported()
        }

        pub(crate) fn register_signals(
            &self,
            signals: &crate::sys::process::signal::Signals,
            _: usize,
        ) -> Result<()> {
            match *signals {}
        }

        pub(crate) fn deregister_signals(
            &self,
            signals: &crate::sys::process::signal::Signals,
        ) -> Result<()> {
            match *signals {}
        }

        pub(crate) fn register_child(
            &self,
            child: &crate::sys::process::Child,
            _: bool,
            _: usize,
        ) -> Result<()> {
            match *child {}
        }

        pub(crate) fn deregister_child(&self, child: &crate::sys::process::Child) -> Result<()> {
            match *child {}
        }
    }
}