pub trait EndpointEventCallbacks {
    // Required methods
    fn connection_started(
        &mut self,
        endpoint: &mut Endpoint,
        cid: &ConnectionId
    );
    fn connection_ended(
        &mut self,
        endpoint: &mut Endpoint,
        cid: &ConnectionId,
        reason: ConnectionEndReason,
        remaining_connections: usize
    ) -> bool;
    fn tick(&mut self, endpoint: &mut Endpoint) -> bool;
    fn main_stream_recv(
        &mut self,
        endpoint: &mut Endpoint,
        cid: &ConnectionId,
        read_data: &[u8]
    ) -> Option<usize>;

    // Provided methods
    fn connection_ending_warning(
        &mut self,
        _endpoint: &mut Endpoint,
        _cid: &ConnectionId,
        _reason: ConnectionEndReason
    ) { ... }
    fn rt_stream_recv(
        &mut self,
        _endpoint: &mut Endpoint,
        _cid: &ConnectionId,
        _read_data: &[u8],
        _rt_id: u64
    ) -> usize { ... }
    fn background_stream_recv(
        &mut self,
        _endpoint: &mut Endpoint,
        _cid: &ConnectionId,
        _read_data: &[u8]
    ) -> Option<usize> { ... }
}
Expand description

Required QUIC Endpoint Handler Event Callback Functions

These functions will get called for their respective events. These callbacks are expected to return within a couple milliseconds AT THE MOST for all processing cases.

Required Methods§

source

fn connection_started(&mut self, endpoint: &mut Endpoint, cid: &ConnectionId)

Called when a new connection is started and is application ready.

source

fn connection_ended( &mut self, endpoint: &mut Endpoint, cid: &ConnectionId, reason: ConnectionEndReason, remaining_connections: usize ) -> bool

Called when a connection has ended and should be cleaned up.

Return true if you want the Endpoint Handler event loop to exit. The event loop will return an Ok(true) indicating that the connection_ended callback function caused the exit. This is intended to be useful in case the application wants to start up the Endpoint Handler event loop again.

source

fn tick(&mut self, endpoint: &mut Endpoint) -> bool

Called when the next tick occurrs based on the tick duration given to the run_event_loop call.

Return true if you want the Endpoint Handler event loop to exit. The event loop will return an Ok(false) indicating that the tick callback function caused the exit.

source

fn main_stream_recv( &mut self, endpoint: &mut Endpoint, cid: &ConnectionId, read_data: &[u8] ) -> Option<usize>

Called when there is something to read on the main stream.

The main stream is a reliable (ordered) stream that focuses on communicating high-priority, small(ish) messages between the server and client.

The read_data length will be the number of bytes asked for on the previous call. The first time it is called the length will be the number of bytes set by the Endpoint Config (initial_main_recv_size). This data can be processed based on the application protocol.

Return the number of bytes you want to read the next time this callback is called. If the optional usize value is set to zero (0) it will be interpreted as the Endpoint Config initial_main_recv_size value. Returning a None will close the main stream but since the main stream is required, the connection will start the close process.

Provided Methods§

source

fn connection_ending_warning( &mut self, _endpoint: &mut Endpoint, _cid: &ConnectionId, _reason: ConnectionEndReason )

Called when a connection is in the process of ending and allows an application to clean up relevant states earlier before the connection fully ends.

By default, this function does nothing when called.

source

fn rt_stream_recv( &mut self, _endpoint: &mut Endpoint, _cid: &ConnectionId, _read_data: &[u8], _rt_id: u64 ) -> usize

Called when there is something to read on the real-time stream.

The real-time “stream” is different than the main stream because it uses multiple incremental QUIC unidirectional streams in the backend where each stream id represents a single time segment that has unreliability the moment when the next single time segment arrives before the previous stream had finished.

The read_data length will be the number of bytes asked for on the previous call. The first time it is called the length will be the number of bytes set by the Endpoint Config (initial_rt_recv_size). This data can be processed based on the application protocol.

Return the number of bytes you want to read the next time this callback is called. If the usize value is set to zero (0) it will be interpreted as waiting for the next finished real-time stream.

By default, this function will return 0, which translates to waiting for the next finished real-time stream as indicated above. This function should be overwritten in order to handle processing real-time stream data.

source

fn background_stream_recv( &mut self, _endpoint: &mut Endpoint, _cid: &ConnectionId, _read_data: &[u8] ) -> Option<usize>

Called when there is something to read on the background stream.

The background stream is a reliable (ordered) stream that focuses on communicating large(ish) messages between the server and client such as a file transfer.

The read_data length will be the number of bytes asked for on the previous call. The first time it is called the length will be the number of bytes set by the Endpoint Config (initial_background_recv_size). This data can be processed based on the application protocol.

Return the number of bytes you want to read the next time this callback is called. If the optional usize value is set to zero (0) it will be interpreted as the as the Endpoint Config initial_background_recv_size value. Returning a None will close the background stream but since the background stream is required, the connection will start the close process.

By default, this function will return None, which translates to a connection closure as indicated above. This function should be overwritten to handle cases where a connection might send information over the background stream to prevent accidental connection closures.

Implementors§