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 RecvStream::recv(), a middleground between read() and read_unordered() #929

Closed
seanmonstar opened this issue Dec 1, 2020 · 2 comments
Labels
enhancement New feature or request

Comments

@seanmonstar
Copy link

This is a request to add a recv like method to RecvStream, which yields Bytes but still ordered.

There are currently two main ways of reading data from a RecvStream:

  • read(&mut [u8]): This is an ordered read, but copies the data into a pre-allocated buffer.
  • read_unordered() -> (Bytes, u64): As the name implies, this is an unordered read, but it gives a Bytes object, which allows the user to receive those bytes without a copy.

In h3, when proving the h3<->quinn bridge, in order to try to reduce copies, we've been using the read_unordered. However, that means we end up having an intermediate collection to wait to put the Bytes in order, since we also need ordered reads. Since quinn is already doing that, it could be useful to provide a method that yields Bytes in an ordered manner. Looking in quinn's source, it'd probably be a simpler read, since it wouldn't need to handle partial reads into buffers, and can just yield a Bytes once the order is right.

So, the final method signature would be something like async fn recv(&mut self) -> Result<Option<Bytes>, ReadError>. (As a side note, if this is accepted, perhaps it might make sense to rename read_unordered to recv_unordered.)

@Ralith
Copy link
Collaborator

Ralith commented Dec 1, 2020

Good call, we should have this. There's a bunch of gotchas in making a robust stream assembler and we definitely don't want to incentivize callers to try to reimplement that.

@Ralith
Copy link
Collaborator

Ralith commented Mar 20, 2021

This is now implemented as RecvStream::read_chunk with ordered = true.

@Ralith Ralith closed this as completed Mar 20, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants