Skip to content

Commit

Permalink
net: merge tcp, udp, uds features to net feature (#2943)
Browse files Browse the repository at this point in the history
  • Loading branch information
taiki-e committed Oct 12, 2020
1 parent 8880222 commit 891de32
Show file tree
Hide file tree
Showing 17 changed files with 53 additions and 90 deletions.
13 changes: 9 additions & 4 deletions tokio/Cargo.toml
Expand Up @@ -52,7 +52,15 @@ io-util = ["memchr"]
# stdin, stdout, stderr
io-std = []
macros = ["tokio-macros"]
net = ["dns", "tcp", "udp", "uds"]
net = [
"dns",
"lazy_static",
"libc",
"mio/os-poll",
"mio/tcp",
"mio/udp",
"mio/uds",
]
process = [
"lazy_static",
"libc",
Expand Down Expand Up @@ -80,10 +88,7 @@ signal = [
stream = ["futures-core"]
sync = ["fnv"]
test-util = []
tcp = ["lazy_static", "mio/tcp", "mio/os-poll"]
time = []
udp = ["lazy_static", "mio/udp", "mio/os-poll"]
uds = ["lazy_static", "libc", "mio/uds", "mio/os-poll"]

[dependencies]
tokio-macros = { version = "0.3.0", path = "../tokio-macros", optional = true }
Expand Down
4 changes: 2 additions & 2 deletions tokio/src/io/driver/scheduled_io.rs
Expand Up @@ -32,7 +32,7 @@ cfg_io_readiness! {

#[derive(Debug, Default)]
struct Waiters {
#[cfg(any(feature = "tcp", feature = "udp", feature = "uds"))]
#[cfg(feature = "net")]
/// List of all current waiters
list: WaitList,

Expand Down Expand Up @@ -220,7 +220,7 @@ impl ScheduledIo {
}
}

#[cfg(any(feature = "tcp", feature = "udp", feature = "uds"))]
#[cfg(feature = "net")]
'outer: loop {
let mut iter = waiters.list.drain_filter(|w| ready.satisfies(w.interest));

Expand Down
8 changes: 1 addition & 7 deletions tokio/src/io/poll_evented.rs
Expand Up @@ -124,13 +124,7 @@ impl<E: Source> PollEvented<E> {

/// Returns a shared reference to the underlying I/O object this readiness
/// stream is wrapping.
#[cfg(any(
feature = "process",
feature = "tcp",
feature = "udp",
feature = "uds",
feature = "signal"
))]
#[cfg(any(feature = "net", feature = "process", feature = "signal"))]
pub(crate) fn get_ref(&self) -> &E {
self.io.as_ref().unwrap()
}
Expand Down
5 changes: 1 addition & 4 deletions tokio/src/lib.rs
Expand Up @@ -79,9 +79,6 @@
//! - `io-util`: Enables the IO based `Ext` traits.
//! - `io-std`: Enable `Stdout`, `Stdin` and `Stderr` types.
//! - `net`: Enables `tokio::net` types such as `TcpStream`, `UnixStream` and `UdpSocket`.
//! - `tcp`: Enables all `tokio::net::tcp` types.
//! - `udp`: Enables all `tokio::net::udp` types.
//! - `uds`: Enables all `tokio::net::unix` types.
//! - `time`: Enables `tokio::time` types and allows the schedulers to enable
//! the built in timer.
//! - `process`: Enables `tokio::process` types.
Expand Down Expand Up @@ -137,7 +134,7 @@
//! needs to `tokio::spawn` and use a `TcpStream`.
//!
//! ```toml
//! tokio = { version = "0.2", features = ["rt-core", "tcp"] }
//! tokio = { version = "0.2", features = ["rt-core", "net"] }
//! ```
//!
//! ## Working With Tasks
Expand Down
4 changes: 1 addition & 3 deletions tokio/src/loom/std/mod.rs
Expand Up @@ -16,12 +16,10 @@ pub(crate) mod cell {
}

#[cfg(any(
feature = "net",
feature = "process",
feature = "signal",
feature = "sync",
feature = "tcp",
feature = "udp",
feature = "uds",
))]
pub(crate) mod future {
pub(crate) use crate::sync::AtomicWaker;
Expand Down
72 changes: 26 additions & 46 deletions tokio/src/macros/cfg.rs
Expand Up @@ -20,13 +20,11 @@ macro_rules! cfg_atomic_waker_impl {
($($item:item)*) => {
$(
#[cfg(any(
feature = "net",
feature = "process",
feature = "rt-util",
feature = "signal",
feature = "tcp",
feature = "time",
feature = "udp",
feature = "uds",
))]
#[cfg(not(loom))]
$item
Expand Down Expand Up @@ -64,18 +62,14 @@ macro_rules! cfg_io_driver {
($($item:item)*) => {
$(
#[cfg(any(
feature = "net",
feature = "process",
all(unix, feature = "signal"),
feature = "tcp",
feature = "udp",
feature = "uds",
))]
#[cfg_attr(docsrs, doc(cfg(any(
feature = "net",
feature = "process",
all(unix, feature = "signal"),
feature = "tcp",
feature = "udp",
feature = "uds",
))))]
$item
)*
Expand All @@ -86,11 +80,9 @@ macro_rules! cfg_not_io_driver {
($($item:item)*) => {
$(
#[cfg(not(any(
feature = "net",
feature = "process",
all(unix, feature = "signal"),
feature = "tcp",
feature = "udp",
feature = "uds",
)))]
$item
)*
Expand All @@ -100,7 +92,7 @@ macro_rules! cfg_not_io_driver {
macro_rules! cfg_io_readiness {
($($item:item)*) => {
$(
#[cfg(any(feature = "udp", feature = "uds", feature = "tcp"))]
#[cfg(feature = "net")]
$item
)*
}
Expand Down Expand Up @@ -155,6 +147,26 @@ macro_rules! cfg_macros {
}
}

macro_rules! cfg_net {
($($item:item)*) => {
$(
#[cfg(feature = "net")]
#[cfg_attr(docsrs, doc(cfg(feature = "net")))]
$item
)*
}
}

macro_rules! cfg_net_unix {
($($item:item)*) => {
$(
#[cfg(all(unix, feature = "net"))]
#[cfg_attr(docsrs, doc(cfg(feature = "net")))]
$item
)*
}
}

macro_rules! cfg_process {
($($item:item)*) => {
$(
Expand Down Expand Up @@ -300,16 +312,6 @@ macro_rules! cfg_not_rt_threaded {
}
}

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

macro_rules! cfg_test_util {
($($item:item)*) => {
$(
Expand Down Expand Up @@ -342,26 +344,6 @@ macro_rules! cfg_not_time {
}
}

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

macro_rules! cfg_uds {
($($item:item)*) => {
$(
#[cfg(all(unix, feature = "uds"))]
#[cfg_attr(docsrs, doc(cfg(feature = "uds")))]
$item
)*
}
}

macro_rules! cfg_trace {
($($item:item)*) => {
$(
Expand All @@ -388,16 +370,14 @@ macro_rules! cfg_coop {
feature = "dns",
feature = "fs",
feature = "io-std",
feature = "net",
feature = "process",
feature = "rt-core",
feature = "rt-util",
feature = "signal",
feature = "sync",
feature = "stream",
feature = "tcp",
feature = "time",
feature = "udp",
feature = "uds",
))]
$item
)*
Expand Down
2 changes: 1 addition & 1 deletion tokio/src/net/addr.rs
Expand Up @@ -23,7 +23,7 @@ pub trait ToSocketAddrs: sealed::ToSocketAddrsPriv {}

type ReadyFuture<T> = future::Ready<io::Result<T>>;

#[cfg(any(feature = "dns", feature = "tcp", feature = "udp"))]
#[cfg(any(feature = "dns", feature = "net"))]
pub(crate) fn to_socket_addrs<T>(arg: T) -> T::Future
where
T: ToSocketAddrs,
Expand Down
8 changes: 3 additions & 5 deletions tokio/src/net/mod.rs
Expand Up @@ -23,7 +23,7 @@
//! [`UnixDatagram`]: UnixDatagram

mod addr;
#[cfg(any(feature = "tcp", feature = "udp"))]
#[cfg(feature = "net")]
pub(crate) use addr::to_socket_addrs;
pub use addr::ToSocketAddrs;

Expand All @@ -32,19 +32,17 @@ cfg_dns! {
pub use lookup_host::lookup_host;
}

cfg_tcp! {
cfg_net! {
pub mod tcp;
pub use tcp::listener::TcpListener;
pub use tcp::socket::TcpSocket;
pub use tcp::stream::TcpStream;
}

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

cfg_uds! {
cfg_net_unix! {
pub mod unix;
pub use unix::datagram::socket::UnixDatagram;
pub use unix::listener::UnixListener;
Expand Down
2 changes: 1 addition & 1 deletion tokio/src/net/tcp/listener.rs
Expand Up @@ -8,7 +8,7 @@ use std::io;
use std::net::{self, SocketAddr};
use std::task::{Context, Poll};

cfg_tcp! {
cfg_net! {
/// A TCP socket server, listening for connections.
///
/// You can accept a new connection by using the [`accept`](`TcpListener::accept`) method. Alternatively `TcpListener`
Expand Down
2 changes: 1 addition & 1 deletion tokio/src/net/tcp/stream.rs
Expand Up @@ -11,7 +11,7 @@ use std::net::{Shutdown, SocketAddr};
use std::pin::Pin;
use std::task::{Context, Poll};

cfg_tcp! {
cfg_net! {
/// A TCP stream between a local and a remote socket.
///
/// A TCP stream can either be created by connecting to an endpoint, via the
Expand Down
2 changes: 1 addition & 1 deletion tokio/src/net/udp/socket.rs
Expand Up @@ -6,7 +6,7 @@ use std::fmt;
use std::io;
use std::net::{self, Ipv4Addr, Ipv6Addr, SocketAddr};

cfg_udp! {
cfg_net! {
/// A UDP socket
///
/// UDP is "connectionless", unlike TCP. Meaning, regardless of what address you've bound to, a `UdpSocket`
Expand Down
2 changes: 1 addition & 1 deletion tokio/src/net/unix/datagram/socket.rs
Expand Up @@ -9,7 +9,7 @@ use std::os::unix::io::{AsRawFd, RawFd};
use std::os::unix::net;
use std::path::Path;

cfg_uds! {
cfg_net_unix! {
/// An I/O object representing a Unix datagram socket.
///
/// A socket can be either named (associated with a filesystem path) or
Expand Down
4 changes: 2 additions & 2 deletions tokio/src/net/unix/listener.rs
Expand Up @@ -9,7 +9,7 @@ use std::os::unix::net;
use std::path::Path;
use std::task::{Context, Poll};

cfg_uds! {
cfg_net_unix! {
/// A Unix socket which can accept connections from other Unix sockets.
///
/// You can accept a new connection by using the [`accept`](`UnixListener::accept`) method. Alternatively `UnixListener`
Expand Down Expand Up @@ -112,7 +112,7 @@ impl UnixListener {
/// Polls to accept a new incoming connection to this listener.
///
/// If there is no connection to accept, `Poll::Pending` is returned and
/// the current task will be notified by a waker.
/// the current task will be notified by a waker.
///
/// When ready, the most recent task that called `poll_accept` is notified.
/// The caller is responsble to ensure that `poll_accept` is called from a
Expand Down
2 changes: 1 addition & 1 deletion tokio/src/net/unix/stream.rs
Expand Up @@ -15,7 +15,7 @@ use std::path::Path;
use std::pin::Pin;
use std::task::{Context, Poll};

cfg_uds! {
cfg_net_unix! {
/// A structure representing a connected Unix socket.
///
/// This socket can be connected directly with `UnixStream::connect` or accepted
Expand Down
8 changes: 1 addition & 7 deletions tokio/src/runtime/builder.rs
Expand Up @@ -139,13 +139,7 @@ impl Builder {
/// .unwrap();
/// ```
pub fn enable_all(&mut self) -> &mut Self {
#[cfg(any(
feature = "process",
all(unix, feature = "signal"),
feature = "tcp",
feature = "udp",
feature = "uds",
))]
#[cfg(any(feature = "net", feature = "process", all(unix, feature = "signal")))]
self.enable_io();
#[cfg(feature = "time")]
self.enable_time();
Expand Down
1 change: 0 additions & 1 deletion tokio/src/util/linked_list.rs
Expand Up @@ -108,7 +108,6 @@ impl<L: Link> LinkedList<L, L::Target> {

/// Removes the last element from a list and returns it, or None if it is
/// empty.
#[cfg_attr(any(feature = "udp", feature = "uds"), allow(unused))]
pub(crate) fn pop_back(&mut self) -> Option<L::Handle> {
unsafe {
let last = self.tail?;
Expand Down
4 changes: 1 addition & 3 deletions tokio/src/util/mod.rs
Expand Up @@ -5,14 +5,12 @@ cfg_io_driver! {

#[cfg(any(
feature = "fs",
feature = "net",
feature = "process",
feature = "rt-core",
feature = "rt-util",
feature = "sync",
feature = "signal",
feature = "tcp",
feature = "udp",
feature = "uds",
))]
pub(crate) mod linked_list;

Expand Down

0 comments on commit 891de32

Please sign in to comment.