pub struct MsgReader { /* private fields */ }Expand description
MsgReader is a per-socket helper to read socket messages. It auto handles partial/multiple messages in recv buffer.
On Readable event, call MsgReader::try_read_fast_dispatch/try_read_fast_read to read messages from a sock into a recv_buffer and calls dispatcher::on_inbound_message to dispatch message.
Implementations§
Source§impl MsgReader
impl MsgReader
pub fn new(min_reserved_bytes: usize) -> Self
pub fn bytes_in_buffer(&self) -> usize
pub fn clear(&mut self)
Sourcepub fn try_read_fast_dispatch<UserCommand>(
&mut self,
ctx: &mut DispatchContext<'_, UserCommand>,
dispatcher: &mut impl FnMut(&mut [u8], usize, usize, &mut DispatchContext<'_, UserCommand>) -> Result<MessageResult>,
) -> Result<()>
pub fn try_read_fast_dispatch<UserCommand>( &mut self, ctx: &mut DispatchContext<'_, UserCommand>, dispatcher: &mut impl FnMut(&mut [u8], usize, usize, &mut DispatchContext<'_, UserCommand>) -> Result<MessageResult>, ) -> Result<()>
Strategy 1: fast dispatch: dispatch on each read of about min_reserve bytes. return Err to close socket
Sourcepub fn try_read_all<UserCommand>(
&mut self,
ctx: &mut DispatchContext<'_, UserCommand>,
) -> Result<()>
pub fn try_read_all<UserCommand>( &mut self, ctx: &mut DispatchContext<'_, UserCommand>, ) -> Result<()>
Read until WOULDBLOCK. return Err to close socket
Sourcepub fn try_dispatch_all<UserCommand>(
&mut self,
new_bytes: usize,
ctx: &mut DispatchContext<'_, UserCommand>,
dispatcher: &mut impl FnMut(&mut [u8], usize, usize, &mut DispatchContext<'_, UserCommand>) -> Result<MessageResult>,
) -> Result<()>
pub fn try_dispatch_all<UserCommand>( &mut self, new_bytes: usize, ctx: &mut DispatchContext<'_, UserCommand>, dispatcher: &mut impl FnMut(&mut [u8], usize, usize, &mut DispatchContext<'_, UserCommand>) -> Result<MessageResult>, ) -> Result<()>
try dispatch all messages in buffer. return Error if there’s any error or close.
Sourcepub fn try_read_fast_read<UserCommand>(
&mut self,
ctx: &mut DispatchContext<'_, UserCommand>,
dispatcher: &mut impl FnMut(&mut [u8], usize, usize, &mut DispatchContext<'_, UserCommand>) -> Result<MessageResult>,
) -> Result<()>
pub fn try_read_fast_read<UserCommand>( &mut self, ctx: &mut DispatchContext<'_, UserCommand>, dispatcher: &mut impl FnMut(&mut [u8], usize, usize, &mut DispatchContext<'_, UserCommand>) -> Result<MessageResult>, ) -> Result<()>
Strategy 2: fast read: read all until WOULDBLOCK, then dispatch all.
Auto Trait Implementations§
impl Freeze for MsgReader
impl RefUnwindSafe for MsgReader
impl Send for MsgReader
impl Sync for MsgReader
impl Unpin for MsgReader
impl UnwindSafe for MsgReader
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more