pub async fn write_frame<W>(
writer: &mut W,
frame: &Frame,
) -> Result<(), FrameIoError>where
W: AsyncWrite + Unpin,Expand description
Write one complete frame to an async stream.
The header’s len must match the opaque body length; mismatches are reported
as a typed error rather than silently rewriting the header. This function does
not flush buffered writers; callers choose their own flush cadence.
HEADER AND BODY GO OUT AS ONE WRITE. Writing them separately looks harmless
behind a BufWriter and is not: BufWriter passes any write at or above its
capacity straight through to the socket, and flushes what it holds first to
preserve ordering. A body larger than the buffer therefore emits the 21-byte
header as a segment of its own, followed by the body as a second segment –
the small-leading-segment shape that Nagle holds until an ACK returns. The
boundary sits at the buffer capacity, so the same code path is fast for small
frames and slow for large ones, which is the hardest version to notice.
Joining them also halves the syscalls on the unbuffered path, where every
write_all is a syscall of its own.