h2 icon indicating copy to clipboard operation
h2 copied to clipboard

Zero-copy transmission with splice/sendfile

Open quasicomputational opened this issue 5 years ago • 1 comments

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.

quasicomputational avatar Jun 28 '19 15:06 quasicomputational

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?

nox avatar May 04 '21 10:05 nox