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§
Required Methods§
Sourcefn new_rpc(
&mut self,
initiating_message: Self::Request,
responder: RpcResponder<'_, Self::Response>,
)
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§
Sourcefn poll(self: Pin<&mut Self>, _context: &mut Context<'_>) -> ControlFlow<()>
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.