Expand description
Zero-copy data transfer utilities using Linux splice(2).
splice(2) moves data between two file descriptors via a kernel pipe
buffer without copying the data through user space. For downloads to
regular files this enables the pipeline socket -> pipe -> file, all
inside the kernel, eliminating the user-space read/write bounce.
§Platform Support
- Linux: Full
splice(2)support vialibc. The publicsplice_transferfunction performs the kernel-mediated transfer. - Other platforms (Windows, macOS, …):
splice_transferalways returnsErrwith kindUnsupported. Callers must fall back to a plainread+writeloop. Useis_splice_supportedto gate the fast path at runtime.
§Safety
All splice(2) invocations are confined to #[cfg(target_os = "linux")]
code paths and operate on valid, open file descriptors owned by the
caller. A RAII [PipeGuard] guarantees the intermediate pipe descriptors
are closed on every exit path (including early return on error and
panics).
Functions§
- is_
splice_ supported - Reports whether
splice(2)is available on the current platform. - splice_
transfer - Transfer up to
lenbytes fromfd_intofd_outusingsplice(2).