Skip to main content

ConnectionService

Trait ConnectionService 

Source
pub trait ConnectionService: Unpin + 'static {
    type Request: Message;
    type Response: Message;

    // Required method
    fn new_rpc(
        &mut self,
        initiating_message: Self::Request,
        responder: RpcResponder<'_, Self::Response>,
    );

    // Provided method
    fn poll(self: Pin<&mut Self>, _context: &mut Context<'_>) -> ControlFlow<()> { ... }
}
Expand description

A connection service receives rpcs from clients and sends responses.

Each client connection gets a ConnectionService. You put your per-connection state in your ConnectionService implementation.

Every interaction with a client is done via an RPC. You are called with the initiating message from the client, and you return the kind of response future that is used to complete the RPC.

A ConnectionService is executed in the context of an RPC connection server, which is a future. This means you get &mut self when you are called with a new rpc. You can use simple mutable state per-connection; but if you need to share state between connections or elsewhere in your application, you will need to use an appropriate state sharing mechanism.

Required Associated Types§

Source

type Request: Message

The type of request message, These messages initiate rpcs.

Source

type Response: Message

The type of response message, These messages complete rpcs, or are streamed from them.

Required Methods§

Source

fn new_rpc( &mut self, initiating_message: Self::Request, responder: RpcResponder<'_, Self::Response>, )

Create a new rpc task completion.

You send the response via the RpcResponder.

Provided Methods§

Source

fn poll(self: Pin<&mut Self>, _context: &mut Context<'_>) -> ControlFlow<()>

Optional poll to allow the connection to push work forward internally.

You can use this to drive connection state machines (e.g., FuturesUnordered), or whatever else you need to do with your connection between reading from the network and writing to it.

Implementors§