Skip to content

Commit

Permalink
Move tokio::net module into tokio tcp/udp crates (tokio-rs#224)
Browse files Browse the repository at this point in the history
  • Loading branch information
srijs authored and carllerche committed Mar 14, 2018
1 parent 64435f5 commit 923a80e
Show file tree
Hide file tree
Showing 29 changed files with 312 additions and 90 deletions.
13 changes: 8 additions & 5 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ members = [
"tokio-io",
"tokio-reactor",
"tokio-threadpool",
"tokio-tcp",
"tokio-udp",
"futures2",
]

Expand All @@ -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"
Expand All @@ -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 = []
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
24 changes: 2 additions & 22 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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,
}
}
9 changes: 3 additions & 6 deletions src/net/mod.rs → src/net.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
8 changes: 0 additions & 8 deletions src/net/tcp/mod.rs

This file was deleted.

9 changes: 0 additions & 9 deletions src/net/udp/mod.rs

This file was deleted.

3 changes: 3 additions & 0 deletions tokio-tcp/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# 0.1.0 (unreleased)

* Initial release
33 changes: 33 additions & 0 deletions tokio-tcp/Cargo.toml
Original file line number Diff line number Diff line change
@@ -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 <[email protected]>"]
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 changes: 25 additions & 0 deletions tokio-tcp/LICENSE
Original file line number Diff line number Diff line change
@@ -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 changes: 15 additions & 0 deletions tokio-tcp/README.md
Original file line number Diff line number Diff line change
@@ -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.
4 changes: 2 additions & 2 deletions src/net/tcp/incoming.rs → tokio-tcp/src/incoming.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
59 changes: 59 additions & 0 deletions tokio-tcp/src/lib.rs
Original file line number Diff line number Diff line change
@@ -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,
}
}
13 changes: 6 additions & 7 deletions src/net/tcp/listener.rs → tokio-tcp/src/listener.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
use net::tcp::Incoming;
use net::tcp::TcpStream;
use super::Incoming;
use super::TcpStream;

use std::fmt;
use std::io;
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;
Expand All @@ -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 {
Expand Down Expand Up @@ -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 }
}

Expand Down
13 changes: 6 additions & 7 deletions src/net/tcp/stream.rs → tokio-tcp/src/stream.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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`
Expand Down Expand Up @@ -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 }
}

Expand All @@ -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 })
}
Expand Down Expand Up @@ -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 }),
Expand Down Expand Up @@ -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 {
Expand Down
4 changes: 2 additions & 2 deletions tests/chain.rs → tokio-tcp/tests/chain.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
extern crate futures;
extern crate tokio;
extern crate tokio_tcp;
extern crate tokio_io;

use std::net::TcpStream;
Expand All @@ -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 {
Expand Down
Loading

0 comments on commit 923a80e

Please sign in to comment.