pub struct SimpleIoReactor<AppData> { /* private fields */ }Expand description
SimpleIoReactor doesn’t have UserCommand. User supplies callback functions to handle inbound socket messages and on_connected/on_close events.
On each readable socket event, the MsgReader reads all data and call on_sock_msg_handler to dispatch message.
**Note that SimpleIoReactor can only be used with SimpleIoRuntime
Implementations§
Source§impl<AppData: 'static> SimpleIoReactor<AppData>
impl<AppData: 'static> SimpleIoReactor<AppData>
pub fn new( app_data: AppData, on_connected_handler: Option<Box<dyn FnMut(&mut SimpleIoReactorContext<'_>, ReactorID, &mut AppData) -> Result<()>>>, on_closed_handler: Option<Box<dyn FnMut(ReactorID, &CmdSender<()>, &mut AppData)>>, on_sock_msg_handler: impl FnMut(&mut [u8], &mut SimpleIoReactorContext<'_>, &mut AppData) -> Result<usize> + 'static, ) -> Self
pub fn new_boxed( app_data: AppData, on_connected_handler: Option<Box<dyn FnMut(&mut SimpleIoReactorContext<'_>, ReactorID, &mut AppData) -> Result<()>>>, on_closed_handler: Option<Box<dyn FnMut(ReactorID, &CmdSender<()>, &mut AppData)>>, on_sock_msg_handler: impl FnMut(&mut [u8], &mut SimpleIoReactorContext<'_>, &mut AppData) -> Result<usize> + 'static, ) -> Box<dyn Reactor<UserCommand = ()>>
Trait Implementations§
Source§impl<AppData> Reactor for SimpleIoReactor<AppData>
impl<AppData> Reactor for SimpleIoReactor<AppData>
type UserCommand = ()
Source§fn on_inbound_message(
&mut self,
buf: &mut [u8],
_new_bytes: usize,
_decoded_msg_size: usize,
ctx: &mut DispatchContext<'_, Self::UserCommand>,
) -> Result<MessageResult>
fn on_inbound_message( &mut self, buf: &mut [u8], _new_bytes: usize, _decoded_msg_size: usize, ctx: &mut DispatchContext<'_, Self::UserCommand>, ) -> Result<MessageResult>
It’s called by in on_readable() when either decoded_msg_size==0 (meaning message size is unknown) or decoded_msg_size <= buf.len() (meaning a full message is read). Read more
Source§fn on_connected(
&mut self,
ctx: &mut DispatchContext<'_, Self::UserCommand>,
listener: ReactorID,
) -> Result<()>
fn on_connected( &mut self, ctx: &mut DispatchContext<'_, Self::UserCommand>, listener: ReactorID, ) -> Result<()>
ReactRuntime calls it when connection is established. Read more
Source§fn on_close(
&mut self,
reactorid: ReactorID,
cmd_sender: &CmdSender<Self::UserCommand>,
)
fn on_close( &mut self, reactorid: ReactorID, cmd_sender: &CmdSender<Self::UserCommand>, )
ReactRuntime calls it when the reactor is removed from poller and before closing the socket.
The Reactor will be destroyed after this call.
Source§fn on_readable(
&mut self,
ctx: &mut ReactorReableContext<'_, Self::UserCommand>,
) -> Result<()>
fn on_readable( &mut self, ctx: &mut ReactorReableContext<'_, Self::UserCommand>, ) -> Result<()>
ReactRuntime calls it when there’s a readable event.
ctx.reader could be used to read message. See MsgReader for usage.
This is a default implementation which uses MsgReader to read all messages then call on_inbound_message to dispatch (default try_read_fast_read).
User may override this function to implement other strategies (e.g. `try_read_fast_dispatch``). Read moreSource§fn on_command(
&mut self,
_cmd: Self::UserCommand,
ctx: &mut DispatchContext<'_, Self::UserCommand>,
) -> Result<()>
fn on_command( &mut self, _cmd: Self::UserCommand, ctx: &mut DispatchContext<'_, Self::UserCommand>, ) -> Result<()>
ReactRuntime calls it when receiving a command. If no user command is used (e.g.
type UserCommand=();), user may not need to override it.
return Err to close the socket.Auto Trait Implementations§
impl<AppData> Freeze for SimpleIoReactor<AppData>where
AppData: Freeze,
impl<AppData> !RefUnwindSafe for SimpleIoReactor<AppData>
impl<AppData> !Send for SimpleIoReactor<AppData>
impl<AppData> !Sync for SimpleIoReactor<AppData>
impl<AppData> Unpin for SimpleIoReactor<AppData>where
AppData: Unpin,
impl<AppData> !UnwindSafe for SimpleIoReactor<AppData>
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