Struct WebSocketHandler

Source
pub struct WebSocketHandler { /* private fields */ }
Expand description

Handle raw messages from a websocket.

Use WebSocketHandler to implement a Websocket server.

Implementations§

Source§

impl WebSocketHandler

Source

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.

Source

pub async fn handle_socket<SocketSink, Incoming, Outgoing>( self: &Arc<Self>, outgoing: SocketSink, incoming: impl Stream<Item = Incoming>, ) -> Result<()>
where Incoming: AsRef<[u8]> + Send + Sync + 'static, Outgoing: From<Vec<u8>>, SocketSink: Sink<Outgoing> + Unpin, SocketSink::Error: Error,

Source

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§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more