Module protocol

Module protocol 

Source
Expand description

Tools for spawning an accept loop that routes incoming requests to the right protocol.

§Example

let endpoint = Endpoint::bind().await?;

let router = Router::builder(endpoint).accept(b"/my/alpn", Echo).spawn();

// The protocol definition:
#[derive(Debug, Clone)]
struct Echo;

impl ProtocolHandler for Echo {
    async fn accept(&self, connection: Connection) -> Result<(), AcceptError> {
        let (mut send, mut recv) = connection.accept_bi().await?;

        // Echo any bytes received back directly.
        let bytes_sent = tokio::io::copy(&mut recv, &mut send).await?;

        send.finish()?;
        connection.closed().await;

        Ok(())
    }
}

Structs§

AccessLimit
Wraps an existing protocol, limiting its access, based on the provided function.
Router
The built router.
RouterBuilder
Builder for creating a Router for accepting protocols.

Enums§

AcceptError

Traits§

DynProtocolHandler
A dyn-compatible version of ProtocolHandler that returns boxed futures.
ProtocolHandler
Handler for incoming connections.