hyperium / h2

HTTP 2.0 client & server implementation for Rust.
MIT License
1.38k stars 278 forks source link

Zero-copy transmission with splice/sendfile #381

Open quasicomputational opened 5 years ago

quasicomputational commented 5 years ago

Hi - it'd be handy if data could be sent through a stream without an (extra) userspace/kernelspace copy, which can be done with the splice system call on Linux and sendfile on some BSDs.

The idea would be to send the data frame's header directly, then pump with splice until all the bytes have been sent. Presumably it should do whatever send_data does if you try to send more bytes than SETTINGS_MAX_FRAME_SIZE.

I had a look at proto/streams/streams.rs and it might not actually need much type surgery - SendStream is already parameterised over the data it sends, so switching from Bytes to a sum of Bytes and a file descriptor + the range to splice should be quite possible.

nox commented 3 years ago

I'm not sure how you would do that, like, how do you know that the underlying socket is an actual raw socket, without TLS, etc?