summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTaiki Endo <te316e89@gmail.com>2020-10-13 03:36:26 +0900
committerGitHub <noreply@github.com>2020-10-13 03:36:26 +0900
commit891de3271dc3545fb09162e578251e9977d9789c (patch)
tree0c2b4f500c0bf7dc85a78d51ac4860130329d166
parent8880222036f37c6204c8466f25e828447f16dacb (diff)
net: merge tcp, udp, uds features to net feature (#2943)
-rw-r--r--tokio/Cargo.toml13
-rw-r--r--tokio/src/io/driver/scheduled_io.rs4
-rw-r--r--tokio/src/io/poll_evented.rs8
-rw-r--r--tokio/src/lib.rs5
-rw-r--r--tokio/src/loom/std/mod.rs4
-rw-r--r--tokio/src/macros/cfg.rs72
-rw-r--r--tokio/src/net/addr.rs2
-rw-r--r--tokio/src/net/mod.rs8
-rw-r--r--tokio/src/net/tcp/listener.rs2
-rw-r--r--tokio/src/net/tcp/stream.rs2
-rw-r--r--tokio/src/net/udp/socket.rs2
-rw-r--r--tokio/src/net/unix/datagram/socket.rs2
-rw-r--r--tokio/src/net/unix/listener.rs4
-rw-r--r--tokio/src/net/unix/stream.rs2
-rw-r--r--tokio/src/runtime/builder.rs8
-rw-r--r--tokio/src/util/linked_list.rs1
-rw-r--r--tokio/src/util/mod.rs4
17 files changed, 53 insertions, 90 deletions
diff --git a/tokio/Cargo.toml b/tokio/Cargo.toml
index cb407f93..5b361e6b 100644
--- a/tokio/Cargo.toml
+++ b/tokio/Cargo.toml
@@ -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",
@@ -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 }
diff --git a/tokio/src/io/driver/scheduled_io.rs b/tokio/src/io/driver/scheduled_io.rs
index 0c0448c3..b1354a05 100644
--- a/tokio/src/io/driver/scheduled_io.rs
+++ b/tokio/src/io/driver/scheduled_io.rs
@@ -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,
@@ -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));
diff --git a/tokio/src/io/poll_evented.rs b/tokio/src/io/poll_evented.rs
index f253f0bb..66a26346 100644
--- a/tokio/src/io/poll_evented.rs
+++ b/tokio/src/io/poll_evented.rs
@@ -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()
}
diff --git a/tokio/src/lib.rs b/tokio/src/lib.rs
index 1334eb88..92d2c35d 100644
--- a/tokio/src/lib.rs
+++ b/tokio/src/lib.rs
@@ -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.
@@ -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
diff --git a/tokio/src/loom/std/mod.rs b/tokio/src/loom/std/mod.rs
index 6492848e..fc32fc9f 100644
--- a/tokio/src/loom/std/mod.rs
+++ b/tokio/src/loom/std/mod.rs
@@ -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;
diff --git a/tokio/src/macros/cfg.rs b/tokio/src/macros/cfg.rs
index 83102da6..849fb42b 100644
--- a/tokio/src/macros/cfg.rs
+++ b/tokio/src/macros/cfg.rs
@@ -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
@@ -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
)*
@@ -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
)*
@@ -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
)*
}
@@ -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)*) => {
$(
@@ -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)*) => {
$(
@@ -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)*) => {
$(
@@ -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
)*
diff --git a/tokio/src/net/addr.rs b/tokio/src/net/addr.rs
index e2d09d47..86ae9919 100644
--- a/tokio/src/net/addr.rs
+++ b/tokio/src/net/addr.rs
@@ -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,
diff --git a/tokio/src/net/mod.rs b/tokio/src/net/mod.rs
index a91085f8..f355356f 100644
--- a/tokio/src/net/mod.rs
+++ b/tokio/src/net/mod.rs
@@ -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;
@@ -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;
diff --git a/tokio/src/net/tcp/listener.rs b/tokio/src/net/tcp/listener.rs
index 98c8961e..57500615 100644
--- a/tokio/src/net/tcp/listener.rs
+++ b/tokio/src/net/tcp/listener.rs
@@ -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`
diff --git a/tokio/src/net/tcp/stream.rs b/tokio/src/net/tcp/stream.rs
index 0a58e481..7acab7db 100644
--- a/tokio/src/net/tcp/stream.rs
+++ b/tokio/src/net/tcp/stream.rs
@@ -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
diff --git a/tokio/src/net/udp/socket.rs b/tokio/src/net/udp/socket.rs
index 18ae2402..77e5dd43 100644
--- a/tokio/src/net/udp/socket.rs
+++ b/tokio/src/net/udp/socket.rs
@@ -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`
diff --git a/tokio/src/net/unix/datagram/socket.rs b/tokio/src/net/unix/datagram/socket.rs
index 5dcda6c9..3ae66d1f 100644
--- a/tokio/src/net/unix/datagram/socket.rs
+++ b/tokio/src/net/unix/datagram/socket.rs
@@ -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
diff --git a/tokio/src/net/unix/listener.rs b/tokio/src/net/unix/listener.rs
index fb85da9f..b2726456 100644
--- a/tokio/src/net/unix/listener.rs
+++ b/tokio/src/net/unix/listener.rs
@@ -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`
@@ -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
diff --git a/tokio/src/net/unix/stream.rs b/tokio/src/net/unix/stream.rs
index c539f224..5138077b 100644
--- a/tokio/src/net/unix/stream.rs
+++ b/tokio/src/net/unix/stream.rs
@@ -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
diff --git a/tokio/src/runtime/builder.rs b/tokio/src/runtime/builder.rs
index 8e76f52b..f260eac6 100644
--- a/tokio/src/runtime/builder.rs
+++ b/tokio/src/runtime/builder.rs
@@ -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();
diff --git a/tokio/src/util/linked_list.rs b/tokio/src/util/linked_list.rs
index b13fc6b7..b2f8dfc8 100644
--- a/tokio/src/util/linked_list.rs
+++ b/tokio/src/util/linked_list.rs
@@ -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?;
diff --git a/tokio/src/util/mod.rs b/tokio/src/util/mod.rs
index e1bcb4b8..ea6c6715 100644
--- a/tokio/src/util/mod.rs
+++ b/tokio/src/util/mod.rs
@@ -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;