Skip to main content

Module io

Module io 

Source
Expand description

Owned-buffer I/O helpers shared by every runtime backend.

The runtime adapters (rt::tokio, rt::smol, and the native rt::compio path) all speak compio’s owned-buffer read/write contract. Two pieces of that contract are fiddly enough that duplicating them per backend invites drift:

  • declaring how many bytes a read initialized in a buffer’s spare capacity, which is the workspace’s single owned-buffer unsafe operation (fill_read); and
  • building borrowed IoSlices over an owned vectored buffer for one writev (with_vectored_slices).

Centralizing both here gives each backend one call site instead of its own copy, and keeps the lone set_buf_init unsafe behind a single documented contract rather than repeated in every adapter.

Like tcp, this module encapsulates its unsafe behind a safe API, so it opts back into unsafe_code that the crate otherwise denies.

Constants§

COPY_OUT_THRESHOLD
Frame-size threshold below which a received frame is copied out of the shared read slab into a right-sized allocation instead of being frozen in place.
READ_SLAB_SIZE
Size of a read scratch slab.

Functions§

fill_read
Read into an owned buffer’s spare capacity, then declare the bytes written as initialized.
take_read_buffer
Take a read-sized scratch buffer from the front of stash, leaving the remaining tail in stash to hand out on the next call.
with_vectored_slices
Build borrowed IoSlices over the initialized bytes of each buffer in an owned vectored buffer and hand them to f for a single vectored write.