Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add 'Connection:poll_recv_data()' #228

Merged
merged 1 commit into from
Mar 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading