pub struct FrameReader<F: Framer, const MAX_MSG_SIZE: usize> { /* private fields */ }Expand description
Represents an abstraction for reading exactly oen frame from the TcpStream. Each call to the Self::read_frame will issue a Read::read system call on the underlying TcpStream. which will capture any bytes read into internal accumulator implemented as a BytesMut. This internal buffer will be passed to the generic impl of Framer::get_frame where it is user’s responsibility to inspect the buffer and split off a single frame.
§Generic Parameters
F- A type that implements the Framer trait. This is used to split off a single frame from the internal buffer.MAX_MSG_SIZE- The maximum size of a single frame. This is used to pre-allocate the internal buffer. Set this number to the maximum size of a single frame for your protocol.
Implementations§
Source§impl<F: Framer, const MAX_MSG_SIZE: usize> FrameReader<F, MAX_MSG_SIZE>
impl<F: Framer, const MAX_MSG_SIZE: usize> FrameReader<F, MAX_MSG_SIZE>
Sourcepub fn new(con_id: ConId, reader: TcpStream) -> FrameReader<F, MAX_MSG_SIZE>
pub fn new(con_id: ConId, reader: TcpStream) -> FrameReader<F, MAX_MSG_SIZE>
Creates a new instance of FrameReader
§Arguments
Sourcepub fn read_frame(&mut self) -> Result<Option<Bytes>, Error>
pub fn read_frame(&mut self) -> Result<Option<Bytes>, Error>
Reads exactly one frame from the underlying TcpStream and returns it as a [Some(Bytes)] or None if the connection was closed.
§Note
If the FrameWriter pair is dropped then this method will return a [Ok(None)].
Trait Implementations§
Source§impl<F: Framer, const MAX_MSG_SIZE: usize> Drop for FrameReader<F, MAX_MSG_SIZE>
impl<F: Framer, const MAX_MSG_SIZE: usize> Drop for FrameReader<F, MAX_MSG_SIZE>
Source§fn drop(&mut self)
fn drop(&mut self)
Will shutdown the underlying std::net::TcpStream in both directions. This way
the peer connection will receive a TCP FIN flag and and once it reaches the peer FrameWriter it will
get a ErrorKind::BrokenPipe error which in turn shall issue a Shutdown::Write