pub struct BlockingFrameWriter<W: Write> { /* private fields */ }Expand description
Blocking frame writer. Writes length-prefixed frames to any Write sink.
Uses BufWriter to batch small writes (length prefix + payload) into
fewer syscalls. Flushed explicitly after each batch.
Implementations§
Source§impl<W: Write> BlockingFrameWriter<W>
impl<W: Write> BlockingFrameWriter<W>
pub fn new(writer: W) -> Self
Sourcepub fn write_frame(&mut self, data: &[u8]) -> Result<()>
pub fn write_frame(&mut self, data: &[u8]) -> Result<()>
Write a complete frame (prepends the 4-byte LE length prefix).
Sourcepub fn write_frame_parts(&mut self, parts: &[&[u8]]) -> Result<()>
pub fn write_frame_parts(&mut self, parts: &[&[u8]]) -> Result<()>
Write one frame whose payload is parts laid end to end, with
the length prefix of their total. Spares a caller that holds a
frame in pieces — a header it computes and a body it was given —
from assembling them in a buffer of its own: each part goes
straight into the write buffer, and the frame reaches the socket
whole at the next flush. A part that arrives while the buffer is
too full to take it still lands on the socket in order, only in a
separate write.
A frame over MAX_FRAME_SIZE is refused with
io::ErrorKind::InvalidInput before any of it is written: the
far end would drop the connection on it, and this is the error
that says why.