mirror of
https://github.com/tokio-rs/tokio.git
synced 2025-09-25 12:00:35 +00:00
udp: move tokio-udp into tokio-net (#1459)
This commit is contained in:
parent
d8b23ef852
commit
ce7e60e396
@ -15,7 +15,6 @@ members = [
|
||||
"tokio-test",
|
||||
"tokio-timer",
|
||||
"tokio-tls",
|
||||
"tokio-udp",
|
||||
"tokio-uds",
|
||||
"ui-tests",
|
||||
]
|
||||
|
@ -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
|
||||
|
||||
|
@ -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" }
|
||||
|
@ -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 }
|
||||
|
||||
|
@ -42,3 +42,6 @@ pub mod util;
|
||||
|
||||
#[cfg(feature = "tcp")]
|
||||
pub mod tcp;
|
||||
|
||||
#[cfg(feature = "udp")]
|
||||
pub mod udp;
|
||||
|
@ -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.
|
@ -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
|
@ -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;
|
@ -65,7 +65,7 @@ fn reunite(s: UdpSocketSendHalf, r: UdpSocketRecvHalf) -> Result<UdpSocket, Reun
|
||||
// receiver and one for the sender, and those `Arc`s are never exposed
|
||||
// externally. And so when we drop one here, the other one must be the
|
||||
// only remaining one.
|
||||
Ok(Arc::try_unwrap(s.0).expect("tokio_udp: try_unwrap failed in reunite"))
|
||||
Ok(Arc::try_unwrap(s.0).expect("udp: try_unwrap failed in reunite"))
|
||||
} else {
|
||||
Err(ReuniteError(s, r))
|
||||
}
|
@ -1,11 +1,12 @@
|
||||
#![feature(async_await)]
|
||||
#![warn(rust_2018_idioms)]
|
||||
|
||||
use tokio_codec::{Decoder, Encoder};
|
||||
use tokio_net::udp::{UdpFramed, UdpSocket};
|
||||
|
||||
use bytes::{BufMut, BytesMut};
|
||||
use futures_util::{future::FutureExt, sink::SinkExt, stream::StreamExt, try_future::try_join};
|
||||
use std::io;
|
||||
use tokio_codec::{Decoder, Encoder};
|
||||
use tokio_udp::{UdpFramed, UdpSocket};
|
||||
|
||||
#[tokio::test]
|
||||
async fn send_recv() -> 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())?;
|
||||
|
@ -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 }
|
||||
|
||||
|
@ -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};
|
||||
|
@ -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"]
|
||||
|
||||
|
@ -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");
|
||||
|
4
ui-tests/tests/ui/net_without_udp_missing_udp.rs
Normal file
4
ui-tests/tests/ui/net_without_udp_missing_udp.rs
Normal file
@ -0,0 +1,4 @@
|
||||
use ui_tests::tokio_net::udp;
|
||||
|
||||
fn main() {}
|
||||
|
7
ui-tests/tests/ui/net_without_udp_missing_udp.stderr
Normal file
7
ui-tests/tests/ui/net_without_udp_missing_udp.stderr
Normal file
@ -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`.
|
Loading…
x
Reference in New Issue
Block a user