Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 0b09f8c4 authored by Matthew Maurer's avatar Matthew Maurer Committed by Automerger Merge Worker
Browse files

Merge "Update for nix 0.27.1." into main am: 16336062

parents 356a00ae 16336062
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -25,7 +25,7 @@ futures = "0.3.13"
grpcio = "0.9"
lazy_static = "1.4"
log = "0.4"
nix = "0.23"
nix = { version = "0.27.1", features = ["time", "user"] }
tokio = { version = "1.0", features = ['bytes', 'macros', 'net', 'rt-multi-thread', 'time'] }

# Proc Macro dependency
+29 −4
Original line number Diff line number Diff line
@@ -2,19 +2,44 @@
///Tokio's time
use nix::sys::time::TimeSpec;
use nix::sys::timerfd::{ClockId, Expiration, TimerFd, TimerFlags, TimerSetTimeFlags};
use std::os::fd::{AsFd, AsRawFd, RawFd};
use std::time::Duration;
use tokio::io::unix::AsyncFd;

/// A wrapper for `TimerFd` which implements `AsRawFd`.
#[derive(Debug)]
struct TimerFdWrapper(TimerFd);

impl TimerFdWrapper {
    fn get(&self) -> nix::Result<Option<Expiration>> {
        self.0.get()
    }

    fn set(&self, expiration: Expiration, flags: TimerSetTimeFlags) -> nix::Result<()> {
        self.0.set(expiration, flags)
    }

    fn wait(&self) -> nix::Result<()> {
        self.0.wait()
    }
}

impl AsRawFd for TimerFdWrapper {
    fn as_raw_fd(&self) -> RawFd {
        self.0.as_fd().as_raw_fd()
    }
}

/// A single shot Alarm
pub struct Alarm {
    fd: AsyncFd<TimerFd>,
    fd: AsyncFd<TimerFdWrapper>,
}

impl Alarm {
    /// Construct a new alarm
    pub fn new() -> Self {
        let timer = TimerFd::new(get_clock(), TimerFlags::empty()).unwrap();
        Self { fd: AsyncFd::new(timer).unwrap() }
        Self { fd: AsyncFd::new(TimerFdWrapper(timer)).unwrap() }
    }

    /// Reset the alarm to duration, starting from now
@@ -53,12 +78,12 @@ pub fn interval(period: Duration) -> Interval {
    let timer = TimerFd::new(get_clock(), TimerFlags::empty()).unwrap();
    timer.set(Expiration::Interval(TimeSpec::from(period)), TimerSetTimeFlags::empty()).unwrap();

    Interval { fd: AsyncFd::new(timer).unwrap() }
    Interval { fd: AsyncFd::new(TimerFdWrapper(timer)).unwrap() }
}

/// Future returned by interval()
pub struct Interval {
    fd: AsyncFd<TimerFd>,
    fd: AsyncFd<TimerFdWrapper>,
}

impl Interval {