From 923a80e098d4d8355c65d3c80e5789ea0cbded95 Mon Sep 17 00:00:00 2001 From: Sam Rijs Date: Thu, 15 Mar 2018 03:38:59 +1100 Subject: [PATCH] Move tokio::net module into tokio tcp/udp crates (#224) --- Cargo.toml | 13 ++-- README.md | 6 ++ src/lib.rs | 24 +------- src/{net/mod.rs => net.rs} | 9 +-- src/net/tcp/mod.rs | 8 --- src/net/udp/mod.rs | 9 --- tokio-tcp/CHANGELOG.md | 3 + tokio-tcp/Cargo.toml | 33 +++++++++++ tokio-tcp/LICENSE | 25 ++++++++ tokio-tcp/README.md | 15 +++++ {src/net/tcp => tokio-tcp/src}/incoming.rs | 4 +- tokio-tcp/src/lib.rs | 59 +++++++++++++++++++ {src/net/tcp => tokio-tcp/src}/listener.rs | 13 ++-- {src/net/tcp => tokio-tcp/src}/stream.rs | 13 ++-- {tests => tokio-tcp/tests}/chain.rs | 4 +- {tests => tokio-tcp/tests}/echo.rs | 4 +- {tests => tokio-tcp/tests}/limit.rs | 4 +- {tests => tokio-tcp/tests}/stream-buffered.rs | 4 +- {tests => tokio-tcp/tests}/tcp.rs | 14 +++-- tokio-udp/CHANGELOG.md | 3 + tokio-udp/Cargo.toml | 33 +++++++++++ tokio-udp/LICENSE | 25 ++++++++ tokio-udp/README.md | 15 +++++ {src/net/udp => tokio-udp/src}/frame.rs | 2 +- tokio-udp/src/lib.rs | 42 +++++++++++++ {src/net/udp => tokio-udp/src}/recv_dgram.rs | 2 +- {src/net/udp => tokio-udp/src}/send_dgram.rs | 2 +- {src/net/udp => tokio-udp/src}/socket.rs | 10 ++-- {tests => tokio-udp/tests}/udp.rs | 4 +- 29 files changed, 312 insertions(+), 90 deletions(-) rename src/{net/mod.rs => net.rs} (89%) delete mode 100644 src/net/tcp/mod.rs delete mode 100644 src/net/udp/mod.rs create mode 100644 tokio-tcp/CHANGELOG.md create mode 100644 tokio-tcp/Cargo.toml create mode 100644 tokio-tcp/LICENSE create mode 100644 tokio-tcp/README.md rename {src/net/tcp => tokio-tcp/src}/incoming.rs (95%) create mode 100644 tokio-tcp/src/lib.rs rename {src/net/tcp => tokio-tcp/src}/listener.rs (97%) rename {src/net/tcp => tokio-tcp/src}/stream.rs (98%) rename {tests => tokio-tcp/tests}/chain.rs (95%) rename {tests => tokio-tcp/tests}/echo.rs (96%) rename {tests => tokio-tcp/tests}/limit.rs (94%) rename {tests => tokio-tcp/tests}/stream-buffered.rs (96%) rename {tests => tokio-tcp/tests}/tcp.rs (92%) create mode 100644 tokio-udp/CHANGELOG.md create mode 100644 tokio-udp/Cargo.toml create mode 100644 tokio-udp/LICENSE create mode 100644 tokio-udp/README.md rename {src/net/udp => tokio-udp/src}/frame.rs (99%) create mode 100644 tokio-udp/src/lib.rs rename {src/net/udp => tokio-udp/src}/recv_dgram.rs (97%) rename {src/net/udp => tokio-udp/src}/send_dgram.rs (98%) rename {src/net/udp => tokio-udp/src}/socket.rs (98%) rename {tests => tokio-udp/tests}/udp.rs (99%) diff --git a/Cargo.toml b/Cargo.toml index 7af8cc430..eb4c8664e 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -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 = [] diff --git a/README.md b/README.md index 791f500ab..742ed89e4 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/src/lib.rs b/src/lib.rs index 6bbf24168..2512cacb4 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -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(old: futures::Async) -> futures2::Async { - match old { - futures::Async::Ready(x) => futures2::Async::Ready(x), - futures::Async::NotReady => futures2::Async::Pending, - } -} - -#[cfg(feature = "unstable-futures")] -fn lower_async(new: futures2::Async) -> futures::Async { - match new { - futures2::Async::Ready(x) => futures::Async::Ready(x), - futures2::Async::Pending => futures::Async::NotReady, - } -} diff --git a/src/net/mod.rs b/src/net.rs similarity index 89% rename from src/net/mod.rs rename to src/net.rs index 077e886a8..f3378eea6 100644 --- a/src/net/mod.rs +++ b/src/net.rs @@ -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}; diff --git a/src/net/tcp/mod.rs b/src/net/tcp/mod.rs deleted file mode 100644 index 5454510ca..000000000 --- a/src/net/tcp/mod.rs +++ /dev/null @@ -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; diff --git a/src/net/udp/mod.rs b/src/net/udp/mod.rs deleted file mode 100644 index 0610b4d2b..000000000 --- a/src/net/udp/mod.rs +++ /dev/null @@ -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; diff --git a/tokio-tcp/CHANGELOG.md b/tokio-tcp/CHANGELOG.md new file mode 100644 index 000000000..fb22aa7c8 --- /dev/null +++ b/tokio-tcp/CHANGELOG.md @@ -0,0 +1,3 @@ +# 0.1.0 (unreleased) + +* Initial release diff --git a/tokio-tcp/Cargo.toml b/tokio-tcp/Cargo.toml new file mode 100644 index 000000000..00a25dfbb --- /dev/null +++ b/tokio-tcp/Cargo.toml @@ -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 "] +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 = [] diff --git a/tokio-tcp/LICENSE b/tokio-tcp/LICENSE new file mode 100644 index 000000000..38c1e27b8 --- /dev/null +++ b/tokio-tcp/LICENSE @@ -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. diff --git a/tokio-tcp/README.md b/tokio-tcp/README.md new file mode 100644 index 000000000..9cfc177b8 --- /dev/null +++ b/tokio-tcp/README.md @@ -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. diff --git a/src/net/tcp/incoming.rs b/tokio-tcp/src/incoming.rs similarity index 95% rename from src/net/tcp/incoming.rs rename to tokio-tcp/src/incoming.rs index 591acc204..6726224b8 100644 --- a/src/net/tcp/incoming.rs +++ b/tokio-tcp/src/incoming.rs @@ -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; diff --git a/tokio-tcp/src/lib.rs b/tokio-tcp/src/lib.rs new file mode 100644 index 000000000..08d41623c --- /dev/null +++ b/tokio-tcp/src/lib.rs @@ -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(old: futures::Async) -> futures2::Async { + match old { + futures::Async::Ready(x) => futures2::Async::Ready(x), + futures::Async::NotReady => futures2::Async::Pending, + } +} + +#[cfg(feature = "unstable-futures")] +fn lower_async(new: futures2::Async) -> futures::Async { + match new { + futures2::Async::Ready(x) => futures::Async::Ready(x), + futures2::Async::Pending => futures::Async::NotReady, + } +} diff --git a/src/net/tcp/listener.rs b/tokio-tcp/src/listener.rs similarity index 97% rename from src/net/tcp/listener.rs rename to tokio-tcp/src/listener.rs index bc9a736a6..41be8245d 100644 --- a/src/net/tcp/listener.rs +++ b/tokio-tcp/src/listener.rs @@ -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, + io: PollEvented, } impl TcpListener { @@ -174,12 +173,12 @@ impl TcpListener { -> io::Result { 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 } } diff --git a/src/net/tcp/stream.rs b/tokio-tcp/src/stream.rs similarity index 98% rename from src/net/tcp/stream.rs rename to tokio-tcp/src/stream.rs index 602bd4bb2..c0ae87659 100644 --- a/src/net/tcp/stream.rs +++ b/tokio-tcp/src/stream.rs @@ -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, + io: PollEvented, } /// 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 { 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(&mut self, f: F) -> Poll - where F: FnOnce(&mut PollEvented2) -> Poll + where F: FnOnce(&mut PollEvented) -> Poll { { let stream = match *self { diff --git a/tests/chain.rs b/tokio-tcp/tests/chain.rs similarity index 95% rename from tests/chain.rs rename to tokio-tcp/tests/chain.rs index b9ac48186..c4e37f103 100644 --- a/tests/chain.rs +++ b/tokio-tcp/tests/chain.rs @@ -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 { diff --git a/tests/echo.rs b/tokio-tcp/tests/echo.rs similarity index 96% rename from tests/echo.rs rename to tokio-tcp/tests/echo.rs index d5bdae811..3c020b193 100644 --- a/tests/echo.rs +++ b/tokio-tcp/tests/echo.rs @@ -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; diff --git a/tests/limit.rs b/tokio-tcp/tests/limit.rs similarity index 94% rename from tests/limit.rs rename to tokio-tcp/tests/limit.rs index 7055ce9b6..8714da9a5 100644 --- a/tests/limit.rs +++ b/tokio-tcp/tests/limit.rs @@ -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 { diff --git a/tests/stream-buffered.rs b/tokio-tcp/tests/stream-buffered.rs similarity index 96% rename from tests/stream-buffered.rs rename to tokio-tcp/tests/stream-buffered.rs index 78fe1c372..a6d71298d 100644 --- a/tests/stream-buffered.rs +++ b/tokio-tcp/tests/stream-buffered.rs @@ -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 { diff --git a/tests/tcp.rs b/tokio-tcp/tests/tcp.rs similarity index 92% rename from tests/tcp.rs rename to tokio-tcp/tests/tcp.rs index 5694e8a61..c905711b2 100644 --- a/tests/tcp.rs +++ b/tokio-tcp/tests/tcp.rs @@ -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; diff --git a/tokio-udp/CHANGELOG.md b/tokio-udp/CHANGELOG.md new file mode 100644 index 000000000..fb22aa7c8 --- /dev/null +++ b/tokio-udp/CHANGELOG.md @@ -0,0 +1,3 @@ +# 0.1.0 (unreleased) + +* Initial release diff --git a/tokio-udp/Cargo.toml b/tokio-udp/Cargo.toml new file mode 100644 index 000000000..c73ef68db --- /dev/null +++ b/tokio-udp/Cargo.toml @@ -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 "] +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 = [] diff --git a/tokio-udp/LICENSE b/tokio-udp/LICENSE new file mode 100644 index 000000000..38c1e27b8 --- /dev/null +++ b/tokio-udp/LICENSE @@ -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. diff --git a/tokio-udp/README.md b/tokio-udp/README.md new file mode 100644 index 000000000..e677c0749 --- /dev/null +++ b/tokio-udp/README.md @@ -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. diff --git a/src/net/udp/frame.rs b/tokio-udp/src/frame.rs similarity index 99% rename from src/net/udp/frame.rs rename to tokio-udp/src/frame.rs index c06b2279c..f3d8e0b23 100644 --- a/src/net/udp/frame.rs +++ b/tokio-udp/src/frame.rs @@ -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}; diff --git a/tokio-udp/src/lib.rs b/tokio-udp/src/lib.rs new file mode 100644 index 000000000..bf7bd28fc --- /dev/null +++ b/tokio-udp/src/lib.rs @@ -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; diff --git a/src/net/udp/recv_dgram.rs b/tokio-udp/src/recv_dgram.rs similarity index 97% rename from src/net/udp/recv_dgram.rs rename to tokio-udp/src/recv_dgram.rs index 86ced3d35..2a9e29606 100644 --- a/src/net/udp/recv_dgram.rs +++ b/tokio-udp/src/recv_dgram.rs @@ -1,4 +1,4 @@ -use net::udp::socket::UdpSocket; +use super::socket::UdpSocket; use std::io; use std::net::SocketAddr; diff --git a/src/net/udp/send_dgram.rs b/tokio-udp/src/send_dgram.rs similarity index 98% rename from src/net/udp/send_dgram.rs rename to tokio-udp/src/send_dgram.rs index c17019a8d..50d650389 100644 --- a/src/net/udp/send_dgram.rs +++ b/tokio-udp/src/send_dgram.rs @@ -1,4 +1,4 @@ -use net::udp::socket::UdpSocket; +use super::socket::UdpSocket; use std::io; use std::net::SocketAddr; diff --git a/src/net/udp/socket.rs b/tokio-udp/src/socket.rs similarity index 98% rename from src/net/udp/socket.rs rename to tokio-udp/src/socket.rs index 46c3345f4..d671d255a 100644 --- a/src/net/udp/socket.rs +++ b/tokio-udp/src/socket.rs @@ -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, + io: PollEvented, } 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 { 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 }) } diff --git a/tests/udp.rs b/tokio-udp/tests/udp.rs similarity index 99% rename from tests/udp.rs rename to tokio-udp/tests/udp.rs index 8faebee62..0eb2f1809 100644 --- a/tests/udp.rs +++ b/tokio-udp/tests/udp.rs @@ -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};