Skip to content

Commit

Permalink
add 'Connection:poll_recv_data()'
Browse files Browse the repository at this point in the history
  • Loading branch information
SergioBenitez authored and seanmonstar committed Mar 12, 2024
1 parent c11410c commit 95242b6
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 11 deletions.
30 changes: 19 additions & 11 deletions h3/src/connection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -623,16 +623,21 @@ where
S: quic::RecvStream,
{
/// Receive some of the request body.
pub async fn recv_data(&mut self) -> Result<Option<impl Buf>, Error> {
pub fn poll_recv_data(
&mut self,
cx: &mut Context<'_>,
) -> Poll<Result<Option<impl Buf>, Error>> {
if !self.stream.has_data() {
let frame = future::poll_fn(|cx| self.stream.poll_next(cx))
.await
let frame = self
.stream
.poll_next(cx)
.map_err(|e| self.maybe_conn_err(e))?;
match frame {

match ready!(frame) {
Some(Frame::Data { .. }) => (),
Some(Frame::Headers(encoded)) => {
self.trailers = Some(encoded);
return Ok(None);
return Poll::Ready(Ok(None));
}

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

let data = future::poll_fn(|cx| self.stream.poll_data(cx))
.await
.map_err(|e| self.maybe_conn_err(e))?;
Ok(data)
self.stream
.poll_data(cx)
.map_err(|e| self.maybe_conn_err(e))
}
/// Receive some of the request body.
pub async fn recv_data(&mut self) -> Result<Option<impl Buf>, Error> {
future::poll_fn(|cx| self.poll_recv_data(cx)).await
}

/// Receive trailers
Expand Down
8 changes: 8 additions & 0 deletions h3/src/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -674,6 +674,14 @@ where
self.inner.recv_data().await
}

/// Poll for data sent from the client
pub fn poll_recv_data(
&mut self,
cx: &mut Context<'_>,
) -> Poll<Result<Option<impl Buf>, Error>> {
self.inner.poll_recv_data(cx)
}

/// Receive an optional set of trailers for the request
pub async fn recv_trailers(&mut self) -> Result<Option<HeaderMap>, Error> {
self.inner.recv_trailers().await
Expand Down

0 comments on commit 95242b6

Please sign in to comment.