From ce7e60e3965283328909aaef57c57e538526a880 Mon Sep 17 00:00:00 2001 From: Carl Lerche Date: Fri, 16 Aug 2019 07:26:10 -0700 Subject: [PATCH] udp: move tokio-udp into tokio-net (#1459) --- Cargo.toml | 1 - azure-pipelines.yml | 3 ++- ci/patch.toml | 1 - tokio-net/Cargo.toml | 9 ++++++++- tokio-net/src/lib.rs | 3 +++ {tokio-udp/src => tokio-net/src/udp}/frame.rs | 4 +++- tokio-udp/src/lib.rs => tokio-net/src/udp/mod.rs | 10 ---------- {tokio-udp/src => tokio-net/src/udp}/socket.rs | 5 ++--- {tokio-udp/src => tokio-net/src/udp}/split.rs | 2 +- {tokio-udp => tokio-net}/tests/udp.rs | 7 +++---- tokio/Cargo.toml | 3 +-- tokio/src/net.rs | 2 +- ui-tests/Cargo.toml | 1 + ui-tests/tests/features.rs | 11 ++++++++++- ui-tests/tests/ui/net_without_udp_missing_udp.rs | 4 ++++ ui-tests/tests/ui/net_without_udp_missing_udp.stderr | 7 +++++++ 16 files changed, 46 insertions(+), 27 deletions(-) rename {tokio-udp/src => tokio-net/src/udp}/frame.rs (99%) rename tokio-udp/src/lib.rs => tokio-net/src/udp/mod.rs (66%) rename {tokio-udp/src => tokio-net/src/udp}/socket.rs (99%) rename {tokio-udp/src => tokio-net/src/udp}/split.rs (98%) rename {tokio-udp => tokio-net}/tests/udp.rs (98%) create mode 100644 ui-tests/tests/ui/net_without_udp_missing_udp.rs create mode 100644 ui-tests/tests/ui/net_without_udp_missing_udp.stderr diff --git a/Cargo.toml b/Cargo.toml index adfbfc845..c9526112e 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -15,7 +15,6 @@ members = [ "tokio-test", "tokio-timer", "tokio-tls", - "tokio-udp", "tokio-uds", "ui-tests", ] diff --git a/azure-pipelines.yml b/azure-pipelines.yml index 37fe85916..8c9edd8ed 100644 --- a/azure-pipelines.yml +++ b/azure-pipelines.yml @@ -49,9 +49,9 @@ jobs: tokio-fs: [] tokio-net: - tcp + - udp tokio-process: [] tokio-signal: [] - tokio-udp: [] tokio-uds: - async-traits @@ -89,6 +89,7 @@ jobs: - executor-without-current-thread - net-no-features - net-with-tcp + - net-with-udp - tokio-no-features - tokio-with-net diff --git a/ci/patch.toml b/ci/patch.toml index 3a3976188..cae047112 100644 --- a/ci/patch.toml +++ b/ci/patch.toml @@ -13,5 +13,4 @@ tokio-signal = { path = "tokio-signal" } tokio-sync = { path = "tokio-sync" } tokio-timer = { path = "tokio-timer" } tokio-tls = { path = "tokio-tls" } -tokio-udp = { path = "tokio-udp" } tokio-uds = { path = "tokio-uds" } diff --git a/tokio-net/Cargo.toml b/tokio-net/Cargo.toml index 5f5cc50d7..0d7deb70f 100644 --- a/tokio-net/Cargo.toml +++ b/tokio-net/Cargo.toml @@ -27,8 +27,14 @@ tcp = [ "futures-util-preview", "iovec", ] +udp = [ + "bytes", + "futures-sink-preview", + "futures-util-preview", +] [dependencies] +tokio-codec = { version = "=0.2.0-alpha.1", path = "../tokio-codec" } tokio-executor = { version = "=0.2.0-alpha.1", path = "../tokio-executor" } tokio-io = { version = "=0.2.0-alpha.1", path = "../tokio-io" } tokio-sync = { version = "=0.2.0-alpha.1", path = "../tokio-sync" } @@ -43,8 +49,9 @@ num_cpus = "1.8.0" parking_lot = "0.9" slab = "0.4.0" -# TCP +# TCP / UDP bytes = { version = "0.4", optional = true } +futures-sink-preview = { version = "=0.3.0-alpha.18", optional = true } futures-util-preview = { version = "=0.3.0-alpha.18", optional = true } iovec = { version = "0.1", optional = true } diff --git a/tokio-net/src/lib.rs b/tokio-net/src/lib.rs index ab9bb1a09..71f5fa4e2 100644 --- a/tokio-net/src/lib.rs +++ b/tokio-net/src/lib.rs @@ -42,3 +42,6 @@ pub mod util; #[cfg(feature = "tcp")] pub mod tcp; + +#[cfg(feature = "udp")] +pub mod udp; diff --git a/tokio-udp/src/frame.rs b/tokio-net/src/udp/frame.rs similarity index 99% rename from tokio-udp/src/frame.rs rename to tokio-net/src/udp/frame.rs index 015685218..b308aac46 100644 --- a/tokio-udp/src/frame.rs +++ b/tokio-net/src/udp/frame.rs @@ -1,4 +1,7 @@ use super::UdpSocket; + +use tokio_codec::{Decoder, Encoder}; + use bytes::{BufMut, BytesMut}; use core::task::{Context, Poll}; use futures_core::{ready, Stream}; @@ -7,7 +10,6 @@ use log::trace; use std::io; use std::net::{Ipv4Addr, SocketAddr, SocketAddrV4}; use std::pin::Pin; -use tokio_codec::{Decoder, Encoder}; /// A unified `Stream` and `Sink` interface to an underlying `UdpSocket`, using /// the `Encoder` and `Decoder` traits to encode and decode frames. diff --git a/tokio-udp/src/lib.rs b/tokio-net/src/udp/mod.rs similarity index 66% rename from tokio-udp/src/lib.rs rename to tokio-net/src/udp/mod.rs index 20de7ade0..156f9573a 100644 --- a/tokio-udp/src/lib.rs +++ b/tokio-net/src/udp/mod.rs @@ -1,13 +1,3 @@ -#![doc(html_root_url = "https://docs.rs/tokio-udp/0.2.0-alpha.1")] -#![warn( - missing_debug_implementations, - missing_docs, - rust_2018_idioms, - unreachable_pub -)] -#![doc(test(no_crate_inject, attr(deny(rust_2018_idioms))))] -#![feature(async_await)] - //! UDP bindings for `tokio`. //! //! This module contains the UDP networking types, similar to the standard diff --git a/tokio-udp/src/socket.rs b/tokio-net/src/udp/socket.rs similarity index 99% rename from tokio-udp/src/socket.rs rename to tokio-net/src/udp/socket.rs index 52ef0645f..1b26a68a5 100644 --- a/tokio-udp/src/socket.rs +++ b/tokio-net/src/udp/socket.rs @@ -1,7 +1,6 @@ use super::split::{split, UdpSocketRecvHalf, UdpSocketSendHalf}; - -use tokio_net::driver::Handle; -use tokio_net::util::PollEvented; +use crate::driver::Handle; +use crate::util::PollEvented; use futures_core::ready; use futures_util::future::poll_fn; diff --git a/tokio-udp/src/split.rs b/tokio-net/src/udp/split.rs similarity index 98% rename from tokio-udp/src/split.rs rename to tokio-net/src/udp/split.rs index d3b2bbdd6..e58f92769 100644 --- a/tokio-udp/src/split.rs +++ b/tokio-net/src/udp/split.rs @@ -65,7 +65,7 @@ fn reunite(s: UdpSocketSendHalf, r: UdpSocketRecvHalf) -> Result std::io::Result<()> { @@ -101,8 +102,6 @@ impl Encoder for ByteCodec { #[tokio::test] async fn send_framed() -> std::io::Result<()> { - drop(env_logger::try_init()); - let mut a_soc = UdpSocket::bind(&"127.0.0.1:0".parse().unwrap())?; let mut b_soc = UdpSocket::bind(&"127.0.0.1:0".parse().unwrap())?; diff --git a/tokio/Cargo.toml b/tokio/Cargo.toml index 2b37a32cc..54369e495 100644 --- a/tokio/Cargo.toml +++ b/tokio/Cargo.toml @@ -51,7 +51,7 @@ rt-full = [ sync = ["tokio-sync"] tcp = ["io", "tokio-net/tcp"] timer = ["tokio-timer"] -udp = ["io", "tokio-net", "tokio-udp"] +udp = ["io", "tokio-net/udp"] uds = ["io", "tokio-net", "tokio-uds"] [dependencies] @@ -69,7 +69,6 @@ tokio-executor = { version = "=0.2.0-alpha.1", optional = true, path = "../tokio tokio-macros = { version = "=0.2.0-alpha.1", optional = true, path = "../tokio-macros" } tokio-net = { version = "=0.2.0-alpha.1", optional = true, features = ["async-traits"], path = "../tokio-net" } tokio-sync = { version = "=0.2.0-alpha.1", optional = true, path = "../tokio-sync", features = ["async-traits"] } -tokio-udp = { version = "=0.2.0-alpha.1", optional = true, path = "../tokio-udp" } tokio-timer = { version = "=0.3.0-alpha.1", optional = true, path = "../tokio-timer", features = ["async-traits"] } tracing-core = { version = "0.1", optional = true } diff --git a/tokio/src/net.rs b/tokio/src/net.rs index 6163d880d..19ec5ccbd 100644 --- a/tokio/src/net.rs +++ b/tokio/src/net.rs @@ -58,7 +58,7 @@ pub mod udp { //! [`Send`]: struct.Send.html //! [`RecvFrom`]: struct.RecvFrom.html //! [`SendTo`]: struct.SendTo.html - pub use tokio_udp::{split, UdpFramed, UdpSocket}; + pub use tokio_net::udp::{split, UdpFramed, UdpSocket}; } #[cfg(feature = "udp")] pub use self::udp::{UdpFramed, UdpSocket}; diff --git a/ui-tests/Cargo.toml b/ui-tests/Cargo.toml index 1e472785d..dab3a64c3 100644 --- a/ui-tests/Cargo.toml +++ b/ui-tests/Cargo.toml @@ -9,6 +9,7 @@ publish = false executor-without-current-thread = ["tokio-executor"] net-no-features = ["tokio-net"] net-with-tcp = ["tokio-net/tcp"] +net-with-udp = ["tokio-net/udp"] tokio-no-features = ["tokio"] tokio-with-net = ["tokio/net"] diff --git a/ui-tests/tests/features.rs b/ui-tests/tests/features.rs index c760b8691..8a2ff29d9 100644 --- a/ui-tests/tests/features.rs +++ b/ui-tests/tests/features.rs @@ -13,6 +13,12 @@ fn net_with_tcp() { use ui_tests::tokio_net::tcp; } +#[test] +#[cfg(feature = "net-with-udp")] +fn net_with_udp() { + use ui_tests::tokio_net::udp; +} + #[test] #[cfg(feature = "tokio-with-net")] fn tokio_with_net() { @@ -27,7 +33,10 @@ fn compile_fail() { t.compile_fail("tests/ui/executor_without_current_thread.rs"); #[cfg(feature = "net-no-features")] - t.compile_fail("tests/ui/net_without_tcp_missing_tcp.rs"); + { + t.compile_fail("tests/ui/net_without_tcp_missing_tcp.rs"); + t.compile_fail("tests/ui/net_without_udp_missing_udp.rs"); + } #[cfg(feature = "tokio-no-features")] t.compile_fail("tests/ui/tokio_without_net_missing_net.rs"); diff --git a/ui-tests/tests/ui/net_without_udp_missing_udp.rs b/ui-tests/tests/ui/net_without_udp_missing_udp.rs new file mode 100644 index 000000000..50dd18dbc --- /dev/null +++ b/ui-tests/tests/ui/net_without_udp_missing_udp.rs @@ -0,0 +1,4 @@ +use ui_tests::tokio_net::udp; + +fn main() {} + diff --git a/ui-tests/tests/ui/net_without_udp_missing_udp.stderr b/ui-tests/tests/ui/net_without_udp_missing_udp.stderr new file mode 100644 index 000000000..3596f7b78 --- /dev/null +++ b/ui-tests/tests/ui/net_without_udp_missing_udp.stderr @@ -0,0 +1,7 @@ +error[E0432]: unresolved import `ui_tests::tokio_net::udp` + --> $DIR/net_without_udp_missing_udp.rs:1:5 + | +1 | use ui_tests::tokio_net::udp; + | ^^^^^^^^^^^^^^^^^^^^^^^^ no `udp` in `tokio_net` + +For more information about this error, try `rustc --explain E0432`.