Skip to content

Commit

Permalink
Add os-ext feature
Browse files Browse the repository at this point in the history
Deprecating the pipe and os-util features.
  • Loading branch information
Thomasdezeeuw committed Nov 3, 2020
1 parent cf826bf commit f5017fa
Show file tree
Hide file tree
Showing 10 changed files with 53 additions and 65 deletions.
7 changes: 5 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,10 @@ include = [
# By default Mio only provides a shell implementation.
default = []

# Enables the `Poll` and `Registry` types.
os-poll = []
os-util = []
pipe = ["os-poll"]
# Enables additional OS specific extensions, e.g. Unix `pipe(2)`.
os-ext = ["os-poll"]
# Enables `mio::net` module containing networking primitives.
net = []

Expand All @@ -41,6 +42,8 @@ extra-docs = [] # Docs are now always present.
tcp = ["net"] # Replaced with "net" feature.
udp = ["net"] # Replaced with "net" feature.
uds = ["net"] # Replaced with "net" feature.
pipe = ["os-ext"] # Replaced with "os-ext" feature.
os-util = ["os-ext"]# Replaced with "os-ext" feature.

[dependencies]
log = "0.4.8"
Expand Down
47 changes: 16 additions & 31 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,37 +68,28 @@ pub use poll::{Poll, Registry};
pub use token::Token;
pub use waker::Waker;

#[cfg(all(unix, any(feature = "os-util", feature = "pipe")))]
#[cfg_attr(
docsrs,
doc(cfg(all(unix, any(feature = "os-util", feature = "pipe"))))
)]
#[cfg(all(unix, feature = "os-ext"))]
#[cfg_attr(docsrs, doc(cfg(all(unix, feature = "os-ext"))))]
pub mod unix {
//! Unix only extensions.

#[cfg(feature = "os-util")]
#[cfg_attr(docsrs, doc(cfg(all(unix, feature = "os-util"))))]
pub use crate::sys::SourceFd;

cfg_pipe! {
pub mod pipe {
//! Unix pipe.
//!
//! See the [`new`] function for documentation.
pub mod pipe {
//! Unix pipe.
//!
//! See the [`new`] function for documentation.

pub use crate::sys::pipe::{new, Receiver, Sender};
}
pub use crate::sys::pipe::{new, Receiver, Sender};
}

pub use crate::sys::SourceFd;
}

#[cfg(all(windows, feature = "os-util"))]
#[cfg_attr(docsrs, doc(cfg(all(windows, feature = "os-util"))))]
#[cfg(all(windows, feature = "os-ext"))]
#[cfg_attr(docsrs, doc(cfg(all(windows, feature = "os-ext"))))]
pub mod windows {
//! Windows only extensions.

cfg_os_poll! {
pub use crate::sys::named_pipe::NamedPipe;
}
pub use crate::sys::named_pipe::NamedPipe;
}

pub mod features {
Expand All @@ -115,17 +106,11 @@ pub mod features {
//!
//! This makes `Poll`, `Registry` and `Waker` functional.
//!
#![cfg_attr(feature = "os-util", doc = "## `os-util` (enabled)")]
#![cfg_attr(not(feature = "os-util"), doc = "## `os-util` (disabled)")]
//!
//! `os-util` enables additional OS specific facilities. Currently this
//! means the `unix` module (with `SourceFd`) becomes available.
//!
#![cfg_attr(feature = "pipe", doc = "## `pipe` (enabled)")]
#![cfg_attr(not(feature = "pipe"), doc = "## `pipe` (disabled)")]
#![cfg_attr(feature = "os-ext", doc = "## `os-ext` (enabled)")]
#![cfg_attr(not(feature = "os-ext"), doc = "## `os-ext` (disabled)")]
//!
//! The `pipe` feature adds `unix::pipe`, and related types, a non-blocking
//! wrapper around the `pipe(2)` system call.
//! `os-ext` enables additional OS specific facilities. These facilities can
//! be found in the `unix` and `windows` module.
//!
#![cfg_attr(feature = "net", doc = "## Network types (enabled)")]
#![cfg_attr(not(feature = "net"), doc = "## Network types (disabled)")]
Expand Down
39 changes: 19 additions & 20 deletions src/macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
// Depending on the features not all macros are used.
#![allow(unused_macros)]

/// Feature `os-poll` enabled.
/// The `os-poll` feature is enabled.
macro_rules! cfg_os_poll {
($($item:item)*) => {
$(
Expand All @@ -14,7 +14,7 @@ macro_rules! cfg_os_poll {
}
}

/// Feature `os-poll` disabled.
/// The `os-poll` feature is disabled.
macro_rules! cfg_not_os_poll {
($($item:item)*) => {
$(
Expand All @@ -24,47 +24,46 @@ macro_rules! cfg_not_os_poll {
}
}

/// The `net` feature is enabled.
macro_rules! cfg_net {
/// The `os-ext` feature is enabled.
macro_rules! cfg_os_ext {
($($item:item)*) => {
$(
#[cfg(feature = "net")]
#[cfg_attr(docsrs, doc(cfg(feature = "net")))]
#[cfg(feature = "os-ext")]
#[cfg_attr(docsrs, doc(cfg(feature = "os-ext")))]
$item
)*
}
}

/// One of the features enabled that needs `IoSource`. That is `net` or `pipe`
/// (on Unix).
macro_rules! cfg_io_source {
/// The `net` feature is enabled.
macro_rules! cfg_net {
($($item:item)*) => {
$(
#[cfg(any(feature = "net", all(unix, feature = "pipe")))]
#[cfg_attr(docsrs, doc(any(feature = "net", all(unix, feature = "pipe"))))]
#[cfg(feature = "net")]
#[cfg_attr(docsrs, doc(cfg(feature = "net")))]
$item
)*
}
}

/// Feature `pipe` enabled.
#[cfg(unix)]
macro_rules! cfg_pipe {
/// One of the features enabled that needs `IoSource`. That is `net` or `os-ext`
/// on Unix (for `pipe`).
macro_rules! cfg_io_source {
($($item:item)*) => {
$(
#[cfg(feature = "pipe")]
#[cfg_attr(docsrs, doc(cfg(feature = "pipe")))]
#[cfg(any(feature = "net", all(unix, feature = "os-ext")))]
#[cfg_attr(docsrs, doc(any(feature = "net", all(unix, feature = "os-ext"))))]
$item
)*
}
}

/// Feature `os-util` enabled, or one of the features that need `os-util`.
macro_rules! cfg_any_os_util {
/// The `os-ext` feature is enabled, or one of the features that need `os-ext`.
macro_rules! cfg_any_os_ext {
($($item:item)*) => {
$(
#[cfg(any(feature = "os-util", feature = "net", all(unix, feature = "pipe")))]
#[cfg_attr(docsrs, doc(cfg(any(feature = "os-util", feature = "net", all(unix, feature = "pipe")))))]
#[cfg(any(feature = "os-ext", feature = "net"))]
#[cfg_attr(docsrs, doc(cfg(any(feature = "os-ext", feature = "net"))))]
$item
)*
}
Expand Down
2 changes: 1 addition & 1 deletion src/sys/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ cfg_not_os_poll! {
pub(crate) use self::shell::*;

#[cfg(unix)]
cfg_any_os_util! {
cfg_any_os_ext! {
mod unix;
pub use self::unix::SourceFd;
}
Expand Down
2 changes: 1 addition & 1 deletion src/sys/shell/selector.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ impl Selector {
}

#[cfg(unix)]
cfg_any_os_util! {
cfg_any_os_ext! {
use crate::{Interest, Token};

impl Selector {
Expand Down
4 changes: 2 additions & 2 deletions src/sys/unix/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ cfg_os_poll! {
}
}

cfg_pipe! {
cfg_os_ext! {
pub(crate) mod pipe;
}
}
Expand All @@ -65,7 +65,7 @@ cfg_not_os_poll! {
pub use self::uds::SocketAddr;
}

cfg_any_os_util! {
cfg_any_os_ext! {
mod sourcefd;
pub use self::sourcefd::SourceFd;
}
Expand Down
2 changes: 1 addition & 1 deletion src/sys/windows/event.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ impl Event {
self.flags |= afd::POLL_RECEIVE
}

#[cfg(feature = "os-util")]
#[cfg(feature = "os-ext")]
pub(super) fn set_writable(&mut self) {
self.flags |= afd::POLL_SEND;
}
Expand Down
5 changes: 3 additions & 2 deletions src/sys/windows/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,9 @@ cfg_net! {
pub(crate) mod udp;
}

#[cfg(feature = "os-util")]
pub(crate) mod named_pipe;
cfg_os_ext! {
pub(crate) mod named_pipe;
}

mod waker;
pub(crate) use waker::Waker;
Expand Down
6 changes: 3 additions & 3 deletions src/sys/windows/overlapped.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,17 @@ use crate::sys::windows::Event;
use std::cell::UnsafeCell;
use std::fmt;

use winapi::um::minwinbase::OVERLAPPED_ENTRY;
#[cfg(feature = "os-util")]
#[cfg(feature = "os-ext")]
use winapi::um::minwinbase::OVERLAPPED;
use winapi::um::minwinbase::OVERLAPPED_ENTRY;

#[repr(C)]
pub(crate) struct Overlapped {
inner: UnsafeCell<miow::Overlapped>,
pub(crate) callback: fn(&OVERLAPPED_ENTRY, Option<&mut Vec<Event>>),
}

#[cfg(feature = "os-util")]
#[cfg(feature = "os-ext")]
impl Overlapped {
pub(crate) fn new(cb: fn(&OVERLAPPED_ENTRY, Option<&mut Vec<Event>>)) -> Overlapped {
Overlapped {
Expand Down
4 changes: 2 additions & 2 deletions src/sys/windows/selector.rs
Original file line number Diff line number Diff line change
Expand Up @@ -374,7 +374,7 @@ impl Selector {
self.inner.cp.clone()
}

#[cfg(feature = "os-util")]
#[cfg(feature = "os-ext")]
pub(super) fn same_port(&self, other: &Arc<CompletionPort>) -> bool {
Arc::ptr_eq(&self.inner.cp, other)
}
Expand Down Expand Up @@ -749,4 +749,4 @@ cfg_net! {

flags
}
}
}

0 comments on commit f5017fa

Please sign in to comment.