Skip to content

Commit

Permalink
lio_listio(2) support (tokio-rs#780)
Browse files Browse the repository at this point in the history
On FreeBSD and DragonflyBSD, kevent(2) has a distinct filter type for
use with lio_listio(2).  This commit adds 2 new public methods:
UnixReady::lio and UnixReady::is_lio.

This patch also deprecates AIO fns on platforms that do not
support AIO.
  • Loading branch information
asomers authored and carllerche committed Jan 5, 2018
1 parent 3fe5e37 commit 00d8573
Show file tree
Hide file tree
Showing 2 changed files with 75 additions and 3 deletions.
6 changes: 6 additions & 0 deletions src/sys/unix/kqueue.rs
Original file line number Diff line number Diff line change
Expand Up @@ -299,6 +299,12 @@ impl Events {
event::kind_mut(&mut self.events[idx]).insert(UnixReady::aio());
}
}
#[cfg(any(target_os = "dragonfly", target_os = "freebsd"))]
{
if e.filter == libc::EVFILT_LIO {
event::kind_mut(&mut self.events[idx]).insert(UnixReady::lio());
}
}

if e.flags & libc::EV_EOF != 0 {
event::kind_mut(&mut self.events[idx]).insert(UnixReady::hup());
Expand Down
72 changes: 69 additions & 3 deletions src/sys/unix/ready.rs
Original file line number Diff line number Diff line change
Expand Up @@ -92,9 +92,13 @@ use std::fmt;
#[derive(Copy, PartialEq, Eq, Clone, PartialOrd, Ord)]
pub struct UnixReady(Ready);

const ERROR: usize = 0b00100;
const HUP: usize = 0b01000;
const AIO: usize = 0b10000;
const ERROR: usize = 0b000100;
const HUP: usize = 0b001000;
#[cfg(any(target_os = "dragonfly",
target_os = "freebsd", target_os = "ios", target_os = "macos"))]
const AIO: usize = 0b010000;
#[cfg(any(target_os = "dragonfly", target_os = "freebsd"))]
const LIO: usize = 0b100000;

impl UnixReady {
/// Returns a `Ready` representing AIO completion readiness
Expand All @@ -113,10 +117,20 @@ impl UnixReady {
///
/// [`Poll`]: ../struct.Poll.html
#[inline]
#[cfg(any(target_os = "dragonfly",
target_os = "freebsd", target_os = "ios", target_os = "macos"))]
pub fn aio() -> UnixReady {
UnixReady(ready_from_usize(AIO))
}

#[cfg(not(any(target_os = "dragonfly",
target_os = "freebsd", target_os = "ios", target_os = "macos")))]
#[deprecated(since = "0.6.12", note = "this function is now platform specific")]
#[doc(hidden)]
pub fn aio() -> UnixReady {
UnixReady(Ready::empty())
}

/// Returns a `Ready` representing error readiness.
///
/// **Note that only readable and writable readiness is guaranteed to be
Expand Down Expand Up @@ -172,6 +186,27 @@ impl UnixReady {
UnixReady(ready_from_usize(HUP))
}

/// Returns a `Ready` representing LIO completion readiness
///
/// See [`Poll`] for more documentation on polling.
///
/// # Examples
///
/// ```
/// use mio::unix::UnixReady;
///
/// let ready = UnixReady::lio();
///
/// assert!(ready.is_lio());
/// ```
///
/// [`Poll`]: struct.Poll.html
#[inline]
#[cfg(any(target_os = "dragonfly", target_os = "freebsd"))]
pub fn lio() -> UnixReady {
UnixReady(ready_from_usize(LIO))
}

/// Returns true if `Ready` contains AIO readiness
///
/// See [`Poll`] for more documentation on polling.
Expand All @@ -188,10 +223,21 @@ impl UnixReady {
///
/// [`Poll`]: ../struct.Poll.html
#[inline]
#[cfg(any(target_os = "dragonfly",
target_os = "freebsd", target_os = "ios", target_os = "macos"))]
pub fn is_aio(&self) -> bool {
self.contains(ready_from_usize(AIO))
}

#[deprecated(since = "0.6.12", note = "this function is now platform specific")]
#[cfg(feature = "with-deprecated")]
#[cfg(not(any(target_os = "dragonfly",
target_os = "freebsd", target_os = "ios", target_os = "macos")))]
#[doc(hidden)]
pub fn is_aio(&self) -> bool {
false
}

/// Returns true if the value includes error readiness
///
/// **Note that only readable and writable readiness is guaranteed to be
Expand Down Expand Up @@ -246,6 +292,25 @@ impl UnixReady {
pub fn is_hup(&self) -> bool {
self.contains(ready_from_usize(HUP))
}

/// Returns true if `Ready` contains LIO readiness
///
/// See [`Poll`] for more documentation on polling.
///
/// # Examples
///
/// ```
/// use mio::unix::UnixReady;
///
/// let ready = UnixReady::lio();
///
/// assert!(ready.is_lio());
/// ```
#[inline]
#[cfg(any(target_os = "dragonfly", target_os = "freebsd"))]
pub fn is_lio(&self) -> bool {
self.contains(ready_from_usize(LIO))
}
}

impl From<Ready> for UnixReady {
Expand Down Expand Up @@ -330,6 +395,7 @@ impl fmt::Debug for UnixReady {
(UnixReady(Ready::writable()), "Writable"),
(UnixReady::error(), "Error"),
(UnixReady::hup(), "Hup"),
#[allow(deprecated)]
(UnixReady::aio(), "Aio")];

for &(flag, msg) in &flags {
Expand Down

0 comments on commit 00d8573

Please sign in to comment.