pub struct WebSocketHandler { /* private fields */ }Expand description
Handle raw messages from a websocket.
Use WebSocketHandler to implement a Websocket server.
Implementations§
Source§impl WebSocketHandler
impl WebSocketHandler
Sourcepub fn new(router: WebSocketRouter, max_in_flight: usize) -> Arc<Self>
pub fn new(router: WebSocketRouter, max_in_flight: usize) -> Arc<Self>
Constructor.
max_in_flight limits the number of RPC/Subscription calls that can be
in-flight at once. This stops clients spawning lots of tasks by blocking
the websocket.
Subscriptions are only considered in-flight until they’ve sent their
initial response to the client. To limit the active subscriptions, use a
Semaphore or similar mechanism in the function that generates the
Stream and hold an OwnedSemaphorePermit permit for the life
of the stream.
pub async fn handle_socket<SocketSink, Incoming, Outgoing>( self: &Arc<Self>, outgoing: SocketSink, incoming: impl Stream<Item = Incoming>, ) -> Result<()>
Sourcepub async fn handle_msg(
&self,
msg: &[u8],
result_sink: &Sender<Result<Vec<u8>>>,
) -> Result<()>
pub async fn handle_msg( &self, msg: &[u8], result_sink: &Sender<Result<Vec<u8>>>, ) -> Result<()>
Handle a raw Websocket message.
This will read a MsgId from the message and route it to the correct
implementation. Prefer using Self::handle_socket if it’s general
enough.
Auto Trait Implementations§
impl Freeze for WebSocketHandler
impl !RefUnwindSafe for WebSocketHandler
impl Send for WebSocketHandler
impl Sync for WebSocketHandler
impl Unpin for WebSocketHandler
impl !UnwindSafe for WebSocketHandler
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more