io_sendfile(3)

πŸ“¦
version 0.34 Β· 2 versions
  • 0.34 Β· alpine 3.24, debian bookworm, debian trixie, nixos 26.05, nixpkgs unstable, opensuse-leap 16.0, ubuntu noble, ubuntu questing, ubuntu resolute, ubuntu stonking (latest)
  • 0.30 Β· fedora 43, fedora 44, ubuntu jammy
, in alpine 3.24, debian bookworm, debian trixie, nixos 26.05, nixpkgs unstable, opensuse-leap 16.0, ubuntu noble, ubuntu questing, ubuntu resolute, ubuntu stonking

πŸ’– io_sendfile(3) πŸ’–

okay bestie, buckle up, this one's from the Library Functions Manual and it's literally the glow-up your file-to-socket pipeline has been begging for 🫢


✨ NAME ✨

io_sendfile β€” send data from a file to a socket πŸ¦‹


✨ SYNTAX ✨

#include <libowfat/io.h>

int64 io_sendfile(int64 sock,int64 fd,uint64 off,uint64 n);

✨ DESCRIPTION ✨

so io_sendfile sends data from a file to a socket. and not in a mid way either β€” it tries to do it in a way that lets high quality operating systems pull off zero-copy TCP πŸ’… which is the fancy way of saying it serves the data without copying the file contents to user space or inside kernel space. no extra copies, no nonsense, just vibes ✨

the way it works: this function will use special operating system "sendfile" primitives where available, and fall back to memory mapped I/O otherwise. either way?? it should always be faster than using read() and write() to copy the data yourself. like, not even close. main character energy fr fr πŸ‘‘

and it tells you how it went:

  • returns the number of bytes sent βœ…
  • if an error occurred, it returns -1 for EAGAIN, or -3 otherwise 😭
bestie pls actually check the return value, okay? -1 and -3 are two different little gremlins and you wanna know which one you got πŸ™ˆ

✨ SEE ALSO ✨


that's the whole page, no cap πŸ’œ this was io_sendfile(3) β€” straight out of the Library Functions Manual, footer and all, say hi to your sockets for me πŸŽ€πŸŒΈ