tokio_quiche: Unable to use a custom `BufFactory`
Hey folks, I'm building a async friendly API using Bytes. I implemented quiche::BufFactory for it via a wrapper. A bytes feature would be nice to avoid this wrapper, but that's a separate request.
However, I don't think it's possible to use because ApplicationOverQuic is not generic over F: BufFactory. The quinn::Connection passed to the trait (aliased as tokio_quiche::QuinnConnection) uses the default DefaultBufFactory. Or tokio_quiche::buf_factory::BufFactory with the zero-copy feature.
I'd like to use stream_send_zc with Bytes to avoid the copy. I imagine the zero-copy feature exists for a reason and there's probably some weird Rust quirk preventing generic zero-copy support, but I just wanted to ask anyway.
I think letting applications define their own BufFactory for TQ is a good idea, it's just it was never implemented. Not quite sure what the API would look like, but would welcome ideas (and PRs!).
I think letting applications define their own BufFactory for TQ is a good idea, it's just it was never implemented. Not quite sure what the API would look like, but would welcome ideas (and PRs!).
Yeah my first idea would be
pub trait ApplicationOverQuic<F: BufFactory = DefaultBufFactory> {
fn process_reads(&mut self, qconn: &mut quinn::Connection<F>) -> QuicResult<()>;
// ...
}
I thiiiiink it would be backwards compatible, and I thiiiiink it's valid Rust. My only concern would be the "zero-copy" feature, but I don't fully understand it yet.
Okay yeah I tried using the zero-copy feature flag as is and it's extremely difficult.
Here's the only way to construct a QuicheBuf outside of the crate, required as the argument to stream_send_zc:
let buf = <tokio_quiche::buf_factory::BufFactory as quiche::BufFactory>::buf_from_slice(
data,
);
And you can barely do anything once the data is copied. It might be a little easier if this pub(crate) was removed (at the very least you could use custom pools) but I haven't thought much about it.