Switch timeout to i32
This commit is contained in:
parent
30908ebdb9
commit
28a4b75d29
16
src/lib.rs
16
src/lib.rs
|
@ -3,7 +3,7 @@ use rustix::{
|
|||
io::{OwnedFd, PollFd, PollFlags},
|
||||
net::{AddressFamily, Protocol, SocketFlags, SocketType},
|
||||
};
|
||||
use std::{collections::HashMap, ops::BitOr, sync::Arc, time::Duration};
|
||||
use std::{collections::HashMap, ops::BitOr, sync::Arc};
|
||||
|
||||
pub mod net;
|
||||
|
||||
|
@ -28,7 +28,7 @@ struct Io {
|
|||
|
||||
#[derive(Default)]
|
||||
pub struct Poller<'a> {
|
||||
timeout: Option<Duration>,
|
||||
timeout: Option<i32>,
|
||||
flags: Vec<PollFlags>,
|
||||
fds: Vec<PollFd<'a>>,
|
||||
}
|
||||
|
@ -125,10 +125,7 @@ impl PollManager {
|
|||
self.notify_token.clone()
|
||||
}
|
||||
|
||||
pub fn poll(
|
||||
&mut self,
|
||||
timeout: Option<Duration>,
|
||||
) -> rustix::io::Result<Vec<(usize, Readiness)>> {
|
||||
pub fn poll(&mut self, timeout: Option<i32>) -> rustix::io::Result<Vec<(usize, Readiness)>> {
|
||||
let mut poller = Poller::new();
|
||||
if let Some(timeout) = timeout {
|
||||
poller.timeout(timeout);
|
||||
|
@ -288,15 +285,12 @@ impl<'a> Poller<'a> {
|
|||
len
|
||||
}
|
||||
|
||||
pub fn timeout(&mut self, timeout: Duration) {
|
||||
pub fn timeout(&mut self, timeout: i32) {
|
||||
self.timeout = Some(timeout);
|
||||
}
|
||||
|
||||
pub fn poll(mut self) -> rustix::io::Result<Vec<(usize, Readiness)>> {
|
||||
let timeout = self
|
||||
.timeout
|
||||
.and_then(|timeout| timeout.as_millis().try_into().ok())
|
||||
.unwrap_or(-1);
|
||||
let timeout = self.timeout.unwrap_or(-1);
|
||||
|
||||
let n = rustix::io::poll(&mut self.fds, timeout)?;
|
||||
|
||||
|
|
Loading…
Reference in a new issue