pub trait ChatListener: Send + Sync {
// Required methods
fn address(&self) -> &str;
fn protocol(&self) -> &str;
fn start<'life0, 'async_trait>(
&'life0 mut self,
handler: MessageHandler,
alive: Sender<()>,
) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait;
fn shutdown<'life0, 'async_trait>(
&'life0 mut self,
) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait;
}Expand description
A single network endpoint: one (protocol, address, port) combination.
Listeners handle all wire-protocol details. When ChatListener::start is
called the listener binds its address, accepts connections, parses inbound
data into Messages, invokes the provided MessageHandler, and sends
any replies back in the appropriate wire format.
Required Methods§
Sourcefn start<'life0, 'async_trait>(
&'life0 mut self,
handler: MessageHandler,
alive: Sender<()>,
) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
fn start<'life0, 'async_trait>(
&'life0 mut self,
handler: MessageHandler,
alive: Sender<()>,
) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
Start accepting connections and processing messages.
The handler is called for every inbound message; the optional String
return value is a reply that the listener formats into its wire protocol.
The alive sender should be held (cloned) by every spawned task. When
all clones are dropped the server knows this listener has fully stopped.