SimpleIoReactor

Struct SimpleIoReactor 

Source
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>

Source

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

Source

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>

Source§

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>

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<()>

ReactRuntime calls it when connection is established. Read more
Source§

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<()>

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 more
Source§

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> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more