Bump to Tokio 0.3.0

This commit is contained in:
John-John Tedro 2020-10-28 03:26:31 +01:00
parent 56e584fe76
commit 43c8b1cb63
5 changed files with 24 additions and 21 deletions

View file

@ -36,7 +36,7 @@ yaml = ["yaml_config"]
proxy = ["tokio-socks"] proxy = ["tokio-socks"]
tls-native = ["native-tls", "tokio-tls"] tls-native = ["native-tls", "tokio-native-tls"]
tls-rust = ["tokio-rustls", "webpki-roots"] tls-rust = ["tokio-rustls", "webpki-roots"]
@ -52,8 +52,8 @@ log = "0.4.0"
parking_lot = "0.11.0" parking_lot = "0.11.0"
pin-utils = "0.1.0-alpha.4" pin-utils = "0.1.0-alpha.4"
thiserror = "1.0.0" thiserror = "1.0.0"
tokio = { version = "0.2.0", features = ["macros", "net", "stream", "time"] } tokio = { version = "0.3.0", features = ["net", "stream", "time"] }
tokio-util = { version = "0.3.0", features = ["codec"] } tokio-util = { version = "0.4.0", features = ["codec"] }
# Feature - Config # Feature - Config
serde = { version = "1.0.0", optional = true } serde = { version = "1.0.0", optional = true }
@ -67,8 +67,8 @@ tokio-socks = { version = "0.3.0", optional = true }
# Feature - TLS # Feature - TLS
native-tls = { version = "0.2.0", optional = true } native-tls = { version = "0.2.0", optional = true }
tokio-rustls = { version = "0.14.0", optional = true } tokio-rustls = { version = "0.20.0", optional = true }
tokio-tls = { version = "0.3.0", optional = true } tokio-native-tls = { version = "0.2.0", optional = true }
webpki-roots = { version = "0.20.0", optional = true } webpki-roots = { version = "0.20.0", optional = true }
@ -78,6 +78,7 @@ args = "2.0.0"
env_logger = "0.7.0" env_logger = "0.7.0"
futures = "0.3.0" futures = "0.3.0"
getopts = "0.2.0" getopts = "0.2.0"
tokio = { version = "0.3.0", features = ["rt", "rt-multi-thread", "macros", "net", "stream", "time"] }
[[example]] [[example]]

View file

@ -21,5 +21,5 @@ encoding = "0.2.0"
thiserror = "1.0.0" thiserror = "1.0.0"
bytes = { version = "0.5.0", optional = true } bytes = { version = "0.5.0", optional = true }
tokio = { version = "0.2.0", optional = true } tokio = { version = "0.3.0", optional = true }
tokio-util = { version = "0.3.0", features = ["codec"], optional = true } tokio-util = { version = "0.4.0", features = ["codec"], optional = true }

View file

@ -7,7 +7,7 @@ use std::{
task::{Context, Poll}, task::{Context, Poll},
}; };
use tokio::net::TcpStream; use tokio::net::TcpStream;
use tokio_util::codec::Decoder; use tokio_util::codec::Framed;
#[cfg(feature = "proxy")] #[cfg(feature = "proxy")]
use tokio_socks::tcp::Socks5Stream; use tokio_socks::tcp::Socks5Stream;
@ -22,7 +22,7 @@ use std::{fs::File, io::Read};
use native_tls::{Certificate, Identity, TlsConnector}; use native_tls::{Certificate, Identity, TlsConnector};
#[cfg(feature = "tls-native")] #[cfg(feature = "tls-native")]
use tokio_tls::{self, TlsStream}; use tokio_native_tls::{self, TlsStream};
#[cfg(feature = "tls-rust")] #[cfg(feature = "tls-rust")]
use std::{ use std::{
@ -150,7 +150,7 @@ impl Connection {
tx: UnboundedSender<Message>, tx: UnboundedSender<Message>,
) -> error::Result<Transport<TcpStream>> { ) -> error::Result<Transport<TcpStream>> {
let stream = Self::new_stream(config).await?; let stream = Self::new_stream(config).await?;
let framed = IrcCodec::new(config.encoding())?.framed(stream); let framed = Framed::new(stream, IrcCodec::new(config.encoding())?);
Ok(Transport::new(&config, framed, tx)) Ok(Transport::new(&config, framed, tx))
} }
@ -184,12 +184,12 @@ impl Connection {
); );
} }
let connector: tokio_tls::TlsConnector = builder.build()?.into(); let connector: tokio_native_tls::TlsConnector = builder.build()?.into();
let domain = config.server()?; let domain = config.server()?;
let stream = Self::new_stream(config).await?; let stream = Self::new_stream(config).await?;
let stream = connector.connect(domain, stream).await?; let stream = connector.connect(domain, stream).await?;
let framed = IrcCodec::new(config.encoding())?.framed(stream); let framed = Framed::new(stream, IrcCodec::new(config.encoding())?);
Ok(Transport::new(&config, framed, tx)) Ok(Transport::new(&config, framed, tx))
} }
@ -236,7 +236,7 @@ impl Connection {
let stream = Self::new_stream(config).await?; let stream = Self::new_stream(config).await?;
let stream = connector.connect(domain, stream).await?; let stream = connector.connect(domain, stream).await?;
let framed = IrcCodec::new(config.encoding())?.framed(stream); let framed = Framed::new(stream, IrcCodec::new(config.encoding())?);
Ok(Transport::new(&config, framed, tx)) Ok(Transport::new(&config, framed, tx))
} }
@ -262,7 +262,7 @@ impl Connection {
})?; })?;
let stream = MockStream::new(&initial); let stream = MockStream::new(&initial);
let framed = IrcCodec::new(config.encoding())?.framed(stream); let framed = Framed::new(stream, IrcCodec::new(config.encoding())?);
Ok(Transport::new(&config, framed, tx)) Ok(Transport::new(&config, framed, tx))
} }

View file

@ -3,7 +3,7 @@ use std::{
pin::Pin, pin::Pin,
task::{Context, Poll}, task::{Context, Poll},
}; };
use tokio::io::{AsyncRead, AsyncWrite}; use tokio::io::{AsyncRead, AsyncWrite, ReadBuf};
/// A fake stream for testing network applications backed by buffers. /// A fake stream for testing network applications backed by buffers.
#[derive(Clone, Debug)] #[derive(Clone, Debug)]
@ -41,9 +41,11 @@ impl AsyncRead for MockStream {
fn poll_read( fn poll_read(
mut self: Pin<&mut Self>, mut self: Pin<&mut Self>,
_: &mut Context<'_>, _: &mut Context<'_>,
buf: &mut [u8], buf: &mut ReadBuf<'_>,
) -> Poll<io::Result<usize>> { ) -> Poll<io::Result<()>> {
Poll::Ready(self.as_mut().received.read(buf)) let n = self.as_mut().received.read(buf.initialize_unfilled())?;
buf.advance(n);
Poll::Ready(Ok(()))
} }
} }

View file

@ -13,7 +13,7 @@ use futures_channel::mpsc::UnboundedSender;
use futures_util::{future::Future, ready, sink::Sink, stream::Stream}; use futures_util::{future::Future, ready, sink::Sink, stream::Stream};
use tokio::{ use tokio::{
io::{AsyncRead, AsyncWrite}, io::{AsyncRead, AsyncWrite},
time::{self, Delay, Interval}, time::{self, Interval, Sleep},
}; };
use tokio_util::codec::Framed; use tokio_util::codec::Framed;
@ -31,7 +31,7 @@ struct Pinger {
/// The amount of time to wait before timing out from no ping response. /// The amount of time to wait before timing out from no ping response.
ping_timeout: Duration, ping_timeout: Duration,
/// The instant that the last ping was sent to the server. /// The instant that the last ping was sent to the server.
ping_deadline: Option<Delay>, ping_deadline: Option<Sleep>,
/// The interval at which to send pings. /// The interval at which to send pings.
ping_interval: Interval, ping_interval: Interval,
} }
@ -98,7 +98,7 @@ impl Pinger {
/// Set the ping deadline. /// Set the ping deadline.
fn set_deadline(&mut self) { fn set_deadline(&mut self) {
if self.ping_deadline.is_none() { if self.ping_deadline.is_none() {
let ping_deadline = time::delay_for(self.ping_timeout); let ping_deadline = time::sleep(self.ping_timeout);
self.ping_deadline = Some(ping_deadline); self.ping_deadline = Some(ping_deadline);
} }
} }