This would be the first step towards ninenines/cowboy#306.
( Sorry for filing this while Xmas :)
Shall I prepare a PR?
Feel free to, but you'll need to add a ct test for it (for ssl at the very least).
I see no existing tests for sendfile/2 to use as a starter...
There are none because sendfile/2 is trivial while a sendfile with offset/length is harder.
There's a sendfile_fallback function in the file module. Can probably start looking there. Also we probably can do with just a sendfile(Socket, Filename, Start, Length) or something because this way we open the file ourselves and not the user, and the one option available otherwise is chunk_size and is probably not important on a per-file basis.
You mean ranch_(tcp|ssl) might only expose sendfile/4, right? I'm pro, with addition in having also sendfile(Socket, File, Start, Length) exposed. The rationale is that it maps 1-1 to file:sendfile/5 in case of plain TCP which is the major case.
The question though who's in charge to close File, I believe it's left to user.
In either event, sendfile/4 is more solid solution imho.
sendfile(Socket, File, Start, Length)
What to ranch_ssl, I'd recommend to put SSL-terminators such as modern haproxy which does also load-balancing and other sweets.
Would you like to write a patch for this?
i hesitate since i have vague skill in ct tests.
So this has been done. Thanks everyone involved!