net: merge tcp, udp, uds features to net feature (#2943)

This commit is contained in:
Taiki Endo
2020-10-13 03:36:26 +09:00
committed by GitHub
parent 8880222036
commit 891de3271d
17 changed files with 53 additions and 90 deletions
+9 -4
View File
@@ -52,7 +52,15 @@ io-util = ["memchr"]
# stdin, stdout, stderr # stdin, stdout, stderr
io-std = [] io-std = []
macros = ["tokio-macros"] macros = ["tokio-macros"]
net = ["dns", "tcp", "udp", "uds"] net = [
"dns",
"lazy_static",
"libc",
"mio/os-poll",
"mio/tcp",
"mio/udp",
"mio/uds",
]
process = [ process = [
"lazy_static", "lazy_static",
"libc", "libc",
@@ -80,10 +88,7 @@ signal = [
stream = ["futures-core"] stream = ["futures-core"]
sync = ["fnv"] sync = ["fnv"]
test-util = [] test-util = []
tcp = ["lazy_static", "mio/tcp", "mio/os-poll"]
time = [] time = []
udp = ["lazy_static", "mio/udp", "mio/os-poll"]
uds = ["lazy_static", "libc", "mio/uds", "mio/os-poll"]
[dependencies] [dependencies]
tokio-macros = { version = "0.3.0", path = "../tokio-macros", optional = true } tokio-macros = { version = "0.3.0", path = "../tokio-macros", optional = true }
+2 -2
View File
@@ -32,7 +32,7 @@ cfg_io_readiness! {
#[derive(Debug, Default)] #[derive(Debug, Default)]
struct Waiters { struct Waiters {
#[cfg(any(feature = "tcp", feature = "udp", feature = "uds"))] #[cfg(feature = "net")]
/// List of all current waiters /// List of all current waiters
list: WaitList, list: WaitList,
@@ -220,7 +220,7 @@ impl ScheduledIo {
} }
} }
#[cfg(any(feature = "tcp", feature = "udp", feature = "uds"))] #[cfg(feature = "net")]
'outer: loop { 'outer: loop {
let mut iter = waiters.list.drain_filter(|w| ready.satisfies(w.interest)); let mut iter = waiters.list.drain_filter(|w| ready.satisfies(w.interest));
+1 -7
View File
@@ -124,13 +124,7 @@ impl<E: Source> PollEvented<E> {
/// Returns a shared reference to the underlying I/O object this readiness /// Returns a shared reference to the underlying I/O object this readiness
/// stream is wrapping. /// stream is wrapping.
#[cfg(any( #[cfg(any(feature = "net", feature = "process", feature = "signal"))]
feature = "process",
feature = "tcp",
feature = "udp",
feature = "uds",
feature = "signal"
))]
pub(crate) fn get_ref(&self) -> &E { pub(crate) fn get_ref(&self) -> &E {
self.io.as_ref().unwrap() self.io.as_ref().unwrap()
} }
+1 -4
View File
@@ -79,9 +79,6 @@
//! - `io-util`: Enables the IO based `Ext` traits. //! - `io-util`: Enables the IO based `Ext` traits.
//! - `io-std`: Enable `Stdout`, `Stdin` and `Stderr` types. //! - `io-std`: Enable `Stdout`, `Stdin` and `Stderr` types.
//! - `net`: Enables `tokio::net` types such as `TcpStream`, `UnixStream` and `UdpSocket`. //! - `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 //! - `time`: Enables `tokio::time` types and allows the schedulers to enable
//! the built in timer. //! the built in timer.
//! - `process`: Enables `tokio::process` types. //! - `process`: Enables `tokio::process` types.
@@ -137,7 +134,7 @@
//! needs to `tokio::spawn` and use a `TcpStream`. //! needs to `tokio::spawn` and use a `TcpStream`.
//! //!
//! ```toml //! ```toml
//! tokio = { version = "0.2", features = ["rt-core", "tcp"] } //! tokio = { version = "0.2", features = ["rt-core", "net"] }
//! ``` //! ```
//! //!
//! ## Working With Tasks //! ## Working With Tasks
+1 -3
View File
@@ -16,12 +16,10 @@ pub(crate) mod cell {
} }
#[cfg(any( #[cfg(any(
feature = "net",
feature = "process", feature = "process",
feature = "signal", feature = "signal",
feature = "sync", feature = "sync",
feature = "tcp",
feature = "udp",
feature = "uds",
))] ))]
pub(crate) mod future { pub(crate) mod future {
pub(crate) use crate::sync::AtomicWaker; pub(crate) use crate::sync::AtomicWaker;
+26 -46
View File
@@ -20,13 +20,11 @@ macro_rules! cfg_atomic_waker_impl {
($($item:item)*) => { ($($item:item)*) => {
$( $(
#[cfg(any( #[cfg(any(
feature = "net",
feature = "process", feature = "process",
feature = "rt-util", feature = "rt-util",
feature = "signal", feature = "signal",
feature = "tcp",
feature = "time", feature = "time",
feature = "udp",
feature = "uds",
))] ))]
#[cfg(not(loom))] #[cfg(not(loom))]
$item $item
@@ -64,18 +62,14 @@ macro_rules! cfg_io_driver {
($($item:item)*) => { ($($item:item)*) => {
$( $(
#[cfg(any( #[cfg(any(
feature = "net",
feature = "process", feature = "process",
all(unix, feature = "signal"), all(unix, feature = "signal"),
feature = "tcp",
feature = "udp",
feature = "uds",
))] ))]
#[cfg_attr(docsrs, doc(cfg(any( #[cfg_attr(docsrs, doc(cfg(any(
feature = "net",
feature = "process", feature = "process",
all(unix, feature = "signal"), all(unix, feature = "signal"),
feature = "tcp",
feature = "udp",
feature = "uds",
))))] ))))]
$item $item
)* )*
@@ -86,11 +80,9 @@ macro_rules! cfg_not_io_driver {
($($item:item)*) => { ($($item:item)*) => {
$( $(
#[cfg(not(any( #[cfg(not(any(
feature = "net",
feature = "process", feature = "process",
all(unix, feature = "signal"), all(unix, feature = "signal"),
feature = "tcp",
feature = "udp",
feature = "uds",
)))] )))]
$item $item
)* )*
@@ -100,7 +92,7 @@ macro_rules! cfg_not_io_driver {
macro_rules! cfg_io_readiness { macro_rules! cfg_io_readiness {
($($item:item)*) => { ($($item:item)*) => {
$( $(
#[cfg(any(feature = "udp", feature = "uds", feature = "tcp"))] #[cfg(feature = "net")]
$item $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 { macro_rules! cfg_process {
($($item:item)*) => { ($($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 { macro_rules! cfg_test_util {
($($item:item)*) => { ($($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 { macro_rules! cfg_trace {
($($item:item)*) => { ($($item:item)*) => {
$( $(
@@ -388,16 +370,14 @@ macro_rules! cfg_coop {
feature = "dns", feature = "dns",
feature = "fs", feature = "fs",
feature = "io-std", feature = "io-std",
feature = "net",
feature = "process", feature = "process",
feature = "rt-core", feature = "rt-core",
feature = "rt-util", feature = "rt-util",
feature = "signal", feature = "signal",
feature = "sync", feature = "sync",
feature = "stream", feature = "stream",
feature = "tcp",
feature = "time", feature = "time",
feature = "udp",
feature = "uds",
))] ))]
$item $item
)* )*
+1 -1
View File
@@ -23,7 +23,7 @@ pub trait ToSocketAddrs: sealed::ToSocketAddrsPriv {}
type ReadyFuture<T> = future::Ready<io::Result<T>>; 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 pub(crate) fn to_socket_addrs<T>(arg: T) -> T::Future
where where
T: ToSocketAddrs, T: ToSocketAddrs,
+3 -5
View File
@@ -23,7 +23,7 @@
//! [`UnixDatagram`]: UnixDatagram //! [`UnixDatagram`]: UnixDatagram
mod addr; mod addr;
#[cfg(any(feature = "tcp", feature = "udp"))] #[cfg(feature = "net")]
pub(crate) use addr::to_socket_addrs; pub(crate) use addr::to_socket_addrs;
pub use addr::ToSocketAddrs; pub use addr::ToSocketAddrs;
@@ -32,19 +32,17 @@ cfg_dns! {
pub use lookup_host::lookup_host; pub use lookup_host::lookup_host;
} }
cfg_tcp! { cfg_net! {
pub mod tcp; pub mod tcp;
pub use tcp::listener::TcpListener; pub use tcp::listener::TcpListener;
pub use tcp::socket::TcpSocket; pub use tcp::socket::TcpSocket;
pub use tcp::stream::TcpStream; pub use tcp::stream::TcpStream;
}
cfg_udp! {
pub mod udp; pub mod udp;
pub use udp::socket::UdpSocket; pub use udp::socket::UdpSocket;
} }
cfg_uds! { cfg_net_unix! {
pub mod unix; pub mod unix;
pub use unix::datagram::socket::UnixDatagram; pub use unix::datagram::socket::UnixDatagram;
pub use unix::listener::UnixListener; pub use unix::listener::UnixListener;
+1 -1
View File
@@ -8,7 +8,7 @@ use std::io;
use std::net::{self, SocketAddr}; use std::net::{self, SocketAddr};
use std::task::{Context, Poll}; use std::task::{Context, Poll};
cfg_tcp! { cfg_net! {
/// A TCP socket server, listening for connections. /// A TCP socket server, listening for connections.
/// ///
/// You can accept a new connection by using the [`accept`](`TcpListener::accept`) method. Alternatively `TcpListener` /// You can accept a new connection by using the [`accept`](`TcpListener::accept`) method. Alternatively `TcpListener`
+1 -1
View File
@@ -11,7 +11,7 @@ use std::net::{Shutdown, SocketAddr};
use std::pin::Pin; use std::pin::Pin;
use std::task::{Context, Poll}; use std::task::{Context, Poll};
cfg_tcp! { cfg_net! {
/// A TCP stream between a local and a remote socket. /// A TCP stream between a local and a remote socket.
/// ///
/// A TCP stream can either be created by connecting to an endpoint, via the /// A TCP stream can either be created by connecting to an endpoint, via the
+1 -1
View File
@@ -6,7 +6,7 @@ use std::fmt;
use std::io; use std::io;
use std::net::{self, Ipv4Addr, Ipv6Addr, SocketAddr}; use std::net::{self, Ipv4Addr, Ipv6Addr, SocketAddr};
cfg_udp! { cfg_net! {
/// A UDP socket /// A UDP socket
/// ///
/// UDP is "connectionless", unlike TCP. Meaning, regardless of what address you've bound to, a `UdpSocket` /// UDP is "connectionless", unlike TCP. Meaning, regardless of what address you've bound to, a `UdpSocket`
+1 -1
View File
@@ -9,7 +9,7 @@ use std::os::unix::io::{AsRawFd, RawFd};
use std::os::unix::net; use std::os::unix::net;
use std::path::Path; use std::path::Path;
cfg_uds! { cfg_net_unix! {
/// An I/O object representing a Unix datagram socket. /// An I/O object representing a Unix datagram socket.
/// ///
/// A socket can be either named (associated with a filesystem path) or /// A socket can be either named (associated with a filesystem path) or
+1 -1
View File
@@ -9,7 +9,7 @@ use std::os::unix::net;
use std::path::Path; use std::path::Path;
use std::task::{Context, Poll}; use std::task::{Context, Poll};
cfg_uds! { cfg_net_unix! {
/// A Unix socket which can accept connections from other Unix sockets. /// 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` /// You can accept a new connection by using the [`accept`](`UnixListener::accept`) method. Alternatively `UnixListener`
+1 -1
View File
@@ -15,7 +15,7 @@ use std::path::Path;
use std::pin::Pin; use std::pin::Pin;
use std::task::{Context, Poll}; use std::task::{Context, Poll};
cfg_uds! { cfg_net_unix! {
/// A structure representing a connected Unix socket. /// A structure representing a connected Unix socket.
/// ///
/// This socket can be connected directly with `UnixStream::connect` or accepted /// This socket can be connected directly with `UnixStream::connect` or accepted
+1 -7
View File
@@ -139,13 +139,7 @@ impl Builder {
/// .unwrap(); /// .unwrap();
/// ``` /// ```
pub fn enable_all(&mut self) -> &mut Self { pub fn enable_all(&mut self) -> &mut Self {
#[cfg(any( #[cfg(any(feature = "net", feature = "process", all(unix, feature = "signal")))]
feature = "process",
all(unix, feature = "signal"),
feature = "tcp",
feature = "udp",
feature = "uds",
))]
self.enable_io(); self.enable_io();
#[cfg(feature = "time")] #[cfg(feature = "time")]
self.enable_time(); self.enable_time();
-1
View File
@@ -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 /// Removes the last element from a list and returns it, or None if it is
/// empty. /// empty.
#[cfg_attr(any(feature = "udp", feature = "uds"), allow(unused))]
pub(crate) fn pop_back(&mut self) -> Option<L::Handle> { pub(crate) fn pop_back(&mut self) -> Option<L::Handle> {
unsafe { unsafe {
let last = self.tail?; let last = self.tail?;
+1 -3
View File
@@ -5,14 +5,12 @@ cfg_io_driver! {
#[cfg(any( #[cfg(any(
feature = "fs", feature = "fs",
feature = "net",
feature = "process", feature = "process",
feature = "rt-core", feature = "rt-core",
feature = "rt-util", feature = "rt-util",
feature = "sync", feature = "sync",
feature = "signal", feature = "signal",
feature = "tcp",
feature = "udp",
feature = "uds",
))] ))]
pub(crate) mod linked_list; pub(crate) mod linked_list;