mirror of
https://github.com/asterinas/asterinas.git
synced 2025-06-25 02:13:24 +00:00
Add timeout parameter for poller.wait
This commit is contained in:
committed by
Tate, Hongliang Tian
parent
bd6a4d34ff
commit
ec857e5205
@ -105,7 +105,8 @@ impl FileLike for PtyMaster {
|
||||
|
||||
if events.is_empty() {
|
||||
drop(input);
|
||||
poller.wait();
|
||||
// FIXME: deal with pty read timeout
|
||||
poller.wait(None)?;
|
||||
}
|
||||
continue;
|
||||
}
|
||||
|
@ -252,7 +252,8 @@ impl LineDiscipline {
|
||||
};
|
||||
let revents = self.pollee.poll(IoEvents::IN, need_poller);
|
||||
if revents.is_empty() {
|
||||
poller.as_ref().unwrap().wait();
|
||||
// FIXME: deal with ldisc read timeout
|
||||
poller.as_ref().unwrap().wait(None)?;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -191,8 +191,7 @@ impl EpollFile {
|
||||
}
|
||||
}
|
||||
|
||||
// FIXME: respect timeout parameter
|
||||
poller.as_ref().unwrap().wait();
|
||||
poller.as_ref().unwrap().wait(timeout)?;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -152,7 +152,8 @@ impl<T: Copy> Producer<T> {
|
||||
}
|
||||
let events = self.poll(mask, Some(&poller));
|
||||
if events.is_empty() {
|
||||
poller.wait();
|
||||
// FIXME: should channel deal with timeout?
|
||||
poller.wait(None)?;
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -240,7 +241,8 @@ impl<T: Copy> Consumer<T> {
|
||||
}
|
||||
let events = self.poll(mask, Some(&poller));
|
||||
if events.is_empty() {
|
||||
poller.wait();
|
||||
// FIXME: should channel have timeout?
|
||||
poller.wait(None)?;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -3,6 +3,7 @@ use crate::events::{Observer, Subject};
|
||||
use crate::prelude::*;
|
||||
|
||||
use core::sync::atomic::{AtomicU32, AtomicUsize, Ordering};
|
||||
use core::time::Duration;
|
||||
use jinux_frame::sync::WaitQueue;
|
||||
use keyable_arc::KeyableWeak;
|
||||
|
||||
@ -157,8 +158,9 @@ impl Poller {
|
||||
}
|
||||
|
||||
/// Wait until there are any interesting events happen since last `wait`.
|
||||
pub fn wait(&self) {
|
||||
self.inner.event_counter.read();
|
||||
pub fn wait(&self, timeout: Option<&Duration>) -> Result<()> {
|
||||
self.inner.event_counter.read(timeout)?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn observer(&self) -> Weak<dyn Observer<IoEvents>> {
|
||||
@ -202,9 +204,8 @@ impl EventCounter {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn read(&self) -> usize {
|
||||
self.wait_queue
|
||||
.wait_until(
|
||||
pub fn read(&self, timeout: Option<&Duration>) -> Result<usize> {
|
||||
let val = self.wait_queue.wait_until(
|
||||
|| {
|
||||
let val = self.counter.swap(0, Ordering::Relaxed);
|
||||
if val > 0 {
|
||||
@ -213,9 +214,9 @@ impl EventCounter {
|
||||
None
|
||||
}
|
||||
},
|
||||
None,
|
||||
)
|
||||
.unwrap()
|
||||
timeout,
|
||||
)?;
|
||||
Ok(val)
|
||||
}
|
||||
|
||||
pub fn write(&self) {
|
||||
|
@ -258,7 +258,8 @@ impl Socket for DatagramSocket {
|
||||
if self.nonblocking() {
|
||||
return_errno_with_message!(Errno::EAGAIN, "try to receive again");
|
||||
}
|
||||
poller.wait();
|
||||
// FIXME: deal with recvfrom timeout
|
||||
poller.wait(None)?;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -57,7 +57,8 @@ impl ConnectedStream {
|
||||
if self.is_nonblocking() {
|
||||
return_errno_with_message!(Errno::EAGAIN, "try to recv again");
|
||||
}
|
||||
poller.wait();
|
||||
// FIXME: deal with receive timeout
|
||||
poller.wait(None)?;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -151,7 +151,8 @@ impl InitStream {
|
||||
} else if self.is_nonblocking() {
|
||||
return_errno_with_message!(Errno::EAGAIN, "try connect again");
|
||||
} else {
|
||||
poller.wait();
|
||||
// FIXME: deal with connecting timeout
|
||||
poller.wait(None)?;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -45,7 +45,8 @@ impl ListenStream {
|
||||
if self.is_nonblocking() {
|
||||
return_errno_with_message!(Errno::EAGAIN, "try accept again");
|
||||
}
|
||||
poller.wait();
|
||||
// FIXME: deal with accept timeout
|
||||
poller.wait(None)?;
|
||||
}
|
||||
continue;
|
||||
};
|
||||
|
@ -131,8 +131,9 @@ impl BacklogTable {
|
||||
return_errno_with_message!(Errno::ECONNABORTED, "connection is aborted");
|
||||
}
|
||||
|
||||
// FIXME: deal with accept timeout
|
||||
if events.is_empty() {
|
||||
poller.wait();
|
||||
poller.wait(None)?;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -91,8 +91,7 @@ pub fn do_poll(poll_fds: &[PollFd], timeout: Option<Duration>) -> Result<usize>
|
||||
return Ok(0);
|
||||
}
|
||||
|
||||
// FIXME: respect timeout parameter
|
||||
poller.wait();
|
||||
poller.wait(timeout.as_ref())?;
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user