diff --git a/Cargo.toml b/Cargo.toml index 5bd604475..22c5a089a 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -15,6 +15,5 @@ members = [ "tokio-test", "tokio-timer", "tokio-tls", - "tokio-uds", "build-tests", ] diff --git a/README.md b/README.md index 9ebdced6b..99aa0e6f5 100644 --- a/README.md +++ b/README.md @@ -140,13 +140,11 @@ The crates included as part of Tokio are: * [`tokio-macros`]: Macros for usage with Tokio. -* [`tokio-net`]: Event loop that drives I/O resources as well as TCP and UDP - apis. +* [`tokio-net`]: Event loop that drives I/O resources as well as TCP, UDP, and + unix domain socket apis. * [ `tokio-timer`]: Time related APIs. -* [`tokio-uds`]: Unix Domain Socket bindings. - [`tokio-codec`]: tokio-codec [`tokio-current-thread`]: tokio-current-thread [`tokio-executor`]: tokio-executor @@ -155,7 +153,6 @@ The crates included as part of Tokio are: [`tokio-macros`]: tokio-macros [`tokio-net`]: tokio-net [`tokio-timer`]: tokio-timer -[`tokio-uds`]: tokio-uds ## Related Projects diff --git a/azure-pipelines.yml b/azure-pipelines.yml index bd6fe8810..cd1fbf0e0 100644 --- a/azure-pipelines.yml +++ b/azure-pipelines.yml @@ -50,10 +50,9 @@ jobs: tokio-net: - tcp - udp + - uds tokio-process: [] tokio-signal: [] - tokio-uds: - - async-traits # Test crates that are NOT platform specific - template: ci/azure-test-stable.yml @@ -90,6 +89,7 @@ jobs: - net-no-features - net-with-tcp - net-with-udp + - net-with-uds - tokio-no-features - tokio-with-net diff --git a/build-tests/Cargo.toml b/build-tests/Cargo.toml index d08dcd628..66621926e 100644 --- a/build-tests/Cargo.toml +++ b/build-tests/Cargo.toml @@ -10,6 +10,7 @@ executor-without-current-thread = ["tokio-executor"] net-no-features = ["tokio-net"] net-with-tcp = ["tokio-net/tcp"] net-with-udp = ["tokio-net/udp"] +net-with-uds = ["tokio-net/uds"] tokio-no-features = ["tokio"] tokio-with-net = ["tokio/net"] diff --git a/build-tests/tests/fail/net_without_uds_missing_uds.rs b/build-tests/tests/fail/net_without_uds_missing_uds.rs new file mode 100644 index 000000000..56b726d24 --- /dev/null +++ b/build-tests/tests/fail/net_without_uds_missing_uds.rs @@ -0,0 +1,4 @@ +use build_tests::tokio_net::udp; + +fn main() {} + diff --git a/build-tests/tests/fail/net_without_uds_missing_uds.stderr b/build-tests/tests/fail/net_without_uds_missing_uds.stderr new file mode 100644 index 000000000..a1ff9256c --- /dev/null +++ b/build-tests/tests/fail/net_without_uds_missing_uds.stderr @@ -0,0 +1,7 @@ +error[E0432]: unresolved import `build_tests::tokio_net::udp` + --> $DIR/net_without_uds_missing_uds.rs:1:5 + | +1 | use build_tests::tokio_net::udp; + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ no `udp` in `tokio_net` + +For more information about this error, try `rustc --explain E0432`. diff --git a/build-tests/tests/features.rs b/build-tests/tests/features.rs index bd00803f8..64982ad02 100644 --- a/build-tests/tests/features.rs +++ b/build-tests/tests/features.rs @@ -19,6 +19,12 @@ fn net_with_udp() { use build_tests::tokio_net::udp; } +#[test] +#[cfg(feature = "net-with-uds")] +fn net_with_udp() { + use build_tests::tokio_net::uds; +} + #[test] #[cfg(feature = "tokio-with-net")] fn tokio_with_net() { @@ -36,6 +42,7 @@ fn compile_fail() { { t.compile_fail("tests/fail/net_without_tcp_missing_tcp.rs"); t.compile_fail("tests/fail/net_without_udp_missing_udp.rs"); + t.compile_fail("tests/fail/net_without_uds_missing_uds.rs"); } #[cfg(feature = "tokio-no-features")] diff --git a/ci/patch.toml b/ci/patch.toml index cae047112..6a1e58550 100644 --- a/ci/patch.toml +++ b/ci/patch.toml @@ -13,4 +13,3 @@ tokio-signal = { path = "tokio-signal" } tokio-sync = { path = "tokio-sync" } tokio-timer = { path = "tokio-timer" } tokio-tls = { path = "tokio-tls" } -tokio-uds = { path = "tokio-uds" } diff --git a/tokio-net/Cargo.toml b/tokio-net/Cargo.toml index 0d7deb70f..2f0128c14 100644 --- a/tokio-net/Cargo.toml +++ b/tokio-net/Cargo.toml @@ -32,6 +32,13 @@ udp = [ "futures-sink-preview", "futures-util-preview", ] +uds = [ + "bytes", + "mio-uds", + "futures-util-preview", + "iovec", + "libc", +] [dependencies] tokio-codec = { version = "=0.2.0-alpha.1", path = "../tokio-codec" } @@ -55,8 +62,17 @@ 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 } +# UDS +[target.'cfg(unix)'.dependencies] +mio-uds = { version = "0.6.5", optional = true } +libc = { version = "0.2.42", optional = true } + [dev-dependencies] tokio = { version = "=0.2.0-alpha.1", path = "../tokio" } tokio-test = { version = "=0.2.0-alpha.1", path = "../tokio-test" } num_cpus = "1.8.0" tokio-io-pool = "0.1.4" + +# UDS tests +tempfile = "3" +futures-preview = "=0.3.0-alpha.18" diff --git a/tokio-net/src/lib.rs b/tokio-net/src/lib.rs index 71f5fa4e2..6107a030a 100644 --- a/tokio-net/src/lib.rs +++ b/tokio-net/src/lib.rs @@ -45,3 +45,7 @@ pub mod tcp; #[cfg(feature = "udp")] pub mod udp; + +#[cfg(feature = "uds")] +#[cfg(unix)] +pub mod uds; diff --git a/tokio-uds/src/datagram.rs b/tokio-net/src/uds/datagram.rs similarity index 99% rename from tokio-uds/src/datagram.rs rename to tokio-net/src/uds/datagram.rs index 644ad7534..d9ebe24f6 100644 --- a/tokio-uds/src/datagram.rs +++ b/tokio-net/src/uds/datagram.rs @@ -1,5 +1,5 @@ -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-uds/src/frame.rs b/tokio-net/src/uds/frame.rs similarity index 100% rename from tokio-uds/src/frame.rs rename to tokio-net/src/uds/frame.rs diff --git a/tokio-uds/src/incoming.rs b/tokio-net/src/uds/incoming.rs similarity index 94% rename from tokio-uds/src/incoming.rs rename to tokio-net/src/uds/incoming.rs index 0bdbcad56..542b5e1d3 100644 --- a/tokio-uds/src/incoming.rs +++ b/tokio-net/src/uds/incoming.rs @@ -1,6 +1,7 @@ #![cfg(feature = "async-traits")] -use crate::{UnixListener, UnixStream}; +use super::{UnixListener, UnixStream}; + use futures_core::ready; use futures_core::stream::Stream; use std::io; diff --git a/tokio-uds/src/listener.rs b/tokio-net/src/uds/listener.rs similarity index 96% rename from tokio-uds/src/listener.rs rename to tokio-net/src/uds/listener.rs index 310914359..75c7e867c 100644 --- a/tokio-uds/src/listener.rs +++ b/tokio-net/src/uds/listener.rs @@ -1,7 +1,6 @@ -use crate::UnixStream; - -use tokio_net::driver::Handle; -use tokio_net::util::PollEvented; +use super::UnixStream; +use crate::driver::Handle; +use crate::util::PollEvented; use futures_core::ready; use futures_util::future::poll_fn; @@ -93,8 +92,8 @@ impl UnixListener { /// This method returns an implementation of the `Stream` trait which /// resolves to the sockets the are accepted on this listener. #[cfg(feature = "async-traits")] - pub fn incoming(self) -> crate::Incoming { - crate::Incoming::new(self) + pub fn incoming(self) -> super::Incoming { + super::Incoming::new(self) } } diff --git a/tokio-net/src/uds/mod.rs b/tokio-net/src/uds/mod.rs new file mode 100644 index 000000000..3b6849925 --- /dev/null +++ b/tokio-net/src/uds/mod.rs @@ -0,0 +1,18 @@ +//! Unix Domain Sockets for Tokio. +//! +//! This crate provides APIs for using Unix Domain Sockets with Tokio. + +mod datagram; +// mod frame; +mod incoming; +mod listener; +pub mod split; +mod stream; +mod ucred; + +pub use self::datagram::UnixDatagram; +#[cfg(feature = "async-traits")] +pub use self::incoming::Incoming; +pub use self::listener::UnixListener; +pub use self::stream::UnixStream; +pub use self::ucred::UCred; diff --git a/tokio-uds/src/split.rs b/tokio-net/src/uds/split.rs similarity index 99% rename from tokio-uds/src/split.rs rename to tokio-net/src/uds/split.rs index 19f2458d8..43f0c5d5e 100644 --- a/tokio-uds/src/split.rs +++ b/tokio-net/src/uds/split.rs @@ -12,13 +12,15 @@ //! addresses, to get and set socket options, and to shutdown the sockets. use super::UnixStream; + +use tokio_io::{AsyncRead, AsyncWrite}; + use bytes::{Buf, BufMut}; use std::io; use std::net::Shutdown; use std::pin::Pin; use std::sync::Arc; use std::task::{Context, Poll}; -use tokio_io::{AsyncRead, AsyncWrite}; /// Read half of a `UnixStream`. #[derive(Debug)] diff --git a/tokio-uds/src/stream.rs b/tokio-net/src/uds/stream.rs similarity index 98% rename from tokio-uds/src/stream.rs rename to tokio-net/src/uds/stream.rs index 4b318a054..daa02246b 100644 --- a/tokio-uds/src/stream.rs +++ b/tokio-net/src/uds/stream.rs @@ -1,18 +1,17 @@ -use crate::split::{ +use super::split::{ split, split_mut, UnixStreamReadHalf, UnixStreamReadHalfMut, UnixStreamWriteHalf, UnixStreamWriteHalfMut, }; -use crate::ucred::{self, UCred}; +use super::ucred::{self, UCred}; +use crate::driver::Handle; +use crate::util::PollEvented; use tokio_io::{AsyncRead, AsyncWrite}; -use tokio_net::driver::Handle; -use tokio_net::util::PollEvented; use bytes::{Buf, BufMut}; use futures_core::ready; use futures_util::future::poll_fn; use iovec::IoVec; -use mio_uds; use std::convert::TryFrom; use std::fmt; use std::io::{self, Read, Write}; diff --git a/tokio-uds/src/ucred.rs b/tokio-net/src/uds/ucred.rs similarity index 98% rename from tokio-uds/src/ucred.rs rename to tokio-net/src/uds/ucred.rs index ed607cfb5..96683fe2a 100644 --- a/tokio-uds/src/ucred.rs +++ b/tokio-net/src/uds/ucred.rs @@ -27,7 +27,8 @@ pub(crate) use self::impl_solaris::get_peer_cred; #[cfg(any(target_os = "linux", target_os = "android"))] pub(crate) mod impl_linux { - use crate::UnixStream; + use crate::uds::UnixStream; + use libc::{c_void, getsockopt, socklen_t, SOL_SOCKET, SO_PEERCRED}; use std::{io, mem}; @@ -81,7 +82,8 @@ pub(crate) mod impl_linux { target_os = "openbsd" ))] pub(crate) mod impl_macos { - use crate::UnixStream; + use crate::uds::UnixStream; + use libc::getpeereid; use std::io; use std::mem::MaybeUninit; @@ -155,7 +157,8 @@ pub(crate) mod impl_solaris { #[cfg(not(target_os = "dragonfly"))] #[cfg(test)] mod test { - use crate::UnixStream; + use crate::uds::UnixStream; + use libc::getegid; use libc::geteuid; diff --git a/tokio-uds/tests/datagram.rs b/tokio-net/tests/uds_datagram.rs similarity index 98% rename from tokio-uds/tests/datagram.rs rename to tokio-net/tests/uds_datagram.rs index c222810be..a8a8131a0 100644 --- a/tokio-uds/tests/datagram.rs +++ b/tokio-net/tests/uds_datagram.rs @@ -2,9 +2,10 @@ #![feature(async_await)] #![warn(rust_2018_idioms)] +use tokio_net::uds::*; + use std::io; use tempfile; -use tokio_uds::*; // struct StringDatagramCodec; diff --git a/tokio-uds/tests/split.rs b/tokio-net/tests/uds_split.rs similarity index 97% rename from tokio-uds/tests/split.rs rename to tokio-net/tests/uds_split.rs index 4afd76876..7de589e76 100644 --- a/tokio-uds/tests/split.rs +++ b/tokio-net/tests/uds_split.rs @@ -2,8 +2,8 @@ #![feature(async_await)] #![deny(warnings, rust_2018_idioms)] +use tokio::net::UnixStream; use tokio::prelude::*; -use tokio_uds::UnixStream; /// Checks that `UnixStream` can be split into a read half and a write half using /// `UnixStream::split` and `UnixStream::split_mut`. diff --git a/tokio-uds/tests/stream.rs b/tokio-net/tests/uds_stream.rs similarity index 97% rename from tokio-uds/tests/stream.rs rename to tokio-net/tests/uds_stream.rs index 66c15586e..b7dc305a6 100644 --- a/tokio-uds/tests/stream.rs +++ b/tokio-net/tests/uds_stream.rs @@ -2,10 +2,11 @@ #![feature(async_await)] #![warn(rust_2018_idioms)] +use tokio_net::uds::*; + use futures::future::try_join; use tempfile::Builder; use tokio::io::{AsyncReadExt, AsyncWriteExt}; -use tokio_uds::*; #[tokio::test] async fn accept_read_write() -> std::io::Result<()> { diff --git a/tokio-uds/CHANGELOG.md b/tokio-uds/CHANGELOG.md deleted file mode 100644 index 45f81888f..000000000 --- a/tokio-uds/CHANGELOG.md +++ /dev/null @@ -1,33 +0,0 @@ -# 0.2.0-alpha.1 (August 8, 2019) - -### Changed -- Switch to `async`, `await`, and `std::future`. - -# 0.2.5 (January 6, 2019) - -* Fix bug in `UnixDatagram::send` (#782). - -# 0.2.4 (November 24, 2018) - -* Implement `UnixDatagramFramed`, providing a `Stream + Sink` layer for - unix domain sockets (#453). -* Add solaris support for `ucred` (#733). -* Documentation tweaks (#754). - -# 0.2.3 (October 23, 2018) - -* Fix build on NetBSD (#715). - -# 0.2.2 (September 27, 2018) - -* Fix bug in `UdsStream::read_buf` (#672). - -# 0.2.1 (August 19, 2018) - -* Re-export `ConnectFuture` (#430). -* bug: Fix `recv_from` (#452). -* bug: Fix build on FreeBSD. - -# 0.2.0 (June 6, 2018) - -* Initial 0.2 release. diff --git a/tokio-uds/Cargo.toml b/tokio-uds/Cargo.toml deleted file mode 100644 index 3f3f4ff22..000000000 --- a/tokio-uds/Cargo.toml +++ /dev/null @@ -1,43 +0,0 @@ -[package] -name = "tokio-uds" -# When releasing to crates.io: -# - Remove path dependencies -# - Update html_root_url. -# - Update doc url -# - Cargo.toml -# - Update CHANGELOG.md. -# - Create "v0.3.x" git tag. -version = "0.3.0-alpha.1" -edition = "2018" -authors = ["Tokio Contributors "] -license = "MIT" -repository = "https://github.com/tokio-rs/tokio" -homepage = "https://github.com/tokio-rs/tokio" -documentation = "https://docs.rs/tokio-uds/0.3.0-alpha.1/tokio_uds/" -description = """ -Unix Domain sockets for Tokio -""" -categories = ["asynchronous"] - -[features] -async-traits = [] - -[dependencies] -tokio-codec = { version = "=0.2.0-alpha.1", path = "../tokio-codec" } -tokio-net = { version = "=0.2.0-alpha.1", path = "../tokio-net" } -tokio-io = { version = "=0.2.0-alpha.1", path = "../tokio-io" } - -bytes = "0.4.8" -mio = "0.6.14" -mio-uds = "0.6.5" -futures-core-preview = "=0.3.0-alpha.18" -futures-util-preview = "=0.3.0-alpha.18" -iovec = "0.1.2" -libc = "0.2.42" -log = "0.4.2" - -[dev-dependencies] -tokio = { version = "=0.2.0-alpha.1", path = "../tokio" } - -tempfile = "3" -futures-preview = "=0.3.0-alpha.18" diff --git a/tokio-uds/LICENSE b/tokio-uds/LICENSE deleted file mode 100644 index cdb28b4b5..000000000 --- a/tokio-uds/LICENSE +++ /dev/null @@ -1,25 +0,0 @@ -Copyright (c) 2019 Tokio Contributors - -Permission is hereby granted, free of charge, to any -person obtaining a copy of this software and associated -documentation files (the "Software"), to deal in the -Software without restriction, including without -limitation the rights to use, copy, modify, merge, -publish, distribute, sublicense, and/or sell copies of -the Software, and to permit persons to whom the Software -is furnished to do so, subject to the following -conditions: - -The above copyright notice and this permission notice -shall be included in all copies or substantial portions -of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF -ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED -TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A -PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT -SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY -CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION -OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR -IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER -DEALINGS IN THE SOFTWARE. diff --git a/tokio-uds/README.md b/tokio-uds/README.md deleted file mode 100644 index ce043da9b..000000000 --- a/tokio-uds/README.md +++ /dev/null @@ -1,13 +0,0 @@ -# tokio-uds - -An implementation of Unix Domain Sockets for Tokio - -## License - -This project is licensed under the [MIT license](./LICENSE). - -### Contribution - -Unless you explicitly state otherwise, any contribution intentionally submitted -for inclusion in Tokio by you, shall be licensed as MIT, without any additional -terms or conditions. diff --git a/tokio-uds/src/lib.rs b/tokio-uds/src/lib.rs deleted file mode 100644 index e531e3b45..000000000 --- a/tokio-uds/src/lib.rs +++ /dev/null @@ -1,29 +0,0 @@ -#![cfg(unix)] -#![doc(html_root_url = "https://docs.rs/tokio-uds/0.3.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)] - -//! Unix Domain Sockets for Tokio. -//! -//! This crate provides APIs for using Unix Domain Sockets with Tokio. - -mod datagram; -// mod frame; -mod incoming; -mod listener; -pub mod split; -mod stream; -mod ucred; - -pub use crate::datagram::UnixDatagram; -#[cfg(feature = "async-traits")] -pub use crate::incoming::Incoming; -pub use crate::listener::UnixListener; -pub use crate::stream::UnixStream; -pub use crate::ucred::UCred; diff --git a/tokio/Cargo.toml b/tokio/Cargo.toml index 54369e495..bcfeb4a96 100644 --- a/tokio/Cargo.toml +++ b/tokio/Cargo.toml @@ -52,7 +52,7 @@ sync = ["tokio-sync"] tcp = ["io", "tokio-net/tcp"] timer = ["tokio-timer"] udp = ["io", "tokio-net/udp"] -uds = ["io", "tokio-net", "tokio-uds"] +uds = ["io", "tokio-net/uds"] [dependencies] futures-core-preview = "=0.3.0-alpha.18" @@ -72,9 +72,6 @@ tokio-sync = { version = "=0.2.0-alpha.1", optional = true, path = "../tokio-syn tokio-timer = { version = "=0.3.0-alpha.1", optional = true, path = "../tokio-timer", features = ["async-traits"] } tracing-core = { version = "0.1", optional = true } -[target.'cfg(unix)'.dependencies] -tokio-uds = { version = "=0.3.0-alpha.1", optional = true, path = "../tokio-uds", features = ["async-traits"] } - [dev-dependencies] tokio-test = { version = "=0.2.0-alpha.1", path = "../tokio-test" } diff --git a/tokio/src/net.rs b/tokio/src/net.rs index 19ec5ccbd..ca9db00e7 100644 --- a/tokio/src/net.rs +++ b/tokio/src/net.rs @@ -67,7 +67,7 @@ pub use self::udp::{UdpFramed, UdpSocket}; pub mod unix { //! Unix domain socket bindings for `tokio` (only available on unix systems). - pub use tokio_uds::{split, UCred, UnixDatagram, UnixListener, UnixStream}; + pub use tokio_net::uds::{split, UCred, UnixDatagram, UnixListener, UnixStream}; } #[cfg(all(unix, feature = "uds"))] pub use self::unix::{UnixDatagram, UnixListener, UnixStream};