This commit is contained in:
Stjepan Glavina 2020-09-01 06:48:09 +02:00
parent 3fdcd68e23
commit 4b4b774116
5 changed files with 14 additions and 22 deletions

View File

@ -4,7 +4,6 @@ use std::io;
use std::os::unix::io::RawFd;
use std::ptr;
use std::time::Duration;
use std::usize;
use crate::Event;
@ -75,7 +74,7 @@ impl Poller {
poller.interest(
event_fd,
Event {
key: NOTIFY_KEY,
key: crate::NOTIFY_KEY,
readable: true,
writable: false,
},
@ -101,7 +100,7 @@ impl Poller {
// Register the file descriptor in epoll.
let mut ev = libc::epoll_event {
events: libc::EPOLLONESHOT,
u64: NOTIFY_KEY as u64,
u64: crate::NOTIFY_KEY as u64,
};
syscall!(epoll_ctl(self.epoll_fd, libc::EPOLL_CTL_ADD, fd, &mut ev))?;
@ -168,7 +167,7 @@ impl Poller {
self.interest(
self.timer_fd,
Event {
key: NOTIFY_KEY,
key: crate::NOTIFY_KEY,
readable: true,
writable: false,
},
@ -203,7 +202,7 @@ impl Poller {
self.interest(
self.event_fd,
Event {
key: NOTIFY_KEY,
key: crate::NOTIFY_KEY,
readable: true,
writable: false,
},
@ -252,9 +251,6 @@ const TS_ZERO: libc::timespec = libc::timespec {
tv_nsec: 0,
};
/// Key associated with the eventfd for producing notifications.
const NOTIFY_KEY: usize = usize::MAX;
/// Epoll flags for all possible readability events.
fn read_flags() -> libc::c_int {
libc::EPOLLIN | libc::EPOLLRDHUP | libc::EPOLLHUP | libc::EPOLLERR | libc::EPOLLPRI

View File

@ -5,7 +5,6 @@ use std::os::unix::io::{AsRawFd, RawFd};
use std::os::unix::net::UnixStream;
use std::ptr;
use std::time::Duration;
use std::usize;
use crate::Event;
@ -39,7 +38,7 @@ impl Poller {
poller.interest(
poller.read_stream.as_raw_fd(),
Event {
key: NOTIFY_KEY,
key: crate::NOTIFY_KEY,
readable: true,
writable: false,
},
@ -214,7 +213,7 @@ impl Poller {
self.interest(
self.read_stream.as_raw_fd(),
Event {
key: NOTIFY_KEY,
key: crate::NOTIFY_KEY,
readable: true,
writable: false,
},
@ -239,9 +238,6 @@ impl Drop for Poller {
}
}
/// Key associated with the pipe for producing notifications.
const NOTIFY_KEY: usize = usize::MAX;
/// A list of reported I/O events.
pub struct Events {
list: Box<[libc::kevent]>,

View File

@ -101,6 +101,9 @@ cfg_if! {
}
}
/// Key associated with notifications.
const NOTIFY_KEY: usize = std::usize::MAX;
/// Indicates that a file descriptor or socket can read or write without blocking.
#[derive(Debug)]
pub struct Event {
@ -313,7 +316,8 @@ impl Poller {
/// before calling [`wait()`][`Poller::wait()`]!
///
/// This method will return with no new events if a notification is delivered by the
/// [`notify()`] method, or the timeout is reached.
/// [`notify()`] method, or the timeout is reached. Sometimes it may even return with no events
/// spuriously.
///
/// Only one thread can wait on I/O. If another thread is already in [`wait()`], concurrent
/// calls to this method will return immediately with no new events.

View File

@ -5,7 +5,6 @@ use std::os::unix::io::{AsRawFd, RawFd};
use std::os::unix::net::UnixStream;
use std::ptr;
use std::time::Duration;
use std::usize;
use crate::Event;
@ -40,7 +39,7 @@ impl Poller {
poller.interest(
poller.read_stream.as_raw_fd(),
Event {
key: NOTIFY_KEY,
key: crate::NOTIFY_KEY,
readable: true,
writable: false,
},
@ -135,7 +134,7 @@ impl Poller {
self.interest(
self.read_stream.as_raw_fd(),
Event {
key: NOTIFY_KEY,
key: crate::NOTIFY_KEY,
readable: true,
writable: false,
},
@ -158,9 +157,6 @@ impl Drop for Poller {
}
}
/// Key associated with the eventfd for producing notifications.
const NOTIFY_KEY: usize = usize::MAX;
/// Poll flags for all possible readability events.
fn read_flags() -> libc::c_short {
libc::POLLIN | libc::POLLHUP | libc::POLLERR | libc::POLLPRI

View File

@ -67,7 +67,7 @@ impl Poller {
let mut ev = we::epoll_event {
events: we::EPOLLONESHOT,
data: we::epoll_data {
u64: std::usize::MAX as u64,
u64: crate::NOTIFY_KEY as u64,
},
};
wepoll!(epoll_ctl(