Struct penguin_mux::Multiplexor
source · pub struct Multiplexor<S> { /* private fields */ }
Expand description
A multiplexor over a WebSocket
connection.
Implementations§
source§impl<S: WebSocketStream> Multiplexor<S>
impl<S: WebSocketStream> Multiplexor<S>
sourcepub fn new(
ws: S,
role: Role,
keepalive_interval: Option<Duration>,
task_joinset: Option<&mut JoinSet<Result<()>>>
) -> Self
pub fn new( ws: S, role: Role, keepalive_interval: Option<Duration>, task_joinset: Option<&mut JoinSet<Result<()>>> ) -> Self
Create a new Multiplexor
.
Arguments
-
ws
: TheWebSocket
connection to multiplex over. -
role
: The role of this side of the connection. (does not have to match theWebSocket
role) -
keepalive_interval
: The interval at which to sendPing
frames. -
task_joinset
: AJoinSet
to spawn the multiplexor task into so that the caller can notice if the task exits. If it isNone
, the task will be spawned bytokio::spawn
and errors will be logged.
sourcepub async fn client_new_stream_channel(
&self,
host: &[u8],
port: u16
) -> Result<MuxStream<S>>
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.
sourcepub async fn server_new_stream_channel(&self) -> Result<MuxStream<S>>
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.
sourcepub async fn get_datagram(&self) -> Result<DatagramFrame>
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.
sourcepub async fn send_datagram(&self, frame: DatagramFrame) -> Result<()>
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 acrate::ws::Error
.
Cancel Safety
This function is cancel safe. If the task is cancelled, it is guaranteed that the datagram has not been sent.