uds: move into tokio-net (#1462)

This commit is contained in:
Carl Lerche 2019-08-16 14:42:05 -07:00 committed by GitHub
parent 4935aae164
commit a83f5e4ba6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
28 changed files with 90 additions and 178 deletions

View File

@ -15,6 +15,5 @@ members = [
"tokio-test",
"tokio-timer",
"tokio-tls",
"tokio-uds",
"build-tests",
]

View File

@ -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

View File

@ -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

View File

@ -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"]

View File

@ -0,0 +1,4 @@
use build_tests::tokio_net::udp;
fn main() {}

View File

@ -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`.

View File

@ -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")]

View File

@ -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" }

View File

@ -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"

View File

@ -45,3 +45,7 @@ pub mod tcp;
#[cfg(feature = "udp")]
pub mod udp;
#[cfg(feature = "uds")]
#[cfg(unix)]
pub mod uds;

View File

@ -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;

View File

@ -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;

View File

@ -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)
}
}

18
tokio-net/src/uds/mod.rs Normal file
View File

@ -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;

View File

@ -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)]

View File

@ -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};

View File

@ -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;

View File

@ -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;

View File

@ -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`.

View File

@ -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<()> {

View File

@ -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.

View File

@ -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 <team@tokio.rs>"]
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"

View File

@ -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.

View File

@ -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.

View File

@ -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;

View File

@ -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" }

View File

@ -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};