Skip to content

Commit

Permalink
Use tokio_util::io::poll_read_buf
Browse files Browse the repository at this point in the history
  • Loading branch information
Urhengulas committed Nov 7, 2020
1 parent b950b6f commit 2588281
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ tokio-tungstenite = { version = "0.12", default-features = false, optional = tru
percent-encoding = "2.1"
pin-project = "1.0"
tokio-rustls = { version = "0.20", optional = true }
tokio-util = { git = "https://github.com/tokio-rs/tokio/", features = ["io"] }

[dev-dependencies]
pretty_env_logger = "0.4"
Expand Down
9 changes: 5 additions & 4 deletions src/filters/fs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use std::pin::Pin;
use std::sync::Arc;
use std::task::Poll;

use bytes::{Bytes, BytesMut};
use bytes::{BufMut, Bytes, BytesMut};
use futures::future::Either;
use futures::{future, ready, stream, FutureExt, Stream, StreamExt, TryFutureExt};
use headers::{
Expand All @@ -23,6 +23,7 @@ use mime_guess;
use percent_encoding::percent_decode_str;
use tokio::fs::File as TkFile;
use tokio::io::{AsyncRead, AsyncSeekExt, ReadBuf};
use tokio_util::io::poll_read_buf;

use crate::filter::{Filter, FilterClone, One};
use crate::reject::{self, Rejection};
Expand Down Expand Up @@ -419,9 +420,9 @@ fn file_stream(
}
reserve_at_least(&mut buf, buf_size);

let mut read_buf = ReadBuf::new(&mut buf);
let n = match ready!(Pin::new(&mut f).poll_read(cx, &mut read_buf)) {
Ok(_n) => read_buf.filled().len() as u64,
let len_before = buf.len();
let n = match ready!(poll_read_buf(Pin::new(&mut f), cx, &mut buf)) {
Ok(n) => n as u64,
Err(err) => {
tracing::debug!("file read error: {}", err);
return Poll::Ready(Some(Err(err)));
Expand Down

0 comments on commit 2588281

Please sign in to comment.