package.bend relies on unsafe/foreign
raw source on the hub · import 0x9c94dd62a275a2a52aba6d0315b7bb60/package.bend as Package
bend-sendfile: package entry for BendHub. Source: bendlang/bend PR #1117 (reviewed by VictorTaelin; closed as WONTFIX (CAPACITY) and rerouted here: "a foreign effect a hub package can ship with no loss ... the same C code").
The file's bytes, from an offset, straight onto a socket: the kernel's sendfile on the C lane, so no byte passes through the program; the JS twin copies through a buffer (Node has no sendfile) and says so. Every lane leaves the file's position alone. Done once all len bytes are out; a file that ends first fails with ENODATA after what it had went out.
1 import
import Base
Effects (foreign code)
effect File.sendfile source · line 17 · raw
@sock:Socket -> @file:File -> @off:U32 -> @len:U32 -> IO(Pair(Socket, Pair(File, Result<&1, &1, Pair(U32, String), Unit>)))
The file's bytes from off, len of them, onto the socket: the kernel's sendfile on the C lane, so no byte passes through the program; every lane leaves the file's position alone. Done once all len are out; a file that ends first fails with ENODATA after what it had went out.
foreign: file_sendfile.c, file_sendfile.js