Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update tokio to 0.3 #125

Merged
merged 1 commit into from
Oct 19, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ stream = []
log = "0.4"
futures-util = { version = "0.3", default-features = false, features = ["async-await", "sink", "std"] }
pin-project = "0.4.17"
tokio = { version = "0.2", default-features = false, features = ["io-util"] }
tokio = { version = "0.3", default-features = false, features = ["io-util"] }

[dependencies.tungstenite]
version = "0.11.1"
Expand All @@ -33,10 +33,10 @@ version = "0.2.0"

[dependencies.tokio-native-tls]
optional = true
version = "0.1"
version = "0.2"

[dev-dependencies]
futures-channel = "0.3"
tokio = { version = "0.2", default-features = false, features = ["io-std", "macros", "stream", "time"] }
tokio = { version = "0.3", default-features = false, features = ["io-std", "macros", "rt-multi-thread", "stream", "time"] }
nickelc marked this conversation as resolved.
Show resolved Hide resolved
url = "2.0.0"
env_logger = "0.7"
2 changes: 1 addition & 1 deletion examples/autobahn-server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ async fn main() {
env_logger::init();

let addr = "127.0.0.1:9002";
let mut listener = TcpListener::bind(&addr).await.expect("Can't listen");
let listener = TcpListener::bind(&addr).await.expect("Can't listen");
info!("Listening on: {}", addr);

while let Ok((stream, _)) = listener.accept().await {
Expand Down
2 changes: 1 addition & 1 deletion examples/echo-server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ async fn main() -> Result<(), Error> {

// Create the event loop and TCP listener we'll accept connections on.
let try_socket = TcpListener::bind(&addr).await;
let mut listener = try_socket.expect("Failed to bind");
let listener = try_socket.expect("Failed to bind");
info!("Listening on: {}", addr);

while let Ok((stream, _)) = listener.accept().await {
Expand Down
2 changes: 1 addition & 1 deletion examples/interval-server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ async fn main() {
env_logger::init();

let addr = "127.0.0.1:9002";
let mut listener = TcpListener::bind(&addr).await.expect("Can't listen");
let listener = TcpListener::bind(&addr).await.expect("Can't listen");
info!("Listening on: {}", addr);

while let Ok((stream, _)) = listener.accept().await {
Expand Down
2 changes: 1 addition & 1 deletion examples/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ async fn main() -> Result<(), IoError> {

// Create the event loop and TCP listener we'll accept connections on.
let try_socket = TcpListener::bind(&addr).await;
let mut listener = try_socket.expect("Failed to bind");
let listener = try_socket.expect("Failed to bind");
println!("Listening on: {}", addr);

// Let's spawn the handling of each connection in a separate task.
Expand Down
8 changes: 5 additions & 3 deletions src/compat.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use std::task::{Context, Poll};

use futures_util::task;
use std::sync::Arc;
use tokio::io::{AsyncRead, AsyncWrite};
use tokio::io::{AsyncRead, AsyncWrite, ReadBuf};
use tungstenite::Error as WsError;

pub(crate) enum ContextWaker {
Expand Down Expand Up @@ -145,15 +145,17 @@ where
{
fn read(&mut self, buf: &mut [u8]) -> std::io::Result<usize> {
trace!("{}:{} Read.read", file!(), line!());
let mut buf = ReadBuf::new(buf);
match self.with_context(ContextWaker::Read, |ctx, stream| {
trace!(
"{}:{} Read.with_context read -> poll_read",
file!(),
line!()
);
stream.poll_read(ctx, buf)
stream.poll_read(ctx, &mut buf)
}) {
Poll::Ready(r) => r,
Poll::Ready(Ok(_)) => Ok(buf.filled().len()),
Poll::Ready(Err(err)) => Err(err),
Poll::Pending => Err(std::io::Error::from(std::io::ErrorKind::WouldBlock)),
}
}
Expand Down
6 changes: 3 additions & 3 deletions src/stream.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use pin_project::pin_project;
use std::pin::Pin;
use std::task::{Context, Poll};

use tokio::io::{AsyncRead, AsyncWrite};
use tokio::io::{AsyncRead, AsyncWrite, ReadBuf};

/// Stream, either plain TCP or TLS.
#[pin_project(project = StreamProj)]
Expand All @@ -22,8 +22,8 @@ impl<S: AsyncRead + Unpin, T: AsyncRead + Unpin> AsyncRead for Stream<S, T> {
fn poll_read(
self: Pin<&mut Self>,
cx: &mut Context<'_>,
buf: &mut [u8],
) -> Poll<std::io::Result<usize>> {
buf: &mut ReadBuf<'_>,
) -> Poll<std::io::Result<()>> {
match self.project() {
StreamProj::Plain(ref mut s) => Pin::new(s).poll_read(cx, buf),
StreamProj::Tls(ref mut s) => Pin::new(s).poll_read(cx, buf),
Expand Down
4 changes: 2 additions & 2 deletions tests/communication.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ async fn communication() {
let (msg_tx, msg_rx) = futures_channel::oneshot::channel();

let f = async move {
let mut listener = TcpListener::bind("0.0.0.0:12345").await.unwrap();
let listener = TcpListener::bind("0.0.0.0:12345").await.unwrap();
info!("Server ready");
con_tx.send(()).unwrap();
info!("Waiting on next connection");
Expand Down Expand Up @@ -76,7 +76,7 @@ async fn split_communication() {
let (msg_tx, msg_rx) = futures_channel::oneshot::channel();

let f = async move {
let mut listener = TcpListener::bind("0.0.0.0:12346").await.unwrap();
let listener = TcpListener::bind("0.0.0.0:12346").await.unwrap();
info!("Server ready");
con_tx.send(()).unwrap();
info!("Waiting on next connection");
Expand Down
2 changes: 1 addition & 1 deletion tests/handshakes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ async fn handshakes() {
let (tx, rx) = futures_channel::oneshot::channel();

let f = async move {
let mut listener = TcpListener::bind("0.0.0.0:12345").await.unwrap();
let listener = TcpListener::bind("0.0.0.0:12345").await.unwrap();
tx.send(()).unwrap();
while let Ok((connection, _)) = listener.accept().await {
let stream = accept_async(connection).await;
Expand Down