h2
h2 copied to clipboard
Zero-copy transmission with splice/sendfile
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.
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?