pub trait RpcHandler:
Send
+ Sync
+ 'static {
type Context: Send + Sync;
// Required method
fn handshake<'life0, 'life1, 'life2, 'async_trait>(
self: Arc<Self>,
peer: &'life0 SocketAddr,
sender: &'life1 mut WebSocketSender,
receiver: &'life2 mut WebSocketReceiver,
messenger: Arc<Messenger>,
) -> Pin<Box<dyn Future<Output = WebSocketResult<Self::Context>> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait;
// Provided methods
fn accept(&self, _peer: &SocketAddr) -> bool { ... }
fn connect<'life0, 'async_trait>(
self: Arc<Self>,
_peer: &'life0 SocketAddr,
) -> Pin<Box<dyn Future<Output = WebSocketResult<()>> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait { ... }
fn disconnect<'async_trait>(
self: Arc<Self>,
_ctx: Self::Context,
_result: WebSocketResult<()>,
) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>
where Self: 'async_trait { ... }
}
Expand description
RpcHandler
- a server-side event handler for RPC connections.
Required Associated Types§
Required Methods§
Sourcefn handshake<'life0, 'life1, 'life2, 'async_trait>(
self: Arc<Self>,
peer: &'life0 SocketAddr,
sender: &'life1 mut WebSocketSender,
receiver: &'life2 mut WebSocketReceiver,
messenger: Arc<Messenger>,
) -> Pin<Box<dyn Future<Output = WebSocketResult<Self::Context>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
fn handshake<'life0, 'life1, 'life2, 'async_trait>(
self: Arc<Self>,
peer: &'life0 SocketAddr,
sender: &'life1 mut WebSocketSender,
receiver: &'life2 mut WebSocketReceiver,
messenger: Arc<Messenger>,
) -> Pin<Box<dyn Future<Output = WebSocketResult<Self::Context>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
RpcHandler::handshake()
is called right after RpcHandler::connect()
and is provided with a WebSocketSender
and WebSocketReceiver
channels
which can be used to communicate with the underlying WebSocket connection
to negotiate a connection. The function also receives the &peer
(SocketAddr
)
of the connection and a Messenger
struct. The Messenger
struct can
be used to post notifications to the given connection as well as to close it.
If negotiation is successful, this function should return a ConnectionContext
defined as Self::Context
. This context will be supplied to all subsequent
RPC calls received from this connection. The Messenger
struct can be
cloned and captured within the ConnectionContext
. This allows an RPC
method handler to later capture and post notifications to the connection
asynchronously.
Provided Methods§
Sourcefn accept(&self, _peer: &SocketAddr) -> bool
fn accept(&self, _peer: &SocketAddr) -> bool
Called to determine if the connection should be accepted.
Sourcefn connect<'life0, 'async_trait>(
self: Arc<Self>,
_peer: &'life0 SocketAddr,
) -> Pin<Box<dyn Future<Output = WebSocketResult<()>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
fn connect<'life0, 'async_trait>(
self: Arc<Self>,
_peer: &'life0 SocketAddr,
) -> Pin<Box<dyn Future<Output = WebSocketResult<()>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
Connection notification - issued when the server has opened a WebSocket
connection, before any other interactions occur. The supplied argument
is the SocketAddr
of the incoming connection. This function should
return WebSocketResult::Ok
if the server accepts connection or
WebSocketError
if the connection is rejected. This function can
be used to reject connections based on a ban list.
Sourcefn disconnect<'async_trait>(
self: Arc<Self>,
_ctx: Self::Context,
_result: WebSocketResult<()>,
) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>where
Self: 'async_trait,
fn disconnect<'async_trait>(
self: Arc<Self>,
_ctx: Self::Context,
_result: WebSocketResult<()>,
) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>where
Self: 'async_trait,
Disconnect notification, receives the context and the result containing the disconnection reason (can be success if the connection is closed gracefully)