Skip to content

Commit

Permalink
Merge pull request cloudflare#4 from taiki-e/deps
Browse files Browse the repository at this point in the history
Update tokio and bytes to 1.0
  • Loading branch information
jonhoo authored Jan 15, 2021
2 parents 05af389 + aec7673 commit 0ad1164
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 11 deletions.
6 changes: 3 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@ byteorder = "1.0.0"
futures-core = "0.3.0"
futures-sink = "0.3.0"
serde = "1.0.8"
tokio = { version = "0.2.0", features = ["tcp"] }
bytes = "0.5.0"
tokio = { version = "1.0", features = ["net"] }
bytes = "1.0"

[dev-dependencies]
futures = "0.3.0"
tokio = { version = "0.2.0", features = ["full"] }
tokio = { version = "1.0", features = ["full"] }
7 changes: 4 additions & 3 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,11 @@ pub use crate::writer::{AsyncDestination, BincodeWriterFor, SyncDestination};
mod tests {
use super::*;
use futures::prelude::*;
use tokio::io::AsyncWriteExt;

#[tokio::test]
async fn it_works() {
let mut echo = tokio::net::TcpListener::bind("127.0.0.1:0").await.unwrap();
let echo = tokio::net::TcpListener::bind("127.0.0.1:0").await.unwrap();
let addr = echo.local_addr().unwrap();

tokio::spawn(async move {
Expand All @@ -51,7 +52,7 @@ mod tests {

#[tokio::test]
async fn lots() {
let mut echo = tokio::net::TcpListener::bind("127.0.0.1:0").await.unwrap();
let echo = tokio::net::TcpListener::bind("127.0.0.1:0").await.unwrap();
let addr = echo.local_addr().unwrap();

tokio::spawn(async move {
Expand All @@ -71,7 +72,7 @@ mod tests {
.await
.unwrap();

tokio::net::TcpStream::shutdown(c.get_mut(), std::net::Shutdown::Write).unwrap();
c.get_mut().shutdown().await.unwrap();

let mut at = 0;
while let Some(got) = c.next().await.transpose().unwrap() {
Expand Down
6 changes: 4 additions & 2 deletions src/reader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use std::io;
use std::marker::PhantomData;
use std::pin::Pin;
use std::task::{Context, Poll};
use tokio::io::AsyncRead;
use tokio::io::{AsyncRead, ReadBuf};

/// A wrapper around an asynchronous reader that produces an asynchronous stream of
/// bincode-decoded values.
Expand Down Expand Up @@ -139,7 +139,9 @@ where
unsafe { rest.set_len(max) };

while self.buffer.len() < target_size {
let n = ready!(Pin::new(&mut self.reader).poll_read(cx, &mut rest[..]))?;
let mut buf = ReadBuf::new(&mut rest[..]);
ready!(Pin::new(&mut self.reader).poll_read(cx, &mut buf))?;
let n = buf.filled().len();
if n == 0 {
if self.buffer.len() == 0 {
return Poll::Ready(Ok(FillResult::EOF));
Expand Down
6 changes: 3 additions & 3 deletions src/stream.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use std::ops::{Deref, DerefMut};
use std::pin::Pin;
use std::task::{Context, Poll};
use std::{fmt, io};
use tokio::io::AsyncRead;
use tokio::io::{AsyncRead, ReadBuf};

/// A wrapper around an asynchronous stream that receives and sends bincode-encoded values.
///
Expand Down Expand Up @@ -135,8 +135,8 @@ where
fn poll_read(
self: Pin<&mut Self>,
cx: &mut Context,
buf: &mut [u8],
) -> Poll<Result<usize, io::Error>> {
buf: &mut ReadBuf,
) -> Poll<Result<(), io::Error>> {
Pin::new(self.get_mut().get_mut()).poll_read(cx, buf)
}
}
Expand Down

0 comments on commit 0ad1164

Please sign in to comment.