diff --git a/quinn/src/recv_stream.rs b/quinn/src/recv_stream.rs index a1c3a0573..7d491bf5e 100644 --- a/quinn/src/recv_stream.rs +++ b/quinn/src/recv_stream.rs @@ -141,7 +141,25 @@ impl RecvStream { .await } - fn poll_read( + /// Attempts to read from the stream into buf. + /// + /// On success, returns Poll::Ready(Ok(num_bytes_read)) and places data in + /// the buf. If no data was read, it implies that EOF has been reached. + /// + /// If no data is available for reading, the method returns Poll::Pending + /// and arranges for the current task (via cx.waker()) to receive a notification + /// when the stream becomes readable or is closed. + pub fn poll_read( + &mut self, + cx: &mut Context, + buf: &mut [u8], + ) -> Poll> { + let mut buf = ReadBuf::new(buf); + ready!(self.poll_read_buf(cx, &mut buf))?; + Poll::Ready(Ok(buf.filled().len())) + } + + fn poll_read_buf( &mut self, cx: &mut Context, buf: &mut ReadBuf<'_>, @@ -196,7 +214,14 @@ impl RecvStream { .await } - /// Foundation of [`Self::read_chunk`] + /// Attempts to read a chunk from the stream. + /// + /// On success, returns `Poll::Ready(Ok(Some(chunk)))`. If `Poll::Ready(Ok(None))` + /// is returned, it implies that EOF has been reached. + /// + /// If no data is available for reading, the method returns `Poll::Pending` + /// and arranges for the current task (via cx.waker()) to receive a notification + /// when the stream becomes readable or is closed. fn poll_read_chunk( &mut self, cx: &mut Context, @@ -451,7 +476,7 @@ impl futures_io::AsyncRead for RecvStream { buf: &mut [u8], ) -> Poll> { let mut buf = ReadBuf::new(buf); - ready!(RecvStream::poll_read(self.get_mut(), cx, &mut buf))?; + ready!(RecvStream::poll_read_buf(self.get_mut(), cx, &mut buf))?; Poll::Ready(Ok(buf.filled().len())) } } @@ -462,7 +487,7 @@ impl tokio::io::AsyncRead for RecvStream { cx: &mut Context<'_>, buf: &mut ReadBuf<'_>, ) -> Poll> { - ready!(Self::poll_read(self.get_mut(), cx, buf))?; + ready!(Self::poll_read_buf(self.get_mut(), cx, buf))?; Poll::Ready(Ok(())) } } @@ -550,7 +575,7 @@ impl<'a> Future for Read<'a> { fn poll(self: Pin<&mut Self>, cx: &mut Context) -> Poll { let this = self.get_mut(); - ready!(this.stream.poll_read(cx, &mut this.buf))?; + ready!(this.stream.poll_read_buf(cx, &mut this.buf))?; match this.buf.filled().len() { 0 if this.buf.capacity() != 0 => Poll::Ready(Ok(None)), n => Poll::Ready(Ok(Some(n))), @@ -574,7 +599,7 @@ impl<'a> Future for ReadExact<'a> { let total = this.buf.remaining(); let mut remaining = total; while remaining > 0 { - ready!(this.stream.poll_read(cx, &mut this.buf))?; + ready!(this.stream.poll_read_buf(cx, &mut this.buf))?; let new = this.buf.remaining(); if new == remaining { let read = total - remaining;