Skip to main content

ReactionHandler

Trait ReactionHandler 

Source
pub trait ReactionHandler: Send + Iterator<Item = Action<Self::Listener, Self::Transport>> {
    type Listener: EventHandler + Source + Send + Debug;
    type Transport: EventHandler + Source + Send + Debug + WriteAtomic;

    // Required methods
    fn tick(&mut self);
    fn timer_reacted(&mut self);
    fn listener_reacted(
        &mut self,
        token: Token,
        reaction: <Self::Listener as EventHandler>::Reaction,
        instant: Instant,
    );
    fn transport_reacted(
        &mut self,
        token: Token,
        reaction: <Self::Transport as EventHandler>::Reaction,
        instant: Instant,
    );
    fn listener_registered(&mut self, token: Token, listener: &Self::Listener);
    fn transport_registered(
        &mut self,
        token: Token,
        transport: &Self::Transport,
    );
    fn handle_command(&mut self, cmd: Control);
    fn handle_error(&mut self, err: Error<Self::Listener, Self::Transport>);
    fn handover_listener(&mut self, token: Token, listener: Self::Listener);
    fn handover_transport(&mut self, token: Token, transport: Self::Transport);
}
Expand description

A service which handles reactions to the events generated in the Reactor.

Required Associated Types§

Source

type Listener: EventHandler + Source + Send + Debug

Type for a listener resource.

Listener resources are resources which may spawn more resources and can’t be written to. A typical example of a listener resource is a std::net::TcpListener, however this may also be a special form of a peripheral device or something else.

Source

type Transport: EventHandler + Source + Send + Debug + WriteAtomic

Type for a transport resource.

Transport is a “full” resource which can be read from - and written to. Usual files, network connections, database connections etc are all fall into this category.

Required Methods§

Source

fn tick(&mut self)

Method called by the reactor on the start of each event loop once the poll has returned.

Source

fn timer_reacted(&mut self)

Method called by the reactor when a previously set timeout is fired.

Related: Action::SetTimer.

Source

fn listener_reacted( &mut self, token: Token, reaction: <Self::Listener as EventHandler>::Reaction, instant: Instant, )

Method called by the reactor upon a reaction to an I/O event on a listener resource.

Since listener doesn’t support writing, it can be only a read event (indicating that a new resource can be spawned from the listener).

Source

fn transport_reacted( &mut self, token: Token, reaction: <Self::Transport as EventHandler>::Reaction, instant: Instant, )

Method called by the reactor upon a reaction to an I/O event on a transport resource.

Source

fn listener_registered(&mut self, token: Token, listener: &Self::Listener)

Method called by the reactor when a given resource was successfully registered for given token.

The token will be used later in ReactionHandler::listener_reacted and ReactionHandler::handover_listener calls to the handler.

Source

fn transport_registered(&mut self, token: Token, transport: &Self::Transport)

Method called by the reactor when a given resource was successfully registered for given token.

The token will be used later in ReactionHandler::transport_reacted, ReactionHandler::handover_transport calls to the handler.

Source

fn handle_command(&mut self, cmd: Control)

Method called by the reactor when a command is received for the ReactionHandler.

The commands are sent via Controller from outside of the reactor, including other threads.

Source

fn handle_error(&mut self, err: Error<Self::Listener, Self::Transport>)

Method called by the reactor on any kind of error during the event loop, including errors of the poll syscall or I/O errors returned as a part of the poll result events.

See Error for the details on errors which may happen.

Source

fn handover_listener(&mut self, token: Token, listener: Self::Listener)

Method called by the reactor upon receiving Action::UnregisterListener.

Passes the listener resource to the ReactionHandler when it is already not a part of the reactor poll. From this point of time it is safe to send the resource to other threads (like workers) or close the resource.

Source

fn handover_transport(&mut self, token: Token, transport: Self::Transport)

Method called by the reactor upon receiving Action::UnregisterTransport.

Passes the transport resource to the ReactionHandler when it is already not a part of the reactor poll. From this point of time it is safe to send the resource to other threads (like workers) or close the resource.

Implementors§