Move tokio::net module into tokio tcp/udp crates (#224)

This commit is contained in:
Sam Rijs 2018-03-15 03:38:59 +11:00 committed by Carl Lerche
parent 64435f5b35
commit 923a80e098
29 changed files with 312 additions and 90 deletions

View File

@ -27,6 +27,8 @@ members = [
"tokio-io",
"tokio-reactor",
"tokio-threadpool",
"tokio-tcp",
"tokio-udp",
"futures2",
]
@ -39,15 +41,14 @@ tokio-io = { version = "0.1.6", path = "tokio-io" }
tokio-executor = { version = "0.1.0", path = "tokio-executor" }
tokio-reactor = { version = "0.1.0", path = "tokio-reactor" }
tokio-threadpool = { version = "0.1.0", path = "tokio-threadpool" }
bytes = "0.4"
log = "0.4"
tokio-tcp = { version = "0.1.0", path = "tokio-tcp" }
tokio-udp = { version = "0.1.0", path = "tokio-udp" }
mio = "0.6.14"
slab = "0.4"
iovec = "0.1"
futures = "0.1.18"
futures2 = { version = "0.1", path = "futures2", optional = true }
[dev-dependencies]
bytes = "0.4"
env_logger = { version = "0.4", default-features = false }
flate2 = { version = "1", features = ["tokio"] }
futures-cpupool = "0.1"
@ -68,6 +69,8 @@ unstable-futures = [
"futures2",
"tokio-reactor/unstable-futures",
"tokio-threadpool/unstable-futures",
"tokio-executor/unstable-futures"
"tokio-executor/unstable-futures",
"tokio-tcp/unstable-futures",
"tokio-udp/unstable-futures"
]
default = []

View File

@ -117,10 +117,16 @@ The crates included as part of Tokio are:
* [`tokio-threadpool`]: Schedules the execution of futures across a pool of
threads.
* [`tokio-tcp`]: TCP bindings for use with `tokio-io` and `tokio-reactor`.
* [`tokio-udp`]: UDP bindings for use with `tokio-io` and `tokio-reactor`.
[`tokio-executor`]: tokio-executor
[`tokio-io`]: tokio-io
[`tokio-reactor`]: tokio-reactor
[`tokio-threadpool`]: tokio-threadpool
[`tokio-tcp`]: tokio-tcp
[`tokio-udp`]: tokio-udp
## License

View File

@ -65,19 +65,15 @@
#![doc(html_root_url = "https://docs.rs/tokio/0.1.3")]
#![deny(missing_docs, warnings, missing_debug_implementations)]
extern crate bytes;
#[macro_use]
extern crate futures;
extern crate iovec;
extern crate mio;
extern crate slab;
extern crate tokio_io;
extern crate tokio_executor;
extern crate tokio_reactor;
extern crate tokio_threadpool;
#[macro_use]
extern crate log;
extern crate tokio_tcp;
extern crate tokio_udp;
#[cfg(feature = "unstable-futures")]
extern crate futures2;
@ -190,19 +186,3 @@ pub mod prelude {
task,
};
}
#[cfg(feature = "unstable-futures")]
fn lift_async<T>(old: futures::Async<T>) -> futures2::Async<T> {
match old {
futures::Async::Ready(x) => futures2::Async::Ready(x),
futures::Async::NotReady => futures2::Async::Pending,
}
}
#[cfg(feature = "unstable-futures")]
fn lower_async<T>(new: futures2::Async<T>) -> futures::Async<T> {
match new {
futures2::Async::Ready(x) => futures::Async::Ready(x),
futures2::Async::Pending => futures::Async::NotReady,
}
}

View File

@ -36,9 +36,6 @@
//! [`UdpFramed`]: struct.UdpFramed.html
//! [`framed`]: struct.UdpSocket.html#method.framed
mod tcp;
mod udp;
pub use self::tcp::{TcpStream, ConnectFuture};
pub use self::tcp::{TcpListener, Incoming};
pub use self::udp::{UdpSocket, UdpFramed, SendDgram, RecvDgram};
pub use tokio_tcp::{TcpStream, ConnectFuture};
pub use tokio_tcp::{TcpListener, Incoming};
pub use tokio_udp::{UdpSocket, UdpFramed, SendDgram, RecvDgram};

View File

@ -1,8 +0,0 @@
mod incoming;
mod listener;
mod stream;
pub use self::incoming::Incoming;
pub use self::listener::TcpListener;
pub use self::stream::TcpStream;
pub use self::stream::ConnectFuture;

View File

@ -1,9 +0,0 @@
mod frame;
mod socket;
mod send_dgram;
mod recv_dgram;
pub use self::frame::UdpFramed;
pub use self::socket::UdpSocket;
pub use self::send_dgram::SendDgram;
pub use self::recv_dgram::RecvDgram;

3
tokio-tcp/CHANGELOG.md Normal file
View File

@ -0,0 +1,3 @@
# 0.1.0 (unreleased)
* Initial release

33
tokio-tcp/Cargo.toml Normal file
View File

@ -0,0 +1,33 @@
[package]
name = "tokio-tcp"
# When releasing to crates.io:
# - Update html_root_url.
# - Update CHANGELOG.md.
# - Create "v0.1.x" git tag.
version = "0.1.0"
authors = ["Carl Lerche <me@carllerche.com>"]
license = "MIT"
repository = "https://github.com/tokio-rs/tokio"
homepage = "https://tokio.rs"
documentation = "https://docs.rs/tokio-tcp/0.1"
description = """
TCP bindings for tokio.
"""
categories = ["asynchronous"]
[dependencies]
tokio-io = { version = "0.1.6", path = "../tokio-io" }
tokio-reactor = { version = "0.1.0", path = "../tokio-reactor" }
bytes = "0.4"
mio = "0.6.14"
iovec = "0.1"
futures = "0.1.18"
futures2 = { version = "0.1", path = "../futures2", optional = true }
[dev-dependencies]
env_logger = { version = "0.4", default-features = false }
[features]
unstable-futures = ["futures2"]
default = []

25
tokio-tcp/LICENSE Normal file
View File

@ -0,0 +1,25 @@
Copyright (c) 2018 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.

15
tokio-tcp/README.md Normal file
View File

@ -0,0 +1,15 @@
# tokio-tcp
TCP bindings for `tokio`.
[Documentation](https://tokio-rs.github.io/tokio/tokio_tcp/)
## 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,5 +1,5 @@
use net::tcp::TcpListener;
use net::tcp::TcpStream;
use super::TcpListener;
use super::TcpStream;
use std::io;
use futures::stream::Stream;

59
tokio-tcp/src/lib.rs Normal file
View File

@ -0,0 +1,59 @@
//! TCP bindings for `tokio`.
//!
//! This module contains the TCP networking types, similar to the standard
//! library, which can be used to implement networking protocols.
//!
//! Connecting to an address, via TCP, can be done using [`TcpStream`]'s
//! [`connect`] method, which returns [`ConnectFuture`]. `ConnectFuture`
//! implements a future which returns a `TcpStream`.
//!
//! To listen on an address [`TcpListener`] can be used. `TcpListener`'s
//! [`incoming`][incoming_method] method can be used to accept new connections.
//! It return the [`Incoming`] struct, which implements a stream which returns
//! `TcpStream`s.
//!
//! [`TcpStream`]: struct.TcpStream.html
//! [`connect`]: struct.TcpStream.html#method.connect
//! [`ConnectFuture`]: struct.ConnectFuture.html
//! [`TcpListener`]: struct.TcpListener.html
//! [incoming_method]: struct.TcpListener.html#method.incoming
//! [`Incoming`]: struct.Incoming.html
#![doc(html_root_url = "https://docs.rs/tokio-tcp/0.1.0")]
#![deny(missing_docs, warnings, missing_debug_implementations)]
extern crate bytes;
#[macro_use]
extern crate futures;
extern crate iovec;
extern crate mio;
extern crate tokio_io;
extern crate tokio_reactor;
#[cfg(feature = "unstable-futures")]
extern crate futures2;
mod incoming;
mod listener;
mod stream;
pub use self::incoming::Incoming;
pub use self::listener::TcpListener;
pub use self::stream::TcpStream;
pub use self::stream::ConnectFuture;
#[cfg(feature = "unstable-futures")]
fn lift_async<T>(old: futures::Async<T>) -> futures2::Async<T> {
match old {
futures::Async::Ready(x) => futures2::Async::Ready(x),
futures::Async::NotReady => futures2::Async::Pending,
}
}
#[cfg(feature = "unstable-futures")]
fn lower_async<T>(new: futures2::Async<T>) -> futures::Async<T> {
match new {
futures2::Async::Ready(x) => futures::Async::Ready(x),
futures2::Async::Pending => futures::Async::NotReady,
}
}

View File

@ -1,5 +1,5 @@
use net::tcp::Incoming;
use net::tcp::TcpStream;
use super::Incoming;
use super::TcpStream;
use std::fmt;
use std::io;
@ -7,8 +7,7 @@ use std::net::{self, SocketAddr};
use futures::{Poll, Async};
use mio;
use reactor::{Handle, PollEvented2};
use tokio_reactor::{Handle, PollEvented};
#[cfg(feature = "unstable-futures")]
use futures2;
@ -18,7 +17,7 @@ use futures2;
/// This object can be converted into a stream of incoming connections for
/// various forms of processing.
pub struct TcpListener {
io: PollEvented2<mio::net::TcpListener>,
io: PollEvented<mio::net::TcpListener>,
}
impl TcpListener {
@ -174,12 +173,12 @@ impl TcpListener {
-> io::Result<TcpListener>
{
let io = mio::net::TcpListener::from_std(listener)?;
let io = PollEvented2::new_with_handle(io, handle)?;
let io = PollEvented::new_with_handle(io, handle)?;
Ok(TcpListener { io })
}
fn new(listener: mio::net::TcpListener) -> TcpListener {
let io = PollEvented2::new(listener);
let io = PollEvented::new(listener);
TcpListener { io }
}

View File

@ -9,8 +9,7 @@ use futures::{Future, Poll, Async};
use iovec::IoVec;
use mio;
use tokio_io::{AsyncRead, AsyncWrite};
use reactor::{Handle, PollEvented2};
use tokio_reactor::{Handle, PollEvented};
#[cfg(feature = "unstable-futures")]
use futures2;
@ -24,7 +23,7 @@ use futures2;
/// [accepting]: struct.TcpListener.html#method.accept
/// [listener]: struct.TcpListener.html
pub struct TcpStream {
io: PollEvented2<mio::net::TcpStream>,
io: PollEvented<mio::net::TcpStream>,
}
/// Future returned by `TcpStream::connect` which will resolve to a `TcpStream`
@ -62,7 +61,7 @@ impl TcpStream {
}
pub(crate) fn new(connected: mio::net::TcpStream) -> TcpStream {
let io = PollEvented2::new(connected);
let io = PollEvented::new(connected);
TcpStream { io }
}
@ -76,7 +75,7 @@ impl TcpStream {
-> io::Result<TcpStream>
{
let io = mio::net::TcpStream::from_stream(stream)?;
let io = PollEvented2::new_with_handle(io, handle)?;
let io = PollEvented::new_with_handle(io, handle)?;
Ok(TcpStream { io })
}
@ -107,7 +106,7 @@ impl TcpStream {
use self::ConnectFutureState::*;
let io = mio::net::TcpStream::connect_stream(stream, addr)
.and_then(|io| PollEvented2::new_with_handle(io, handle));
.and_then(|io| PollEvented::new_with_handle(io, handle));
let inner = match io {
Ok(io) => Waiting(TcpStream { io }),
@ -584,7 +583,7 @@ impl futures2::Future for ConnectFuture {
impl ConnectFutureState {
fn poll_inner<F>(&mut self, f: F) -> Poll<TcpStream, io::Error>
where F: FnOnce(&mut PollEvented2<mio::net::TcpStream>) -> Poll<mio::Ready, io::Error>
where F: FnOnce(&mut PollEvented<mio::net::TcpStream>) -> Poll<mio::Ready, io::Error>
{
{
let stream = match *self {

View File

@ -1,5 +1,5 @@
extern crate futures;
extern crate tokio;
extern crate tokio_tcp;
extern crate tokio_io;
use std::net::TcpStream;
@ -9,7 +9,7 @@ use std::io::{Write, Read};
use futures::Future;
use futures::stream::Stream;
use tokio_io::io::read_to_end;
use tokio::net::TcpListener;
use tokio_tcp::TcpListener;
macro_rules! t {
($e:expr) => (match $e {

View File

@ -1,6 +1,6 @@
extern crate env_logger;
extern crate futures;
extern crate tokio;
extern crate tokio_tcp;
extern crate tokio_io;
use std::io::{Read, Write};
@ -9,7 +9,7 @@ use std::thread;
use futures::Future;
use futures::stream::Stream;
use tokio::net::TcpListener;
use tokio_tcp::TcpListener;
use tokio_io::AsyncRead;
use tokio_io::io::copy;

View File

@ -1,5 +1,5 @@
extern crate futures;
extern crate tokio;
extern crate tokio_tcp;
extern crate tokio_io;
use std::net::TcpStream;
@ -9,7 +9,7 @@ use std::io::{Write, Read};
use futures::Future;
use futures::stream::Stream;
use tokio_io::io::read_to_end;
use tokio::net::TcpListener;
use tokio_tcp::TcpListener;
macro_rules! t {
($e:expr) => (match $e {

View File

@ -1,6 +1,6 @@
extern crate env_logger;
extern crate futures;
extern crate tokio;
extern crate tokio_tcp;
extern crate tokio_io;
use std::io::{Read, Write};
@ -11,7 +11,7 @@ use futures::Future;
use futures::stream::Stream;
use tokio_io::io::copy;
use tokio_io::AsyncRead;
use tokio::net::TcpListener;
use tokio_tcp::TcpListener;
macro_rules! t {
($e:expr) => (match $e {

View File

@ -1,13 +1,14 @@
extern crate env_logger;
extern crate tokio;
extern crate tokio_io;
extern crate tokio_tcp;
extern crate mio;
extern crate futures;
use std::{net, thread};
use std::sync::mpsc::channel;
use tokio::net::{TcpListener, TcpStream};
use tokio::prelude::*;
use futures::{Future, Stream};
use tokio_tcp::{TcpListener, TcpStream};
macro_rules! t {
@ -82,13 +83,14 @@ fn accept2() {
#[cfg(unix)]
mod unix {
use tokio::net::TcpStream;
use tokio::prelude::*;
use tokio_tcp::TcpStream;
use env_logger;
use futures::future;
use futures::{Future, future};
use mio::unix::UnixReady;
use tokio_io::AsyncRead;
use std::io::Write;
use std::{net, thread};
use std::time::Duration;

3
tokio-udp/CHANGELOG.md Normal file
View File

@ -0,0 +1,3 @@
# 0.1.0 (unreleased)
* Initial release

33
tokio-udp/Cargo.toml Normal file
View File

@ -0,0 +1,33 @@
[package]
name = "tokio-udp"
# When releasing to crates.io:
# - Update html_root_url.
# - Update CHANGELOG.md.
# - Create "v0.1.x" git tag.
version = "0.1.0"
authors = ["Carl Lerche <me@carllerche.com>"]
license = "MIT"
repository = "https://github.com/tokio-rs/tokio"
homepage = "https://tokio.rs"
documentation = "https://docs.rs/tokio-udp/0.1"
description = """
UDP bindings for tokio.
"""
categories = ["asynchronous"]
[dependencies]
tokio-io = { version = "0.1.6", path = "../tokio-io" }
tokio-reactor = { version = "0.1.0", path = "../tokio-reactor" }
bytes = "0.4"
mio = "0.6.14"
log = "0.4"
futures = "0.1.18"
futures2 = { version = "0.1", path = "../futures2", optional = true }
[dev-dependencies]
env_logger = { version = "0.4", default-features = false }
[features]
unstable-futures = ["futures2"]
default = []

25
tokio-udp/LICENSE Normal file
View File

@ -0,0 +1,25 @@
Copyright (c) 2018 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.

15
tokio-udp/README.md Normal file
View File

@ -0,0 +1,15 @@
# tokio-udp
UDP bindings for `tokio`.
[Documentation](https://tokio-rs.github.io/tokio/tokio_udp/)
## 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

@ -3,7 +3,7 @@ use std::net::{SocketAddr, Ipv4Addr, SocketAddrV4};
use futures::{Async, Poll, Stream, Sink, StartSend, AsyncSink};
use net::UdpSocket;
use super::UdpSocket;
use tokio_io::codec::{Decoder, Encoder};
use bytes::{BytesMut, BufMut};

42
tokio-udp/src/lib.rs Normal file
View File

@ -0,0 +1,42 @@
//! UDP bindings for `tokio`.
//!
//! This module contains the UDP networking types, similar to the standard
//! library, which can be used to implement networking protocols.
//!
//! The main struct for UDP is the [`UdpSocket`], which represents a UDP socket.
//! Reading and writing to it can be done using futures, which return the
//! [`RecvDgram`] and [`SendDgram`] structs respectively.
//!
//! For convience it's also possible to convert raw datagrams into higher-level
//! frames.
//!
//! [`UdpSocket`]: struct.UdpSocket.html
//! [`RecvDgram`]: struct.RecvDgram.html
//! [`SendDgram`]: struct.SendDgram.html
//! [`UdpFramed`]: struct.UdpFramed.html
//! [`framed`]: struct.UdpSocket.html#method.framed
#![doc(html_root_url = "https://docs.rs/tokio-tcp/0.1.0")]
#![deny(missing_docs, warnings, missing_debug_implementations)]
extern crate bytes;
#[macro_use]
extern crate futures;
extern crate mio;
#[macro_use]
extern crate log;
extern crate tokio_io;
extern crate tokio_reactor;
#[cfg(feature = "unstable-futures")]
extern crate futures2;
mod frame;
mod socket;
mod send_dgram;
mod recv_dgram;
pub use self::frame::UdpFramed;
pub use self::socket::UdpSocket;
pub use self::send_dgram::SendDgram;
pub use self::recv_dgram::RecvDgram;

View File

@ -1,4 +1,4 @@
use net::udp::socket::UdpSocket;
use super::socket::UdpSocket;
use std::io;
use std::net::SocketAddr;

View File

@ -1,4 +1,4 @@
use net::udp::socket::UdpSocket;
use super::socket::UdpSocket;
use std::io;
use std::net::SocketAddr;

View File

@ -1,4 +1,4 @@
use net::udp::{SendDgram, RecvDgram};
use super::{SendDgram, RecvDgram};
use std::io;
use std::net::{self, SocketAddr, Ipv4Addr, Ipv6Addr};
@ -7,11 +7,11 @@ use std::fmt;
use futures::{Async, Poll};
use mio;
use reactor::{Handle, PollEvented2};
use tokio_reactor::{Handle, PollEvented};
/// An I/O object representing a UDP socket.
pub struct UdpSocket {
io: PollEvented2<mio::net::UdpSocket>,
io: PollEvented<mio::net::UdpSocket>,
}
impl UdpSocket {
@ -23,7 +23,7 @@ impl UdpSocket {
}
fn new(socket: mio::net::UdpSocket) -> UdpSocket {
let io = PollEvented2::new(socket);
let io = PollEvented::new(socket);
UdpSocket { io: io }
}
@ -39,7 +39,7 @@ impl UdpSocket {
pub fn from_std(socket: net::UdpSocket,
handle: &Handle) -> io::Result<UdpSocket> {
let io = mio::net::UdpSocket::from_socket(socket)?;
let io = PollEvented2::new_with_handle(io, handle)?;
let io = PollEvented::new_with_handle(io, handle)?;
Ok(UdpSocket { io })
}

View File

@ -1,7 +1,7 @@
#![allow(deprecated)]
extern crate futures;
extern crate tokio;
extern crate tokio_udp;
#[macro_use]
extern crate tokio_io;
extern crate bytes;
@ -12,7 +12,7 @@ use std::net::SocketAddr;
use futures::{Future, Poll, Stream, Sink};
use tokio::net::{UdpSocket, UdpFramed};
use tokio_udp::{UdpSocket, UdpFramed};
use tokio_io::codec::{Encoder, Decoder};
use bytes::{BytesMut, BufMut};