Skip to content

Commit

Permalink
codec: use poll_write_buf
Browse files Browse the repository at this point in the history
Signed-off-by: Eliza Weisman <eliza@buoyant.io>
  • Loading branch information
hawkw committed Nov 20, 2020
1 parent 45b7345 commit a124b06
Showing 1 changed file with 3 additions and 5 deletions.
8 changes: 3 additions & 5 deletions tokio-util/src/codec/framed_impl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use tokio::{
stream::Stream,
};

use bytes::{Buf, BytesMut};
use bytes::BytesMut;
use futures_core::ready;
use futures_sink::Sink;
use log::trace;
Expand Down Expand Up @@ -189,15 +189,15 @@ where
}

fn poll_flush(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Result<(), Self::Error>> {
use crate::util::poll_write_buf;
trace!("flushing framed transport");
let mut pinned = self.project();

while !pinned.state.borrow_mut().buffer.is_empty() {
let WriteFrame { buffer } = pinned.state.borrow_mut();
trace!("writing; remaining={}", buffer.len());

let buf = &buffer;
let n = ready!(pinned.inner.as_mut().poll_write(cx, &buf))?;
let n = ready!(poll_write_buf(pinned.inner.as_mut(), cx, buffer))?;

if n == 0 {
return Poll::Ready(Err(io::Error::new(
Expand All @@ -207,8 +207,6 @@ where
)
.into()));
}

pinned.state.borrow_mut().buffer.advance(n);
}

// Try flushing the underlying IO
Expand Down

0 comments on commit a124b06

Please sign in to comment.