Skip to content

Commit

Permalink
Deprecate the tcp, udp and uds features
Browse files Browse the repository at this point in the history
In favour of a new `net` feature that enables all networking primitives.
  • Loading branch information
Thomasdezeeuw committed Nov 3, 2020
1 parent 25731e8 commit a301ba5
Show file tree
Hide file tree
Showing 10 changed files with 39 additions and 164 deletions.
11 changes: 8 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,17 +25,22 @@ include = [
"examples/**/*.rs",
]

# For documentation of features see the `mio::features` module.
[features]
# By default Mio only provides a shell implementation.
default = []

os-poll = []
os-util = []
pipe = ["os-poll"]
tcp = []
udp = []
uds = []
# Enables `mio::net` module containing networking primitives.
net = []

# Deprecated features, will be removed in a future version.
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.

[dependencies]
log = "0.4.8"
Expand Down
17 changes: 3 additions & 14 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -127,21 +127,10 @@ pub mod features {
//! The `pipe` feature adds `unix::pipe`, and related types, a non-blocking
//! wrapper around the `pipe(2)` system call.
//!
//! ## Network types
#![cfg_attr(feature = "net", doc = "## Network types (enabled)")]
#![cfg_attr(not(feature = "net"), doc = "## Network types (disabled)")]
//!
//! Mio provide three features to enable network types:
//!
#![cfg_attr(feature = "tcp", doc = "* `tcp` (enabled)")]
#![cfg_attr(not(feature = "tcp"), doc = "* `tcp` (disabled)")]
//! : includes `TcpStream` and `TcpListener`,
#![cfg_attr(feature = "udp", doc = "* `udp` (enabled)")]
#![cfg_attr(not(feature = "udp"), doc = "* `udp` (disabled)")]
//! : includes `UdpSocket`, and
#![cfg_attr(feature = "uds", doc = "* `uds` (enabled)")]
#![cfg_attr(not(feature = "uds"), doc = "* `uds` (disabled)")]
//! : includes `UnixDatagram`, `UnixListener`, `UnixStream` and `SocketAddr`.
//!
//! All types can be found in the `net` module.
//! The `net` feature enables networking primitives in the `net` module.
}

pub mod guide {
Expand Down
78 changes: 9 additions & 69 deletions src/macros/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,71 +24,24 @@ macro_rules! cfg_not_os_poll {
}
}

/// One of the `tcp`, `udp`, `uds` features enabled.
#[cfg(unix)]
/// The `net` feature is enabled.
macro_rules! cfg_net {
($($item:item)*) => {
$(
#[cfg(any(feature = "tcp", feature = "udp", feature = "uds"))]
#[cfg_attr(docsrs, doc(cfg(any(feature = "tcp", feature = "udp", feature = "uds"))))]
#[cfg(feature = "net")]
#[cfg_attr(docsrs, doc(cfg(feature = "net")))]
$item
)*
}
}

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

/// One of the `tcp`, `udp` features enabled.
#[cfg(windows)]
macro_rules! cfg_net {
($($item:item)*) => {
$(
#[cfg(any(feature = "tcp", feature = "udp"))]
#[cfg_attr(docsrs, doc(cfg(any(feature = "tcp", feature = "udp"))))]
$item
)*
}
}

/// Feature `tcp` enabled.
macro_rules! cfg_tcp {
($($item:item)*) => {
$(
#[cfg(feature = "tcp")]
#[cfg_attr(docsrs, doc(cfg(feature = "tcp")))]
$item
)*
}
}

/// Feature `udp` enabled.
macro_rules! cfg_udp {
($($item:item)*) => {
$(
#[cfg(feature = "udp")]
#[cfg_attr(docsrs, doc(cfg(feature = "udp")))]
$item
)*
}
}

/// Feature `uds` enabled.
#[cfg(unix)]
macro_rules! cfg_uds {
($($item:item)*) => {
$(
#[cfg(feature = "uds")]
#[cfg_attr(docsrs, doc(cfg(feature = "uds")))]
#[cfg(any(feature = "net", all(unix, feature = "pipe")))]
#[cfg_attr(docsrs, doc(any(feature = "net", all(unix, feature = "pipe"))))]
$item
)*
}
Expand All @@ -107,24 +60,11 @@ macro_rules! cfg_pipe {
}

/// Feature `os-util` enabled, or one of the features that need `os-util`.
#[cfg(unix)]
macro_rules! cfg_any_os_util {
($($item:item)*) => {
$(
#[cfg(any(feature = "os-util", feature = "tcp", feature = "udp", feature = "uds", feature = "pipe"))]
#[cfg_attr(docsrs, doc(cfg(any(feature = "os-util", feature = "tcp", feature = "udp", feature = "uds", feature = "pipe"))))]
$item
)*
}
}

/// Feature `os-util` enabled, or one of the features that need `os-util`.
#[cfg(windows)]
macro_rules! cfg_any_os_util {
($($item:item)*) => {
$(
#[cfg(any(feature = "os-util", feature = "tcp", feature = "udp", feature = "pipe"))]
#[cfg_attr(docsrs, doc(cfg(any(feature = "os-util", feature = "tcp", feature = "udp", feature = "pipe"))))]
#[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")))))]
$item
)*
}
Expand Down
21 changes: 8 additions & 13 deletions src/net/mod.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//! Networking primitives
//! Networking primitives.
//!
//! The types provided in this module are non-blocking by default and are
//! designed to be portable across all supported Mio platforms. As long as the
Expand All @@ -7,18 +7,13 @@
//!
//! [portability guidelines]: ../struct.Poll.html#portability

cfg_tcp! {
mod tcp;
pub use self::tcp::{TcpListener, TcpSocket, TcpStream};
}
mod tcp;
pub use self::tcp::{TcpListener, TcpSocket, TcpStream};

cfg_udp! {
mod udp;
pub use self::udp::UdpSocket;
}
mod udp;
pub use self::udp::UdpSocket;

#[cfg(unix)]
cfg_uds! {
mod uds;
pub use self::uds::{SocketAddr, UnixDatagram, UnixListener, UnixStream};
}
mod uds;
#[cfg(unix)]
pub use self::uds::{SocketAddr, UnixDatagram, UnixListener, UnixStream};
28 changes: 2 additions & 26 deletions src/sys/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,31 +54,7 @@ cfg_os_poll! {
#[cfg(unix)]
cfg_os_poll! {
mod unix;
pub use self::unix::SourceFd;

pub(crate) use self::unix::{event, Event, Events, Selector, Waker};

cfg_tcp! {
pub(crate) use self::unix::tcp;
}

cfg_udp! {
pub(crate) use self::unix::udp;
}

cfg_uds! {
pub use self::unix::SocketAddr;

pub(crate) use self::unix::uds;
}

cfg_pipe! {
pub(crate) use self::unix::pipe;
}

cfg_io_source! {
pub(crate) use self::unix::IoSourceState;
}
pub use self::unix::*;
}

#[cfg(windows)]
Expand All @@ -98,7 +74,7 @@ cfg_not_os_poll! {
}

#[cfg(unix)]
cfg_uds! {
cfg_net! {
pub use self::unix::SocketAddr;
}
}
10 changes: 2 additions & 8 deletions src/sys/shell/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,10 @@ pub(crate) use self::selector::{event, Event, Events, Selector};
mod waker;
pub(crate) use self::waker::Waker;

cfg_tcp! {
cfg_net! {
pub(crate) mod tcp;
}

cfg_udp! {
pub(crate) mod udp;
}

#[cfg(unix)]
cfg_uds! {
#[cfg(unix)]
pub(crate) mod uds;
}

Expand Down
14 changes: 4 additions & 10 deletions src/sys/unix/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@ macro_rules! syscall {
}

cfg_os_poll! {
mod net;

mod selector;
pub(crate) use self::selector::{event, Event, Events, Selector};

Expand All @@ -25,15 +23,11 @@ cfg_os_poll! {
mod waker;
pub(crate) use self::waker::Waker;

cfg_tcp! {
pub(crate) mod tcp;
}
cfg_net! {
mod net;

cfg_udp! {
pub(crate) mod tcp;
pub(crate) mod udp;
}

cfg_uds! {
pub(crate) mod uds;
pub use self::uds::SocketAddr;
}
Expand Down Expand Up @@ -66,7 +60,7 @@ cfg_os_poll! {
}

cfg_not_os_poll! {
cfg_uds! {
cfg_net! {
mod uds;
pub use self::uds::SocketAddr;
}
Expand Down
8 changes: 0 additions & 8 deletions src/sys/unix/net.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
#[cfg(all(feature = "os-poll", any(feature = "tcp", feature = "udp")))]
use std::net::SocketAddr;

#[cfg(all(feature = "os-poll", any(feature = "udp")))]
pub(crate) fn new_ip_socket(
addr: SocketAddr,
socket_type: libc::c_int,
Expand All @@ -15,10 +13,6 @@ pub(crate) fn new_ip_socket(
}

/// Create a new non-blocking socket.
#[cfg(all(
feature = "os-poll",
any(feature = "tcp", feature = "udp", feature = "uds")
))]
pub(crate) fn new_socket(
domain: libc::c_int,
socket_type: libc::c_int,
Expand Down Expand Up @@ -70,7 +64,6 @@ pub(crate) fn new_socket(
socket
}

#[cfg(all(feature = "os-poll", any(feature = "tcp", feature = "udp")))]
pub(crate) fn socket_addr(addr: &SocketAddr) -> (*const libc::sockaddr, libc::socklen_t) {
use std::mem::size_of_val;

Expand All @@ -87,7 +80,6 @@ pub(crate) fn socket_addr(addr: &SocketAddr) -> (*const libc::sockaddr, libc::so
}

/// `storage` must be initialised to `sockaddr_in` or `sockaddr_in6`.
#[cfg(all(feature = "os-poll", feature = "tcp"))]
pub(crate) unsafe fn to_socket_addr(
storage: *const libc::sockaddr_storage,
) -> std::io::Result<SocketAddr> {
Expand Down
11 changes: 2 additions & 9 deletions src/sys/windows/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,10 @@ cfg_net! {
}
}};
}
}

cfg_tcp! {
pub(crate) mod tcp;
}
mod net;

cfg_udp! {
pub(crate) mod tcp;
pub(crate) mod udp;
}

Expand All @@ -41,10 +38,6 @@ pub(crate) mod named_pipe;
mod waker;
pub(crate) use waker::Waker;

cfg_net! {
mod net;
}

cfg_io_source! {
use std::io;
use std::os::windows::io::RawSocket;
Expand Down
5 changes: 1 addition & 4 deletions src/sys/windows/net.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,7 @@ use std::sync::Once;

use winapi::ctypes::c_int;
use winapi::shared::ws2def::SOCKADDR;
use winapi::um::winsock2::{
ioctlsocket, socket, FIONBIO, INVALID_SOCKET, SOCKET,
};
use winapi::um::winsock2::{ioctlsocket, socket, FIONBIO, INVALID_SOCKET, SOCKET};

/// Initialise the network stack for Windows.
pub(crate) fn init() {
Expand All @@ -21,7 +19,6 @@ pub(crate) fn init() {
}

/// Create a new non-blocking socket.
#[cfg(feature = "udp")]
pub(crate) fn new_ip_socket(addr: SocketAddr, socket_type: c_int) -> io::Result<SOCKET> {
use winapi::um::winsock2::{PF_INET, PF_INET6};

Expand Down

0 comments on commit a301ba5

Please sign in to comment.