quinn-rs / quinn

Async-friendly QUIC implementation in Rust
Apache License 2.0
3.84k stars 394 forks source link

Support all-or-nothing writes to `SendStream` #1754

Closed omegablitz closed 8 months ago

omegablitz commented 9 months ago

There's currently no way in quinn_proto::SendStream (and consequently quinn::SendStream) to perform all-or-nothing writes.

As a concrete example, I have a &mut [Bytes] that I'd like to write to a quinn::SendStream in its entirety if there's sufficient send capacity, or not at all. The end-user API could look something like fn try_write_all_chunks(&mut self, bufs: &mut [Bytes]) -> Result<(), WriteError> - note that this function is not asynchronous.

The current functionality seems to be a consequence of how quinn_proto::write_source works. It currently takes in a BytesSource, acquires a lock, checks the write limit, and then writes from the BytesSource up to the limit. https://github.com/quinn-rs/quinn/blob/dcc8048974ce9b1ca6b365019149b5586ed88f4a/quinn-proto/src/connection/streams/mod.rs#L205-L243 Conceptually, this could be implemented by augmenting quinn_proto::write_source to also take in min_limit parameter.

There's probably a more flexible end-user abstraction than the try_write_all_chunks function I proposed above, but first wanted to get feedback on the idea. I'm happy to draft a PR for this if the idea seems generally useful.

Ralith commented 9 months ago

Can you elaborate on the use case, and cite any prior art? We've already got an awful lot of variations on "write".

omegablitz commented 8 months ago

Closing this, as I think I can work around this with cwnd from Connection::stats().