externally-driven-async-rt 0.5.1

Async runtime that is meant to be embedded
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
use rustix::{
    event::{PollFd, PollFlags, Timespec, poll},
    fd::AsFd,
};

pub(crate) trait FdTestingExt: AsFd {
    fn wait_readable_blocking(&self, timeout_ms: i64) -> bool {
        let fd = self.as_fd();
        let mut fds = [PollFd::new(&fd, PollFlags::IN)];
        let timeout = Timespec {
            tv_sec: timeout_ms / 1000,
            tv_nsec: timeout_ms % 1000 * 1_000_000,
        };
        poll(&mut fds, Some(&timeout)).unwrap() == 1
    }
}

impl<T: AsFd + ?Sized> FdTestingExt for T {}