Trait laminar::Connection[][src]

pub trait Connection: Debug {
    type SendEvent: Debug + ConnectionEventAddress;
    type ReceiveEvent: Debug + ConnectionEventAddress;
    fn create_connection(
        messenger: &mut impl ConnectionMessenger<Self::ReceiveEvent>,
        address: SocketAddr,
        time: Instant
    ) -> Self;
fn is_established(&self) -> bool;
fn should_drop(
        &mut self,
        messenger: &mut impl ConnectionMessenger<Self::ReceiveEvent>,
        time: Instant
    ) -> bool;
fn process_packet(
        &mut self,
        messenger: &mut impl ConnectionMessenger<Self::ReceiveEvent>,
        payload: &[u8],
        time: Instant
    );
fn process_event(
        &mut self,
        messenger: &mut impl ConnectionMessenger<Self::ReceiveEvent>,
        event: Self::SendEvent,
        time: Instant
    );
fn update(
        &mut self,
        messenger: &mut impl ConnectionMessenger<Self::ReceiveEvent>,
        time: Instant
    ); }

Allows to implement actual connection. Defines a type of Send and Receive events, that will be used by a connection.

Associated Types

type SendEvent: Debug + ConnectionEventAddress[src]

Defines a user event type.

type ReceiveEvent: Debug + ConnectionEventAddress[src]

Defines a connection event type.

Loading content...

Required methods

fn create_connection(
    messenger: &mut impl ConnectionMessenger<Self::ReceiveEvent>,
    address: SocketAddr,
    time: Instant
) -> Self
[src]

Creates new connection and initialize it by sending an connection event to the user.

  • messenger - allows to send packets and events, also provides a config.
  • address - defines a address that connection is associated with.
  • time - creation time, used by connection, so that it doesn’t get dropped immediately or send heartbeat packet.

fn is_established(&self) -> bool[src]

Connections are considered established once they have both had both a send and a receive.

fn should_drop(
    &mut self,
    messenger: &mut impl ConnectionMessenger<Self::ReceiveEvent>,
    time: Instant
) -> bool
[src]

Determines if the connection should be dropped due to its state.

fn process_packet(
    &mut self,
    messenger: &mut impl ConnectionMessenger<Self::ReceiveEvent>,
    payload: &[u8],
    time: Instant
)
[src]

Processes a received packet: parse it and emit an event.

fn process_event(
    &mut self,
    messenger: &mut impl ConnectionMessenger<Self::ReceiveEvent>,
    event: Self::SendEvent,
    time: Instant
)
[src]

Processes a received event and send a packet.

fn update(
    &mut self,
    messenger: &mut impl ConnectionMessenger<Self::ReceiveEvent>,
    time: Instant
)
[src]

Processes various connection-related tasks: resend dropped packets, send heartbeat packet, etc… This function gets called frequently.

Loading content...

Implementors

impl Connection for VirtualConnection[src]

type SendEvent = Packet

Defines a user event type.

type ReceiveEvent = SocketEvent

Defines a connection event type.

fn create_connection(
    messenger: &mut impl ConnectionMessenger<Self::ReceiveEvent>,
    address: SocketAddr,
    time: Instant
) -> VirtualConnection
[src]

Creates new connection and initialize it by sending an connection event to the user.

  • address - defines a address that connection is associated with.
  • time - creation time, used by connection, so that it doesn’t get dropped immediately or send heartbeat packet.
  • initial_data - if initiated by remote host, this will hold that a packet data.

fn is_established(&self) -> bool[src]

Connections are considered established once they both have had a send and a receive.

fn should_drop(
    &mut self,
    messenger: &mut impl ConnectionMessenger<Self::ReceiveEvent>,
    time: Instant
) -> bool
[src]

Determines if the given Connection should be dropped due to its state.

fn process_packet(
    &mut self,
    messenger: &mut impl ConnectionMessenger<Self::ReceiveEvent>,
    payload: &[u8],
    time: Instant
)
[src]

Processes a received packet: parse it and emit an event.

fn process_event(
    &mut self,
    messenger: &mut impl ConnectionMessenger<Self::ReceiveEvent>,
    event: Self::SendEvent,
    time: Instant
)
[src]

Processes a received event and send a packet.

fn update(
    &mut self,
    messenger: &mut impl ConnectionMessenger<Self::ReceiveEvent>,
    time: Instant
)
[src]

Processes various connection-related tasks: resend dropped packets, send heartbeat packet, etc… This function gets called very frequently.

Loading content...