pingora_core::apps

Trait ServerApp

Source
pub trait ServerApp {
    // Required method
    fn process_new<'life0, 'life1, 'async_trait>(
        self: &'life0 Arc<Self>,
        session: Stream,
        shutdown: &'life1 ShutdownWatch,
    ) -> Pin<Box<dyn Future<Output = Option<Stream>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait;

    // Provided method
    fn cleanup<'life0, 'async_trait>(
        &'life0 self,
    ) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>
       where Self: Sync + 'async_trait,
             'life0: 'async_trait { ... }
}
Expand description

This trait defines the interface of a transport layer (TCP or TLS) application.

Required Methods§

Source

fn process_new<'life0, 'life1, 'async_trait>( self: &'life0 Arc<Self>, session: Stream, shutdown: &'life1 ShutdownWatch, ) -> Pin<Box<dyn Future<Output = Option<Stream>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Whenever a new connection is established, this function will be called with the established Stream object provided.

The application can do whatever it wants with the session.

After processing the session, if the session’s connection is reusable, This function can return it to the service by returning Some(session). The returned session will be fed to another Self::process_new() for another round of processing. If not reusable, None should be returned.

The shutdown argument will change from false to true when the server receives a signal to shutdown. This argument allows the application to react accordingly.

Provided Methods§

Source

fn cleanup<'life0, 'async_trait>( &'life0 self, ) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>
where Self: Sync + 'async_trait, 'life0: 'async_trait,

This callback will be called once after the service stops listening to its endpoints.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§

Source§

impl<T> ServerApp for T
where T: HttpServerApp + Send + Sync + 'static,