mirror of
https://github.com/tokio-rs/tokio.git
synced 2026-08-20 00:00:08 +02:00
net: merge tcp, udp, uds features to net feature (#2943)
This commit is contained in:
+9
-4
@@ -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 }
|
||||
|
||||
@@ -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));
|
||||
|
||||
|
||||
@@ -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()
|
||||
}
|
||||
|
||||
+1
-4
@@ -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
|
||||
|
||||
@@ -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;
|
||||
|
||||
+26
-46
@@ -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
|
||||
)*
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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`
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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`
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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();
|
||||
|
||||
@@ -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?;
|
||||
|
||||
@@ -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;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user