pub struct Multiplexor<S> { /* private fields */ }
Expand description

A multiplexor over a WebSocket connection.

Implementations§

source§

impl<S: WebSocketStream> Multiplexor<S>

source

pub fn new( ws: S, role: Role, keepalive_interval: Option<Duration>, task_joinset: Option<&mut JoinSet<Result<()>>> ) -> Self

Create a new Multiplexor.

Arguments
  • ws: The WebSocket connection to multiplex over.

  • role: The role of this side of the connection. (does not have to match the WebSocket role)

  • keepalive_interval: The interval at which to send Ping frames.

  • task_joinset: A JoinSet to spawn the multiplexor task into so that the caller can notice if the task exits. If it is None, the task will be spawned by tokio::spawn and errors will be logged.

source

pub async fn client_new_stream_channel( &self, host: &[u8], port: u16 ) -> Result<MuxStream<S>>

Request a channel for host and port.

Arguments
  • host: The host to forward to. While the current implementation supports a domain of arbitrary length, Section 3.2.2 of RFC 3986 specifies that the host component of a URI is limited to 255 octets.
  • port: The port to forward to.
Panics

Panics if the Multiplexor is not a client.

Cancel safety

This function is not cancel safe. If the task is cancelled while waiting for the channel to be established, that channel may be established but inaccessible through normal means. Subsequent calls to this function will result in a new channel being established.

source

pub async fn server_new_stream_channel(&self) -> Result<MuxStream<S>>

Get the next available stream channel.

Errors

Returns Error::Closed if the connection is closed.

Panics

Panics if the Multiplexor is not a server.

Cancel Safety

This function is cancel safe. If the task is cancelled while waiting for a new connection, it is guaranteed that no connected stream will be lost.

source

pub async fn get_datagram(&self) -> Result<DatagramFrame>

Get the next available datagram.

Errors

Returns Error::Closed if the connection is closed.

Cancel Safety

This function is cancel safe. If the task is cancelled while waiting for a datagram, it is guaranteed that no datagram will be lost.

source

pub async fn send_datagram(&self, frame: DatagramFrame) -> Result<()>

Send a datagram

Errors
  • Returns Error::DatagramHostTooLong if the destination host is longer than 255 octets.
  • Returns Error::SendDatagram if the datagram could not be sent due to a crate::ws::Error.
Cancel Safety

This function is cancel safe. If the task is cancelled, it is guaranteed that the datagram has not been sent.

Trait Implementations§

source§

impl<S: Debug> Debug for Multiplexor<S>

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl<S> Drop for Multiplexor<S>

source§

fn drop(&mut self)

Executes the destructor for this type. Read more

Auto Trait Implementations§

§

impl<S> !RefUnwindSafe for Multiplexor<S>

§

impl<S> Send for Multiplexor<S>where S: Send,

§

impl<S> Sync for Multiplexor<S>where S: Send,

§

impl<S> Unpin for Multiplexor<S>

§

impl<S> !UnwindSafe for Multiplexor<S>

Blanket Implementations§

source§

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

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

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

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere 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 Twhere 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> Same for T

§

type Output = T

Should always be Self
source§

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

§

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 Twhere U: TryFrom<T>,

§

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.
§

impl<V, T> VZip<V> for Twhere V: MultiLane<T>,

§

fn vzip(self) -> V

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