Skip to content

Commit 49c808e

Browse files
committed
add 'Connection:poll_recv_data()'
1 parent c11410c commit 49c808e

File tree

2 files changed

+27
-11
lines changed

2 files changed

+27
-11
lines changed

h3/src/connection.rs

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -623,16 +623,21 @@ where
623623
S: quic::RecvStream,
624624
{
625625
/// Receive some of the request body.
626-
pub async fn recv_data(&mut self) -> Result<Option<impl Buf>, Error> {
626+
pub fn poll_recv_data(
627+
&mut self,
628+
cx: &mut Context<'_>,
629+
) -> Poll<Result<Option<impl Buf>, Error>> {
627630
if !self.stream.has_data() {
628-
let frame = future::poll_fn(|cx| self.stream.poll_next(cx))
629-
.await
631+
let frame = self
632+
.stream
633+
.poll_next(cx)
630634
.map_err(|e| self.maybe_conn_err(e))?;
631-
match frame {
635+
636+
match ready!(frame) {
632637
Some(Frame::Data { .. }) => (),
633638
Some(Frame::Headers(encoded)) => {
634639
self.trailers = Some(encoded);
635-
return Ok(None);
640+
return Poll::Ready(Ok(None));
636641
}
637642

638643
//= https://www.rfc-editor.org/rfc/rfc9114#section-4.1
@@ -657,15 +662,18 @@ where
657662
//# The MAX_PUSH_ID frame is always sent on the control stream. Receipt
658663
//# of a MAX_PUSH_ID frame on any other stream MUST be treated as a
659664
//# connection error of type H3_FRAME_UNEXPECTED.
660-
Some(_) => return Err(Code::H3_FRAME_UNEXPECTED.into()),
661-
None => return Ok(None),
665+
Some(_) => return Poll::Ready(Err(Code::H3_FRAME_UNEXPECTED.into())),
666+
None => return Poll::Ready(Ok(None)),
662667
}
663668
}
664669

665-
let data = future::poll_fn(|cx| self.stream.poll_data(cx))
666-
.await
667-
.map_err(|e| self.maybe_conn_err(e))?;
668-
Ok(data)
670+
self.stream
671+
.poll_data(cx)
672+
.map_err(|e| self.maybe_conn_err(e))
673+
}
674+
/// Receive some of the request body.
675+
pub async fn recv_data(&mut self) -> Result<Option<impl Buf>, Error> {
676+
future::poll_fn(|cx| self.poll_recv_data(cx)).await
669677
}
670678

671679
/// Receive trailers

h3/src/server.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -674,6 +674,14 @@ where
674674
self.inner.recv_data().await
675675
}
676676

677+
/// Poll for data sent from the client
678+
pub fn poll_recv_data(
679+
&mut self,
680+
cx: &mut Context<'_>,
681+
) -> Poll<Result<Option<impl Buf>, Error>> {
682+
self.inner.poll_recv_data(cx)
683+
}
684+
677685
/// Receive an optional set of trailers for the request
678686
pub async fn recv_trailers(&mut self) -> Result<Option<HeaderMap>, Error> {
679687
self.inner.recv_trailers().await

0 commit comments

Comments
 (0)