pub struct BoundedLines<R> { /* private fields */ }Expand description
An AsyncRead that fails once a newline-delimited frame exceeds
cap bytes.
Wraps stdin under rmcp’s own BufReader, so the counter sees the
delivered chunks and not the frames: the cap is enforced as soon as the
running frame passes it, without waiting for the \n that may never
come. A frame of exactly cap bytes is accepted, mirroring the http
side’s <= max_bytes.
The count lives here rather than in a per-receive future because rmcp
keeps partial bytes across cancelled polls: receive is polled inside a
select! and an in-progress line read is dropped whenever an outgoing
response wins, so a per-call counter would restart mid-frame and the cap
would bound nothing.
Implementations§
Source§impl<R> BoundedLines<R>
impl<R> BoundedLines<R>
Sourcepub fn new(inner: R, cap: usize) -> Self
pub fn new(inner: R, cap: usize) -> Self
Bound inner to frames of at most cap bytes before the \n.
Sourcepub fn cap(&self) -> usize
pub fn cap(&self) -> usize
The frame cap this reader enforces, in bytes before the delimiter.
Exposed so a test can assert that the stdio and http transports were sized from the same derivation rather than from two numbers that happen to agree today.
Sourcepub fn over_cap(&self) -> Arc<AtomicBool> ⓘ
pub fn over_cap(&self) -> Arc<AtomicBool> ⓘ
The trip flag, shared with whoever outlives the transport.
rmcp turns the read error into receive() -> None, which the
service reports as an ordinary close (QuitReason::Closed) — so
without this flag a refused frame and a peer hangup are the same
Ok exit. main bails on it after waiting() so both stages exit
non-zero.
Trait Implementations§
Source§impl<R: AsyncRead + Unpin> AsyncRead for BoundedLines<R>
impl<R: AsyncRead + Unpin> AsyncRead for BoundedLines<R>
Source§fn poll_read(
self: Pin<&mut Self>,
cx: &mut Context<'_>,
buf: &mut ReadBuf<'_>,
) -> Poll<Result<()>>
fn poll_read( self: Pin<&mut Self>, cx: &mut Context<'_>, buf: &mut ReadBuf<'_>, ) -> Poll<Result<()>>
Delegates the read, then measures what arrived.
Every frame in the chunk is checked at its delimiter, not only the
bytes after the chunk’s last newline: a frame that both passes the
cap and ends inside the tripping chunk would otherwise be seen as a
short tail and let through. (Chunk length is not the measure either —
many short frames may share one chunk.) Overshoot is bounded by one chunk
(8 KiB under rmcp’s BufReader), since the cap can only be observed
on bytes already delivered.
Bytes the tripping read delivered stay in buf; the caller drops
them with the error, and the transport is closed either way.
Auto Trait Implementations§
impl<R> Freeze for BoundedLines<R>where
R: Freeze,
impl<R> RefUnwindSafe for BoundedLines<R>where
R: RefUnwindSafe,
impl<R> Send for BoundedLines<R>where
R: Send,
impl<R> Sync for BoundedLines<R>where
R: Sync,
impl<R> Unpin for BoundedLines<R>where
R: Unpin,
impl<R> UnsafeUnpin for BoundedLines<R>where
R: UnsafeUnpin,
impl<R> UnwindSafe for BoundedLines<R>where
R: UnwindSafe,
Blanket Implementations§
Source§impl<R> AsyncReadExt for R
impl<R> AsyncReadExt for R
Source§fn read<'a>(&'a mut self, buf: &'a mut [u8]) -> Read<'a, Self>where
Self: Unpin,
fn read<'a>(&'a mut self, buf: &'a mut [u8]) -> Read<'a, Self>where
Self: Unpin,
Source§fn read_buf<'a, B>(&'a mut self, buf: &'a mut B) -> ReadBuf<'a, Self, B>
fn read_buf<'a, B>(&'a mut self, buf: &'a mut B) -> ReadBuf<'a, Self, B>
Source§fn read_exact<'a>(&'a mut self, buf: &'a mut [u8]) -> ReadExact<'a, Self>where
Self: Unpin,
fn read_exact<'a>(&'a mut self, buf: &'a mut [u8]) -> ReadExact<'a, Self>where
Self: Unpin,
buf. Read moreSource§fn read_u8(&mut self) -> ReadU8<&mut Self>where
Self: Unpin,
fn read_u8(&mut self) -> ReadU8<&mut Self>where
Self: Unpin,
Source§fn read_i8(&mut self) -> ReadI8<&mut Self>where
Self: Unpin,
fn read_i8(&mut self) -> ReadI8<&mut Self>where
Self: Unpin,
Source§fn read_u16(&mut self) -> ReadU16<&mut Self>where
Self: Unpin,
fn read_u16(&mut self) -> ReadU16<&mut Self>where
Self: Unpin,
Source§fn read_i16(&mut self) -> ReadI16<&mut Self>where
Self: Unpin,
fn read_i16(&mut self) -> ReadI16<&mut Self>where
Self: Unpin,
Source§fn read_u32(&mut self) -> ReadU32<&mut Self>where
Self: Unpin,
fn read_u32(&mut self) -> ReadU32<&mut Self>where
Self: Unpin,
Source§fn read_i32(&mut self) -> ReadI32<&mut Self>where
Self: Unpin,
fn read_i32(&mut self) -> ReadI32<&mut Self>where
Self: Unpin,
Source§fn read_u64(&mut self) -> ReadU64<&mut Self>where
Self: Unpin,
fn read_u64(&mut self) -> ReadU64<&mut Self>where
Self: Unpin,
Source§fn read_i64(&mut self) -> ReadI64<&mut Self>where
Self: Unpin,
fn read_i64(&mut self) -> ReadI64<&mut Self>where
Self: Unpin,
Source§fn read_u128(&mut self) -> ReadU128<&mut Self>where
Self: Unpin,
fn read_u128(&mut self) -> ReadU128<&mut Self>where
Self: Unpin,
Source§fn read_i128(&mut self) -> ReadI128<&mut Self>where
Self: Unpin,
fn read_i128(&mut self) -> ReadI128<&mut Self>where
Self: Unpin,
Source§fn read_f32(&mut self) -> ReadF32<&mut Self>where
Self: Unpin,
fn read_f32(&mut self) -> ReadF32<&mut Self>where
Self: Unpin,
Source§fn read_f64(&mut self) -> ReadF64<&mut Self>where
Self: Unpin,
fn read_f64(&mut self) -> ReadF64<&mut Self>where
Self: Unpin,
Source§fn read_u16_le(&mut self) -> ReadU16Le<&mut Self>where
Self: Unpin,
fn read_u16_le(&mut self) -> ReadU16Le<&mut Self>where
Self: Unpin,
Source§fn read_i16_le(&mut self) -> ReadI16Le<&mut Self>where
Self: Unpin,
fn read_i16_le(&mut self) -> ReadI16Le<&mut Self>where
Self: Unpin,
Source§fn read_u32_le(&mut self) -> ReadU32Le<&mut Self>where
Self: Unpin,
fn read_u32_le(&mut self) -> ReadU32Le<&mut Self>where
Self: Unpin,
Source§fn read_i32_le(&mut self) -> ReadI32Le<&mut Self>where
Self: Unpin,
fn read_i32_le(&mut self) -> ReadI32Le<&mut Self>where
Self: Unpin,
Source§fn read_u64_le(&mut self) -> ReadU64Le<&mut Self>where
Self: Unpin,
fn read_u64_le(&mut self) -> ReadU64Le<&mut Self>where
Self: Unpin,
Source§fn read_i64_le(&mut self) -> ReadI64Le<&mut Self>where
Self: Unpin,
fn read_i64_le(&mut self) -> ReadI64Le<&mut Self>where
Self: Unpin,
Source§fn read_u128_le(&mut self) -> ReadU128Le<&mut Self>where
Self: Unpin,
fn read_u128_le(&mut self) -> ReadU128Le<&mut Self>where
Self: Unpin,
Source§fn read_i128_le(&mut self) -> ReadI128Le<&mut Self>where
Self: Unpin,
fn read_i128_le(&mut self) -> ReadI128Le<&mut Self>where
Self: Unpin,
Source§fn read_f32_le(&mut self) -> ReadF32Le<&mut Self>where
Self: Unpin,
fn read_f32_le(&mut self) -> ReadF32Le<&mut Self>where
Self: Unpin,
Source§fn read_f64_le(&mut self) -> ReadF64Le<&mut Self>where
Self: Unpin,
fn read_f64_le(&mut self) -> ReadF64Le<&mut Self>where
Self: Unpin,
Source§fn read_to_end<'a>(&'a mut self, buf: &'a mut Vec<u8>) -> ReadToEnd<'a, Self>where
Self: Unpin,
fn read_to_end<'a>(&'a mut self, buf: &'a mut Vec<u8>) -> ReadToEnd<'a, Self>where
Self: Unpin,
buf. Read more