Skip to content

Commit

Permalink
Pass byte read count to FinishEarly
Browse files Browse the repository at this point in the history
If read_exact() finishes early (end of stream), report the number of
bytes actually read.

Fixes #1663
  • Loading branch information
rom1v authored and Ralith committed Sep 20, 2023
1 parent f81c2fa commit e5bf98c
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions quinn/src/recv_stream.rs
Original file line number Diff line number Diff line change
Expand Up @@ -537,12 +537,14 @@ impl<'a> Future for ReadExact<'a> {
type Output = Result<(), ReadExactError>;
fn poll(self: Pin<&mut Self>, cx: &mut Context) -> Poll<Self::Output> {
let this = self.get_mut();
let mut remaining = this.buf.remaining();
let total = this.buf.remaining();
let mut remaining = total;
while remaining > 0 {
ready!(this.stream.poll_read(cx, &mut this.buf))?;
let new = this.buf.remaining();
if new == remaining {
return Poll::Ready(Err(ReadExactError::FinishedEarly));
let read = total - remaining;
return Poll::Ready(Err(ReadExactError::FinishedEarly(read)));
}
remaining = new;
}
Expand All @@ -554,8 +556,8 @@ impl<'a> Future for ReadExact<'a> {
#[derive(Debug, Error, Clone, PartialEq, Eq)]
pub enum ReadExactError {
/// The stream finished before all bytes were read
#[error("stream finished early")]
FinishedEarly,
#[error("stream finished early ({0} bytes read)")]
FinishedEarly(usize),
/// A read error occurred
#[error(transparent)]
ReadError(#[from] ReadError),
Expand Down

0 comments on commit e5bf98c

Please sign in to comment.