mirror of
https://github.com/MercuryWorkshop/epoxy-tls.git
synced 2025-05-12 14:00:01 -04:00
rename to transportread/transportwrite/transportreadext/transportext
This commit is contained in:
parent
3f381d6b39
commit
a986fc07c4
16 changed files with 96 additions and 96 deletions
|
@ -19,7 +19,7 @@ use wisp_mux::{
|
||||||
extensions::{udp::UdpProtocolExtensionBuilder, AnyProtocolExtensionBuilder},
|
extensions::{udp::UdpProtocolExtensionBuilder, AnyProtocolExtensionBuilder},
|
||||||
packet::StreamType,
|
packet::StreamType,
|
||||||
stream::{MuxStream, MuxStreamAsyncRW},
|
stream::{MuxStream, MuxStreamAsyncRW},
|
||||||
ws::{WebSocketRead, WebSocketWrite},
|
ws::{TransportRead, TransportWrite},
|
||||||
ClientMux, WispV2Handshake,
|
ClientMux, WispV2Handshake,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -33,8 +33,8 @@ pub type ProviderUnencryptedStream = MuxStream<ProviderWispTransportWrite>;
|
||||||
pub type ProviderUnencryptedAsyncRW = MuxStreamAsyncRW<ProviderWispTransportWrite>;
|
pub type ProviderUnencryptedAsyncRW = MuxStreamAsyncRW<ProviderWispTransportWrite>;
|
||||||
pub type ProviderTlsAsyncRW = IgnoreCloseNotify;
|
pub type ProviderTlsAsyncRW = IgnoreCloseNotify;
|
||||||
pub type ProviderAsyncRW = Either<ProviderTlsAsyncRW, ProviderUnencryptedAsyncRW>;
|
pub type ProviderAsyncRW = Either<ProviderTlsAsyncRW, ProviderUnencryptedAsyncRW>;
|
||||||
pub type ProviderWispTransportRead = Pin<Box<dyn WebSocketRead>>;
|
pub type ProviderWispTransportRead = Pin<Box<dyn TransportRead>>;
|
||||||
pub type ProviderWispTransportWrite = Pin<Box<dyn WebSocketWrite>>;
|
pub type ProviderWispTransportWrite = Pin<Box<dyn TransportWrite>>;
|
||||||
pub type ProviderWispTransportGenerator = Box<
|
pub type ProviderWispTransportGenerator = Box<
|
||||||
dyn Fn(
|
dyn Fn(
|
||||||
bool,
|
bool,
|
||||||
|
|
|
@ -17,7 +17,7 @@ use wisp_mux::{
|
||||||
},
|
},
|
||||||
packet::{CloseReason, ConnectPacket},
|
packet::{CloseReason, ConnectPacket},
|
||||||
stream::{MuxStream, MuxStreamRead, MuxStreamWrite},
|
stream::{MuxStream, MuxStreamRead, MuxStreamWrite},
|
||||||
ws::{WebSocketRead, WebSocketWrite},
|
ws::{TransportRead, TransportWrite},
|
||||||
ClientMux, Role, WispError, WispV2Handshake,
|
ClientMux, Role, WispError, WispV2Handshake,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -98,8 +98,8 @@ impl ProtocolExtension for WispnetServerProtocolExtension {
|
||||||
|
|
||||||
async fn handle_handshake(
|
async fn handle_handshake(
|
||||||
&mut self,
|
&mut self,
|
||||||
_: &mut dyn WebSocketRead,
|
_: &mut dyn TransportRead,
|
||||||
_: &mut dyn WebSocketWrite,
|
_: &mut dyn TransportWrite,
|
||||||
) -> Result<(), WispError> {
|
) -> Result<(), WispError> {
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
@ -108,8 +108,8 @@ impl ProtocolExtension for WispnetServerProtocolExtension {
|
||||||
&mut self,
|
&mut self,
|
||||||
packet_type: u8,
|
packet_type: u8,
|
||||||
mut packet: Bytes,
|
mut packet: Bytes,
|
||||||
_: &mut dyn WebSocketRead,
|
_: &mut dyn TransportRead,
|
||||||
write: &mut dyn WebSocketWrite,
|
write: &mut dyn TransportWrite,
|
||||||
) -> Result<(), WispError> {
|
) -> Result<(), WispError> {
|
||||||
if packet_type == Self::ID {
|
if packet_type == Self::ID {
|
||||||
if packet.remaining() < 4 {
|
if packet.remaining() < 4 {
|
||||||
|
|
|
@ -13,7 +13,7 @@ use log::{debug, error, trace};
|
||||||
use tokio_util::codec::{FramedRead, FramedWrite, LengthDelimitedCodec};
|
use tokio_util::codec::{FramedRead, FramedWrite, LengthDelimitedCodec};
|
||||||
use tokio_websockets::Limits;
|
use tokio_websockets::Limits;
|
||||||
use wisp_mux::ws::{
|
use wisp_mux::ws::{
|
||||||
TokioWebsocketsTransport, WebSocketExt, WebSocketSplitRead, WebSocketSplitWrite,
|
TokioWebsocketsTransport, TransportExt, WebSocketSplitRead, WebSocketSplitWrite,
|
||||||
};
|
};
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
|
|
|
@ -34,7 +34,7 @@ use wisp_mux::{
|
||||||
AnyProtocolExtensionBuilder, ProtocolExtensionListExt,
|
AnyProtocolExtensionBuilder, ProtocolExtensionListExt,
|
||||||
},
|
},
|
||||||
packet::StreamType,
|
packet::StreamType,
|
||||||
ws::{TokioWebsocketsTransport, WebSocketWrite, WebSocketExt},
|
ws::{TokioWebsocketsTransport, TransportWrite, TransportExt},
|
||||||
ClientMux, WispError, WispV2Handshake,
|
ClientMux, WispError, WispV2Handshake,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -98,7 +98,7 @@ async fn create_mux(
|
||||||
opts: &Cli,
|
opts: &Cli,
|
||||||
) -> Result<
|
) -> Result<
|
||||||
(
|
(
|
||||||
ClientMux<impl WebSocketWrite>,
|
ClientMux<impl TransportWrite>,
|
||||||
impl Future<Output = Result<(), WispError>> + Send,
|
impl Future<Output = Result<(), WispError>> + Send,
|
||||||
),
|
),
|
||||||
Box<dyn Error + Send + Sync>,
|
Box<dyn Error + Send + Sync>,
|
||||||
|
|
|
@ -15,7 +15,7 @@ use async_trait::async_trait;
|
||||||
use bytes::{BufMut, Bytes};
|
use bytes::{BufMut, Bytes};
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
ws::{PayloadMut, WebSocketRead, WebSocketWrite},
|
ws::{PayloadMut, TransportRead, TransportWrite},
|
||||||
Role, WispError,
|
Role, WispError,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -112,8 +112,8 @@ pub trait ProtocolExtension: std::fmt::Debug + Sync + Send + 'static {
|
||||||
/// This should be used to send or receive data before any streams are created.
|
/// This should be used to send or receive data before any streams are created.
|
||||||
async fn handle_handshake(
|
async fn handle_handshake(
|
||||||
&mut self,
|
&mut self,
|
||||||
read: &mut dyn WebSocketRead,
|
read: &mut dyn TransportRead,
|
||||||
write: &mut dyn WebSocketWrite,
|
write: &mut dyn TransportWrite,
|
||||||
) -> Result<(), WispError> {
|
) -> Result<(), WispError> {
|
||||||
let _ = (read, write);
|
let _ = (read, write);
|
||||||
Ok(())
|
Ok(())
|
||||||
|
@ -124,8 +124,8 @@ pub trait ProtocolExtension: std::fmt::Debug + Sync + Send + 'static {
|
||||||
&mut self,
|
&mut self,
|
||||||
packet_type: u8,
|
packet_type: u8,
|
||||||
packet: Bytes,
|
packet: Bytes,
|
||||||
read: &mut dyn WebSocketRead,
|
read: &mut dyn TransportRead,
|
||||||
write: &mut dyn WebSocketWrite,
|
write: &mut dyn TransportWrite,
|
||||||
) -> Result<(), WispError> {
|
) -> Result<(), WispError> {
|
||||||
let _ = (packet_type, packet, read, write);
|
let _ = (packet_type, packet, read, write);
|
||||||
Ok(())
|
Ok(())
|
||||||
|
|
|
@ -16,13 +16,13 @@ use std::{
|
||||||
use futures::Sink;
|
use futures::Sink;
|
||||||
use slab::Slab;
|
use slab::Slab;
|
||||||
|
|
||||||
use crate::ws::{Payload, WebSocketWrite};
|
use crate::ws::{Payload, TransportWrite};
|
||||||
|
|
||||||
// it would be nice to have type_alias_bounds but oh well
|
// it would be nice to have type_alias_bounds but oh well
|
||||||
#[expect(type_alias_bounds)]
|
#[expect(type_alias_bounds)]
|
||||||
pub(crate) type LockedWebSocketWrite<I: WebSocketWrite> = LockedSink<I, Payload>;
|
pub(crate) type LockedWebSocketWrite<I: TransportWrite> = LockedSink<I, Payload>;
|
||||||
#[expect(type_alias_bounds)]
|
#[expect(type_alias_bounds)]
|
||||||
pub type LockedWebSocketWriteGuard<I: WebSocketWrite> = LockedSinkGuard<I, Payload>;
|
pub type LockedWebSocketWriteGuard<I: TransportWrite> = LockedSinkGuard<I, Payload>;
|
||||||
|
|
||||||
pub(crate) enum Waiter {
|
pub(crate) enum Waiter {
|
||||||
Sleeping(Waker),
|
Sleeping(Waker),
|
||||||
|
|
|
@ -5,7 +5,7 @@ use crate::{
|
||||||
mux::send_info_packet,
|
mux::send_info_packet,
|
||||||
packet::{ConnectPacket, ContinuePacket, MaybeInfoPacket, Packet, StreamType},
|
packet::{ConnectPacket, ContinuePacket, MaybeInfoPacket, Packet, StreamType},
|
||||||
stream::MuxStream,
|
stream::MuxStream,
|
||||||
ws::{WebSocketRead, WebSocketReadExt, WebSocketWrite},
|
ws::{TransportRead, TransportReadExt, TransportWrite},
|
||||||
LockedWebSocketWrite, Role, WispError,
|
LockedWebSocketWrite, Role, WispError,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -18,7 +18,7 @@ use super::{
|
||||||
|
|
||||||
pub(crate) struct ClientActor;
|
pub(crate) struct ClientActor;
|
||||||
|
|
||||||
impl<W: WebSocketWrite> MultiplexorActor<W> for ClientActor {
|
impl<W: TransportWrite> MultiplexorActor<W> for ClientActor {
|
||||||
fn handle_connect_packet(
|
fn handle_connect_packet(
|
||||||
&mut self,
|
&mut self,
|
||||||
_: crate::stream::MuxStream<W>,
|
_: crate::stream::MuxStream<W>,
|
||||||
|
@ -54,10 +54,10 @@ impl<W: WebSocketWrite> MultiplexorActor<W> for ClientActor {
|
||||||
|
|
||||||
pub struct ClientImpl;
|
pub struct ClientImpl;
|
||||||
|
|
||||||
impl<W: WebSocketWrite> MultiplexorImpl<W> for ClientImpl {
|
impl<W: TransportWrite> MultiplexorImpl<W> for ClientImpl {
|
||||||
type Actor = ClientActor;
|
type Actor = ClientActor;
|
||||||
|
|
||||||
async fn handshake<R: WebSocketRead>(
|
async fn handshake<R: TransportRead>(
|
||||||
&mut self,
|
&mut self,
|
||||||
rx: &mut R,
|
rx: &mut R,
|
||||||
tx: &mut LockedWebSocketWrite<W>,
|
tx: &mut LockedWebSocketWrite<W>,
|
||||||
|
@ -126,14 +126,14 @@ impl<W: WebSocketWrite> MultiplexorImpl<W> for ClientImpl {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<W: WebSocketWrite> Multiplexor<ClientImpl, W> {
|
impl<W: TransportWrite> Multiplexor<ClientImpl, W> {
|
||||||
/// Create a new client side multiplexor.
|
/// Create a new client side multiplexor.
|
||||||
///
|
///
|
||||||
/// If `wisp_v2` is None a Wisp v1 connection is created, otherwise a Wisp v2 connection is created.
|
/// If `wisp_v2` is None a Wisp v1 connection is created, otherwise a Wisp v2 connection is created.
|
||||||
/// **It is not guaranteed that all extensions you specify are available.** You must manually check
|
/// **It is not guaranteed that all extensions you specify are available.** You must manually check
|
||||||
/// if the extensions you need are available after the multiplexor has been created.
|
/// if the extensions you need are available after the multiplexor has been created.
|
||||||
#[expect(clippy::new_ret_no_self)]
|
#[expect(clippy::new_ret_no_self)]
|
||||||
pub async fn new<R: WebSocketRead>(
|
pub async fn new<R: TransportRead>(
|
||||||
rx: R,
|
rx: R,
|
||||||
tx: W,
|
tx: W,
|
||||||
wisp_v2: Option<WispV2Handshake>,
|
wisp_v2: Option<WispV2Handshake>,
|
||||||
|
|
|
@ -22,11 +22,11 @@ use crate::{
|
||||||
PacketType, StreamType,
|
PacketType, StreamType,
|
||||||
},
|
},
|
||||||
stream::MuxStream,
|
stream::MuxStream,
|
||||||
ws::{Payload, WebSocketRead, WebSocketWrite},
|
ws::{Payload, TransportRead, TransportWrite},
|
||||||
LockedWebSocketWrite, WispError,
|
LockedWebSocketWrite, WispError,
|
||||||
};
|
};
|
||||||
|
|
||||||
pub(crate) enum WsEvent<W: WebSocketWrite> {
|
pub(crate) enum WsEvent<W: TransportWrite> {
|
||||||
Close(u32, ClosePacket, oneshot::Sender<Result<(), WispError>>),
|
Close(u32, ClosePacket, oneshot::Sender<Result<(), WispError>>),
|
||||||
CreateStream(
|
CreateStream(
|
||||||
ConnectPacket,
|
ConnectPacket,
|
||||||
|
@ -135,7 +135,7 @@ impl StreamInfo {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) trait MultiplexorActor<W: WebSocketWrite>: Send {
|
pub(crate) trait MultiplexorActor<W: TransportWrite>: Send {
|
||||||
fn handle_connect_packet(
|
fn handle_connect_packet(
|
||||||
&mut self,
|
&mut self,
|
||||||
stream: MuxStream<W>,
|
stream: MuxStream<W>,
|
||||||
|
@ -164,14 +164,14 @@ pub(crate) trait MultiplexorActor<W: WebSocketWrite>: Send {
|
||||||
fn get_flow_control(ty: StreamType, flow_stream_types: &[u8]) -> FlowControl;
|
fn get_flow_control(ty: StreamType, flow_stream_types: &[u8]) -> FlowControl;
|
||||||
}
|
}
|
||||||
|
|
||||||
struct MuxStart<R: WebSocketRead, W: WebSocketWrite> {
|
struct MuxStart<R: TransportRead, W: TransportWrite> {
|
||||||
rx: R,
|
rx: R,
|
||||||
downgrade: Option<Packet<'static>>,
|
downgrade: Option<Packet<'static>>,
|
||||||
extensions: Vec<AnyProtocolExtension>,
|
extensions: Vec<AnyProtocolExtension>,
|
||||||
actor_rx: flume::Receiver<WsEvent<W>>,
|
actor_rx: flume::Receiver<WsEvent<W>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) struct MuxInner<R: WebSocketRead, W: WebSocketWrite, M: MultiplexorActor<W>> {
|
pub(crate) struct MuxInner<R: TransportRead, W: TransportWrite, M: MultiplexorActor<W>> {
|
||||||
start: Option<MuxStart<R, W>>,
|
start: Option<MuxStart<R, W>>,
|
||||||
tx: LockedWebSocketWrite<W>,
|
tx: LockedWebSocketWrite<W>,
|
||||||
flow_stream_types: Box<[u8]>,
|
flow_stream_types: Box<[u8]>,
|
||||||
|
@ -185,12 +185,12 @@ pub(crate) struct MuxInner<R: WebSocketRead, W: WebSocketWrite, M: MultiplexorAc
|
||||||
actor_tx: flume::Sender<WsEvent<W>>,
|
actor_tx: flume::Sender<WsEvent<W>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) struct MuxInnerResult<R: WebSocketRead, W: WebSocketWrite, M: MultiplexorActor<W>> {
|
pub(crate) struct MuxInnerResult<R: TransportRead, W: TransportWrite, M: MultiplexorActor<W>> {
|
||||||
pub mux: MuxInner<R, W, M>,
|
pub mux: MuxInner<R, W, M>,
|
||||||
pub actor_tx: flume::Sender<WsEvent<W>>,
|
pub actor_tx: flume::Sender<WsEvent<W>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<R: WebSocketRead, W: WebSocketWrite, M: MultiplexorActor<W>> MuxInner<R, W, M> {
|
impl<R: TransportRead, W: TransportWrite, M: MultiplexorActor<W>> MuxInner<R, W, M> {
|
||||||
#[expect(clippy::new_ret_no_self)]
|
#[expect(clippy::new_ret_no_self)]
|
||||||
pub fn new(
|
pub fn new(
|
||||||
rx: R,
|
rx: R,
|
||||||
|
|
|
@ -15,7 +15,7 @@ pub type ClientMux<W> = Multiplexor<ClientImpl, W>;
|
||||||
use crate::{
|
use crate::{
|
||||||
extensions::{udp::UdpProtocolExtension, AnyProtocolExtension, AnyProtocolExtensionBuilder},
|
extensions::{udp::UdpProtocolExtension, AnyProtocolExtension, AnyProtocolExtensionBuilder},
|
||||||
packet::{CloseReason, InfoPacket, Packet, PacketType},
|
packet::{CloseReason, InfoPacket, Packet, PacketType},
|
||||||
ws::{WebSocketRead, WebSocketWrite},
|
ws::{TransportRead, TransportWrite},
|
||||||
LockedWebSocketWrite, LockedWebSocketWriteGuard, Role, WispError, WISP_VERSION,
|
LockedWebSocketWrite, LockedWebSocketWriteGuard, Role, WispError, WISP_VERSION,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -43,7 +43,7 @@ impl WispHandshakeResultKind {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn handle_handshake<R: WebSocketRead, W: WebSocketWrite>(
|
async fn handle_handshake<R: TransportRead, W: TransportWrite>(
|
||||||
read: &mut R,
|
read: &mut R,
|
||||||
write: &mut LockedWebSocketWrite<W>,
|
write: &mut LockedWebSocketWrite<W>,
|
||||||
extensions: &mut [AnyProtocolExtension],
|
extensions: &mut [AnyProtocolExtension],
|
||||||
|
@ -58,7 +58,7 @@ async fn handle_handshake<R: WebSocketRead, W: WebSocketWrite>(
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn send_info_packet<W: WebSocketWrite>(
|
async fn send_info_packet<W: TransportWrite>(
|
||||||
write: &mut LockedWebSocketWrite<W>,
|
write: &mut LockedWebSocketWrite<W>,
|
||||||
builders: &mut [AnyProtocolExtensionBuilder],
|
builders: &mut [AnyProtocolExtensionBuilder],
|
||||||
role: Role,
|
role: Role,
|
||||||
|
@ -104,10 +104,10 @@ fn get_supported_extensions(
|
||||||
.collect()
|
.collect()
|
||||||
}
|
}
|
||||||
|
|
||||||
trait MultiplexorImpl<W: WebSocketWrite> {
|
trait MultiplexorImpl<W: TransportWrite> {
|
||||||
type Actor: MultiplexorActor<W> + 'static;
|
type Actor: MultiplexorActor<W> + 'static;
|
||||||
|
|
||||||
async fn handshake<R: WebSocketRead>(
|
async fn handshake<R: TransportRead>(
|
||||||
&mut self,
|
&mut self,
|
||||||
rx: &mut R,
|
rx: &mut R,
|
||||||
tx: &mut LockedWebSocketWrite<W>,
|
tx: &mut LockedWebSocketWrite<W>,
|
||||||
|
@ -122,7 +122,7 @@ trait MultiplexorImpl<W: WebSocketWrite> {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[expect(private_bounds)]
|
#[expect(private_bounds)]
|
||||||
pub struct Multiplexor<M: MultiplexorImpl<W>, W: WebSocketWrite> {
|
pub struct Multiplexor<M: MultiplexorImpl<W>, W: TransportWrite> {
|
||||||
mux: M,
|
mux: M,
|
||||||
|
|
||||||
downgraded: bool,
|
downgraded: bool,
|
||||||
|
@ -133,7 +133,7 @@ pub struct Multiplexor<M: MultiplexorImpl<W>, W: WebSocketWrite> {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[expect(private_bounds)]
|
#[expect(private_bounds)]
|
||||||
impl<M: MultiplexorImpl<W>, W: WebSocketWrite> Multiplexor<M, W> {
|
impl<M: MultiplexorImpl<W>, W: TransportWrite> Multiplexor<M, W> {
|
||||||
async fn create<R>(
|
async fn create<R>(
|
||||||
mut rx: R,
|
mut rx: R,
|
||||||
tx: W,
|
tx: W,
|
||||||
|
@ -142,7 +142,7 @@ impl<M: MultiplexorImpl<W>, W: WebSocketWrite> Multiplexor<M, W> {
|
||||||
actor: M::Actor,
|
actor: M::Actor,
|
||||||
) -> Result<MuxResult<M, W>, WispError>
|
) -> Result<MuxResult<M, W>, WispError>
|
||||||
where
|
where
|
||||||
R: WebSocketRead,
|
R: TransportRead,
|
||||||
{
|
{
|
||||||
let mut tx = LockedWebSocketWrite::new(tx);
|
let mut tx = LockedWebSocketWrite::new(tx);
|
||||||
|
|
||||||
|
@ -256,13 +256,13 @@ pub type MultiplexorActorFuture = Pin<Box<dyn Future<Output = Result<(), WispErr
|
||||||
pub struct MuxResult<M, W>(Multiplexor<M, W>, MultiplexorActorFuture)
|
pub struct MuxResult<M, W>(Multiplexor<M, W>, MultiplexorActorFuture)
|
||||||
where
|
where
|
||||||
M: MultiplexorImpl<W>,
|
M: MultiplexorImpl<W>,
|
||||||
W: WebSocketWrite;
|
W: TransportWrite;
|
||||||
|
|
||||||
#[expect(private_bounds)]
|
#[expect(private_bounds)]
|
||||||
impl<M, W> MuxResult<M, W>
|
impl<M, W> MuxResult<M, W>
|
||||||
where
|
where
|
||||||
M: MultiplexorImpl<W>,
|
M: MultiplexorImpl<W>,
|
||||||
W: WebSocketWrite,
|
W: TransportWrite,
|
||||||
{
|
{
|
||||||
/// Require no protocol extensions.
|
/// Require no protocol extensions.
|
||||||
pub fn with_no_required_extensions(self) -> (Multiplexor<M, W>, MultiplexorActorFuture) {
|
pub fn with_no_required_extensions(self) -> (Multiplexor<M, W>, MultiplexorActorFuture) {
|
||||||
|
|
|
@ -4,7 +4,7 @@ use crate::{
|
||||||
locked_sink::LockedWebSocketWrite,
|
locked_sink::LockedWebSocketWrite,
|
||||||
packet::{CloseReason, ConnectPacket, MaybeInfoPacket, Packet, StreamType},
|
packet::{CloseReason, ConnectPacket, MaybeInfoPacket, Packet, StreamType},
|
||||||
stream::MuxStream,
|
stream::MuxStream,
|
||||||
ws::{Payload, WebSocketRead, WebSocketReadExt, WebSocketWrite},
|
ws::{Payload, TransportRead, TransportReadExt, TransportWrite},
|
||||||
Role, WispError,
|
Role, WispError,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -15,11 +15,11 @@ use super::{
|
||||||
WispHandshakeResultKind, WispV2Handshake,
|
WispHandshakeResultKind, WispV2Handshake,
|
||||||
};
|
};
|
||||||
|
|
||||||
pub(crate) struct ServerActor<W: WebSocketWrite> {
|
pub(crate) struct ServerActor<W: TransportWrite> {
|
||||||
stream_tx: flume::Sender<(ConnectPacket, MuxStream<W>)>,
|
stream_tx: flume::Sender<(ConnectPacket, MuxStream<W>)>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<W: WebSocketWrite> MultiplexorActor<W> for ServerActor<W> {
|
impl<W: TransportWrite> MultiplexorActor<W> for ServerActor<W> {
|
||||||
fn handle_connect_packet(
|
fn handle_connect_packet(
|
||||||
&mut self,
|
&mut self,
|
||||||
stream: MuxStream<W>,
|
stream: MuxStream<W>,
|
||||||
|
@ -62,15 +62,15 @@ impl<W: WebSocketWrite> MultiplexorActor<W> for ServerActor<W> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct ServerImpl<W: WebSocketWrite> {
|
pub struct ServerImpl<W: TransportWrite> {
|
||||||
buffer_size: u32,
|
buffer_size: u32,
|
||||||
stream_rx: flume::Receiver<(ConnectPacket, MuxStream<W>)>,
|
stream_rx: flume::Receiver<(ConnectPacket, MuxStream<W>)>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<W: WebSocketWrite> MultiplexorImpl<W> for ServerImpl<W> {
|
impl<W: TransportWrite> MultiplexorImpl<W> for ServerImpl<W> {
|
||||||
type Actor = ServerActor<W>;
|
type Actor = ServerActor<W>;
|
||||||
|
|
||||||
async fn handshake<R: WebSocketRead>(
|
async fn handshake<R: TransportRead>(
|
||||||
&mut self,
|
&mut self,
|
||||||
rx: &mut R,
|
rx: &mut R,
|
||||||
tx: &mut LockedWebSocketWrite<W>,
|
tx: &mut LockedWebSocketWrite<W>,
|
||||||
|
@ -165,14 +165,14 @@ impl<W: WebSocketWrite> MultiplexorImpl<W> for ServerImpl<W> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<W: WebSocketWrite> Multiplexor<ServerImpl<W>, W> {
|
impl<W: TransportWrite> Multiplexor<ServerImpl<W>, W> {
|
||||||
/// Create a new server-side multiplexor.
|
/// Create a new server-side multiplexor.
|
||||||
///
|
///
|
||||||
/// If `wisp_v2` is None a Wisp v1 connection is created, otherwise a Wisp v2 connection is created.
|
/// If `wisp_v2` is None a Wisp v1 connection is created, otherwise a Wisp v2 connection is created.
|
||||||
/// **It is not guaranteed that all extensions you specify are available.** You must manually check
|
/// **It is not guaranteed that all extensions you specify are available.** You must manually check
|
||||||
/// if the extensions you need are available after the multiplexor has been created.
|
/// if the extensions you need are available after the multiplexor has been created.
|
||||||
#[expect(clippy::new_ret_no_self)]
|
#[expect(clippy::new_ret_no_self)]
|
||||||
pub async fn new<R: WebSocketRead>(
|
pub async fn new<R: TransportRead>(
|
||||||
rx: R,
|
rx: R,
|
||||||
tx: W,
|
tx: W,
|
||||||
buffer_size: u32,
|
buffer_size: u32,
|
||||||
|
|
|
@ -5,7 +5,7 @@ use num_enum::{FromPrimitive, IntoPrimitive};
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
extensions::{AnyProtocolExtension, AnyProtocolExtensionBuilder},
|
extensions::{AnyProtocolExtension, AnyProtocolExtensionBuilder},
|
||||||
ws::{Payload, PayloadMut, PayloadRef, WebSocketRead, WebSocketWrite},
|
ws::{Payload, PayloadMut, PayloadRef, TransportRead, TransportWrite},
|
||||||
LockedWebSocketWrite, Role, WispError, WISP_VERSION,
|
LockedWebSocketWrite, Role, WispError, WISP_VERSION,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -404,10 +404,10 @@ pub(crate) enum MaybeExtensionPacket<'a> {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl MaybeExtensionPacket<'static> {
|
impl MaybeExtensionPacket<'static> {
|
||||||
pub(crate) async fn decode<W: WebSocketWrite>(
|
pub(crate) async fn decode<W: TransportWrite>(
|
||||||
mut packet: Payload,
|
mut packet: Payload,
|
||||||
extensions: &mut [AnyProtocolExtension],
|
extensions: &mut [AnyProtocolExtension],
|
||||||
rx: &mut dyn WebSocketRead,
|
rx: &mut dyn TransportRead,
|
||||||
tx: &mut LockedWebSocketWrite<W>,
|
tx: &mut LockedWebSocketWrite<W>,
|
||||||
) -> Result<Self, WispError> {
|
) -> Result<Self, WispError> {
|
||||||
if packet.remaining() < size_of::<u8>() + size_of::<u32>() {
|
if packet.remaining() < size_of::<u8>() + size_of::<u32>() {
|
||||||
|
|
|
@ -14,15 +14,15 @@ use pin_project::pin_project;
|
||||||
use crate::{
|
use crate::{
|
||||||
locked_sink::LockedWebSocketWrite,
|
locked_sink::LockedWebSocketWrite,
|
||||||
packet::{ClosePacket, CloseReason, Packet},
|
packet::{ClosePacket, CloseReason, Packet},
|
||||||
ws::{Payload, WebSocketWrite},
|
ws::{Payload, TransportWrite},
|
||||||
WispError,
|
WispError,
|
||||||
};
|
};
|
||||||
|
|
||||||
use super::{MuxStream, MuxStreamRead, MuxStreamWrite, StreamInfo, WsEvent};
|
use super::{MuxStream, MuxStreamRead, MuxStreamWrite, StreamInfo, WsEvent};
|
||||||
|
|
||||||
struct MapToIo<W: WebSocketWrite>(MuxStreamRead<W>);
|
struct MapToIo<W: TransportWrite>(MuxStreamRead<W>);
|
||||||
|
|
||||||
impl<W: WebSocketWrite> Stream for MapToIo<W> {
|
impl<W: TransportWrite> Stream for MapToIo<W> {
|
||||||
type Item = Result<Payload, std::io::Error>;
|
type Item = Result<Payload, std::io::Error>;
|
||||||
|
|
||||||
fn poll_next(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Option<Self::Item>> {
|
fn poll_next(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Option<Self::Item>> {
|
||||||
|
@ -32,12 +32,12 @@ impl<W: WebSocketWrite> Stream for MapToIo<W> {
|
||||||
|
|
||||||
// TODO: don't use `futures` for this so get_close_reason etc can be implemented
|
// TODO: don't use `futures` for this so get_close_reason etc can be implemented
|
||||||
#[pin_project]
|
#[pin_project]
|
||||||
pub struct MuxStreamAsyncRead<W: WebSocketWrite> {
|
pub struct MuxStreamAsyncRead<W: TransportWrite> {
|
||||||
#[pin]
|
#[pin]
|
||||||
inner: IntoAsyncRead<MapToIo<W>>,
|
inner: IntoAsyncRead<MapToIo<W>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<W: WebSocketWrite> MuxStreamAsyncRead<W> {
|
impl<W: TransportWrite> MuxStreamAsyncRead<W> {
|
||||||
pub(crate) fn new(inner: MuxStreamRead<W>) -> Self {
|
pub(crate) fn new(inner: MuxStreamRead<W>) -> Self {
|
||||||
Self {
|
Self {
|
||||||
inner: MapToIo(inner).into_async_read(),
|
inner: MapToIo(inner).into_async_read(),
|
||||||
|
@ -45,7 +45,7 @@ impl<W: WebSocketWrite> MuxStreamAsyncRead<W> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<W: WebSocketWrite> AsyncRead for MuxStreamAsyncRead<W> {
|
impl<W: TransportWrite> AsyncRead for MuxStreamAsyncRead<W> {
|
||||||
fn poll_read(
|
fn poll_read(
|
||||||
self: Pin<&mut Self>,
|
self: Pin<&mut Self>,
|
||||||
cx: &mut Context<'_>,
|
cx: &mut Context<'_>,
|
||||||
|
@ -63,7 +63,7 @@ impl<W: WebSocketWrite> AsyncRead for MuxStreamAsyncRead<W> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<W: WebSocketWrite> AsyncBufRead for MuxStreamAsyncRead<W> {
|
impl<W: TransportWrite> AsyncBufRead for MuxStreamAsyncRead<W> {
|
||||||
fn poll_fill_buf(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<io::Result<&[u8]>> {
|
fn poll_fill_buf(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<io::Result<&[u8]>> {
|
||||||
self.project().inner.poll_fill_buf(cx)
|
self.project().inner.poll_fill_buf(cx)
|
||||||
}
|
}
|
||||||
|
@ -73,7 +73,7 @@ impl<W: WebSocketWrite> AsyncBufRead for MuxStreamAsyncRead<W> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct MuxStreamAsyncWrite<W: WebSocketWrite> {
|
pub struct MuxStreamAsyncWrite<W: TransportWrite> {
|
||||||
inner: flume::r#async::SendSink<'static, WsEvent<W>>,
|
inner: flume::r#async::SendSink<'static, WsEvent<W>>,
|
||||||
write: LockedWebSocketWrite<W>,
|
write: LockedWebSocketWrite<W>,
|
||||||
info: Arc<StreamInfo>,
|
info: Arc<StreamInfo>,
|
||||||
|
@ -81,7 +81,7 @@ pub struct MuxStreamAsyncWrite<W: WebSocketWrite> {
|
||||||
oneshot: Option<oneshot::Receiver<Result<(), WispError>>>,
|
oneshot: Option<oneshot::Receiver<Result<(), WispError>>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<W: WebSocketWrite> MuxStreamAsyncWrite<W> {
|
impl<W: TransportWrite> MuxStreamAsyncWrite<W> {
|
||||||
pub(crate) fn new(inner: MuxStreamWrite<W>) -> Self {
|
pub(crate) fn new(inner: MuxStreamWrite<W>) -> Self {
|
||||||
Self {
|
Self {
|
||||||
inner: inner.inner,
|
inner: inner.inner,
|
||||||
|
@ -98,7 +98,7 @@ impl<W: WebSocketWrite> MuxStreamAsyncWrite<W> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<W: WebSocketWrite> AsyncWrite for MuxStreamAsyncWrite<W> {
|
impl<W: TransportWrite> AsyncWrite for MuxStreamAsyncWrite<W> {
|
||||||
fn poll_write(
|
fn poll_write(
|
||||||
mut self: Pin<&mut Self>,
|
mut self: Pin<&mut Self>,
|
||||||
cx: &mut Context<'_>,
|
cx: &mut Context<'_>,
|
||||||
|
@ -160,14 +160,14 @@ impl<W: WebSocketWrite> AsyncWrite for MuxStreamAsyncWrite<W> {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[pin_project]
|
#[pin_project]
|
||||||
pub struct MuxStreamAsyncRW<W: WebSocketWrite> {
|
pub struct MuxStreamAsyncRW<W: TransportWrite> {
|
||||||
#[pin]
|
#[pin]
|
||||||
read: MuxStreamAsyncRead<W>,
|
read: MuxStreamAsyncRead<W>,
|
||||||
#[pin]
|
#[pin]
|
||||||
write: MuxStreamAsyncWrite<W>,
|
write: MuxStreamAsyncWrite<W>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<W: WebSocketWrite> MuxStreamAsyncRW<W> {
|
impl<W: TransportWrite> MuxStreamAsyncRW<W> {
|
||||||
pub(crate) fn new(old: MuxStream<W>) -> Self {
|
pub(crate) fn new(old: MuxStream<W>) -> Self {
|
||||||
Self {
|
Self {
|
||||||
read: MuxStreamAsyncRead::new(old.read),
|
read: MuxStreamAsyncRead::new(old.read),
|
||||||
|
@ -185,7 +185,7 @@ impl<W: WebSocketWrite> MuxStreamAsyncRW<W> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<W: WebSocketWrite> AsyncRead for MuxStreamAsyncRW<W> {
|
impl<W: TransportWrite> AsyncRead for MuxStreamAsyncRW<W> {
|
||||||
fn poll_read(
|
fn poll_read(
|
||||||
self: Pin<&mut Self>,
|
self: Pin<&mut Self>,
|
||||||
cx: &mut Context<'_>,
|
cx: &mut Context<'_>,
|
||||||
|
@ -203,7 +203,7 @@ impl<W: WebSocketWrite> AsyncRead for MuxStreamAsyncRW<W> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<W: WebSocketWrite> AsyncBufRead for MuxStreamAsyncRW<W> {
|
impl<W: TransportWrite> AsyncBufRead for MuxStreamAsyncRW<W> {
|
||||||
fn poll_fill_buf(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<io::Result<&[u8]>> {
|
fn poll_fill_buf(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<io::Result<&[u8]>> {
|
||||||
self.project().read.poll_fill_buf(cx)
|
self.project().read.poll_fill_buf(cx)
|
||||||
}
|
}
|
||||||
|
@ -213,7 +213,7 @@ impl<W: WebSocketWrite> AsyncBufRead for MuxStreamAsyncRW<W> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<W: WebSocketWrite> AsyncWrite for MuxStreamAsyncRW<W> {
|
impl<W: TransportWrite> AsyncWrite for MuxStreamAsyncRW<W> {
|
||||||
fn poll_write(
|
fn poll_write(
|
||||||
self: Pin<&mut Self>,
|
self: Pin<&mut Self>,
|
||||||
cx: &mut Context<'_>,
|
cx: &mut Context<'_>,
|
||||||
|
|
|
@ -4,7 +4,7 @@ use futures::channel::oneshot;
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
packet::{ClosePacket, CloseReason},
|
packet::{ClosePacket, CloseReason},
|
||||||
ws::WebSocketWrite,
|
ws::TransportWrite,
|
||||||
WispError,
|
WispError,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -12,12 +12,12 @@ use super::{StreamInfo, WsEvent};
|
||||||
|
|
||||||
/// Close handle for a multiplexor stream.
|
/// Close handle for a multiplexor stream.
|
||||||
#[derive(Clone)]
|
#[derive(Clone)]
|
||||||
pub struct MuxStreamCloser<W: WebSocketWrite> {
|
pub struct MuxStreamCloser<W: TransportWrite> {
|
||||||
pub(crate) info: Arc<StreamInfo>,
|
pub(crate) info: Arc<StreamInfo>,
|
||||||
pub(crate) inner: flume::Sender<WsEvent<W>>,
|
pub(crate) inner: flume::Sender<WsEvent<W>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<W: WebSocketWrite + 'static> MuxStreamCloser<W> {
|
impl<W: TransportWrite + 'static> MuxStreamCloser<W> {
|
||||||
/// Close the stream. You will no longer be able to write or read after this has been called.
|
/// Close the stream. You will no longer be able to write or read after this has been called.
|
||||||
pub async fn close(&self, reason: CloseReason) -> Result<(), WispError> {
|
pub async fn close(&self, reason: CloseReason) -> Result<(), WispError> {
|
||||||
if self.inner.is_disconnected() {
|
if self.inner.is_disconnected() {
|
||||||
|
|
|
@ -9,7 +9,7 @@ use futures::{channel::oneshot, FutureExt, Sink, SinkExt, Stream, StreamExt};
|
||||||
use crate::{
|
use crate::{
|
||||||
mux::inner::{FlowControl, StreamInfo, WsEvent},
|
mux::inner::{FlowControl, StreamInfo, WsEvent},
|
||||||
packet::{ClosePacket, CloseReason, Packet},
|
packet::{ClosePacket, CloseReason, Packet},
|
||||||
ws::{Payload, WebSocketWrite},
|
ws::{Payload, TransportWrite},
|
||||||
LockedWebSocketWrite, WispError,
|
LockedWebSocketWrite, WispError,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -35,7 +35,7 @@ macro_rules! unlock {
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct MuxStreamRead<W: WebSocketWrite> {
|
pub struct MuxStreamRead<W: TransportWrite> {
|
||||||
inner: flume::r#async::RecvStream<'static, Payload>,
|
inner: flume::r#async::RecvStream<'static, Payload>,
|
||||||
write: LockedWebSocketWrite<W>,
|
write: LockedWebSocketWrite<W>,
|
||||||
info: Arc<StreamInfo>,
|
info: Arc<StreamInfo>,
|
||||||
|
@ -44,7 +44,7 @@ pub struct MuxStreamRead<W: WebSocketWrite> {
|
||||||
chunk: Option<Payload>,
|
chunk: Option<Payload>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<W: WebSocketWrite> MuxStreamRead<W> {
|
impl<W: TransportWrite> MuxStreamRead<W> {
|
||||||
fn new(
|
fn new(
|
||||||
inner: flume::Receiver<Payload>,
|
inner: flume::Receiver<Payload>,
|
||||||
write: LockedWebSocketWrite<W>,
|
write: LockedWebSocketWrite<W>,
|
||||||
|
@ -73,7 +73,7 @@ impl<W: WebSocketWrite> MuxStreamRead<W> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<W: WebSocketWrite> Stream for MuxStreamRead<W> {
|
impl<W: TransportWrite> Stream for MuxStreamRead<W> {
|
||||||
type Item = Result<Payload, WispError>;
|
type Item = Result<Payload, WispError>;
|
||||||
|
|
||||||
fn poll_next(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Option<Self::Item>> {
|
fn poll_next(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Option<Self::Item>> {
|
||||||
|
@ -124,7 +124,7 @@ impl<W: WebSocketWrite> Stream for MuxStreamRead<W> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct MuxStreamWrite<W: WebSocketWrite> {
|
pub struct MuxStreamWrite<W: TransportWrite> {
|
||||||
inner: flume::r#async::SendSink<'static, WsEvent<W>>,
|
inner: flume::r#async::SendSink<'static, WsEvent<W>>,
|
||||||
write: LockedWebSocketWrite<W>,
|
write: LockedWebSocketWrite<W>,
|
||||||
info: Arc<StreamInfo>,
|
info: Arc<StreamInfo>,
|
||||||
|
@ -134,7 +134,7 @@ pub struct MuxStreamWrite<W: WebSocketWrite> {
|
||||||
oneshot: Option<oneshot::Receiver<Result<(), WispError>>>,
|
oneshot: Option<oneshot::Receiver<Result<(), WispError>>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<W: WebSocketWrite> MuxStreamWrite<W> {
|
impl<W: TransportWrite> MuxStreamWrite<W> {
|
||||||
fn new(
|
fn new(
|
||||||
inner: flume::Sender<WsEvent<W>>,
|
inner: flume::Sender<WsEvent<W>>,
|
||||||
write: LockedWebSocketWrite<W>,
|
write: LockedWebSocketWrite<W>,
|
||||||
|
@ -203,7 +203,7 @@ impl<W: WebSocketWrite> MuxStreamWrite<W> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<W: WebSocketWrite> Sink<Payload> for MuxStreamWrite<W> {
|
impl<W: TransportWrite> Sink<Payload> for MuxStreamWrite<W> {
|
||||||
type Error = WispError;
|
type Error = WispError;
|
||||||
|
|
||||||
fn poll_ready(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Result<(), Self::Error>> {
|
fn poll_ready(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Result<(), Self::Error>> {
|
||||||
|
@ -277,12 +277,12 @@ impl<W: WebSocketWrite> Sink<Payload> for MuxStreamWrite<W> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct MuxStream<W: WebSocketWrite> {
|
pub struct MuxStream<W: TransportWrite> {
|
||||||
read: MuxStreamRead<W>,
|
read: MuxStreamRead<W>,
|
||||||
write: MuxStreamWrite<W>,
|
write: MuxStreamWrite<W>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<W: WebSocketWrite> MuxStream<W> {
|
impl<W: TransportWrite> MuxStream<W> {
|
||||||
pub(crate) fn new(
|
pub(crate) fn new(
|
||||||
rx: flume::Receiver<Payload>,
|
rx: flume::Receiver<Payload>,
|
||||||
tx: flume::Sender<WsEvent<W>>,
|
tx: flume::Sender<WsEvent<W>>,
|
||||||
|
@ -321,7 +321,7 @@ impl<W: WebSocketWrite> MuxStream<W> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<W: WebSocketWrite> Stream for MuxStream<W> {
|
impl<W: TransportWrite> Stream for MuxStream<W> {
|
||||||
type Item = <MuxStreamRead<W> as Stream>::Item;
|
type Item = <MuxStreamRead<W> as Stream>::Item;
|
||||||
|
|
||||||
fn poll_next(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Option<Self::Item>> {
|
fn poll_next(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Option<Self::Item>> {
|
||||||
|
@ -333,7 +333,7 @@ impl<W: WebSocketWrite> Stream for MuxStream<W> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<W: WebSocketWrite> Sink<Payload> for MuxStream<W> {
|
impl<W: TransportWrite> Sink<Payload> for MuxStream<W> {
|
||||||
type Error = <MuxStreamWrite<W> as Sink<Payload>>::Error;
|
type Error = <MuxStreamWrite<W> as Sink<Payload>>::Error;
|
||||||
|
|
||||||
fn poll_ready(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Result<(), Self::Error>> {
|
fn poll_ready(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Result<(), Self::Error>> {
|
||||||
|
|
|
@ -59,25 +59,25 @@ impl Deref for PayloadRef<'_> {
|
||||||
pub type Payload = Bytes;
|
pub type Payload = Bytes;
|
||||||
pub type PayloadMut = BytesMut;
|
pub type PayloadMut = BytesMut;
|
||||||
|
|
||||||
pub trait WebSocketRead:
|
pub trait TransportRead:
|
||||||
Stream<Item = Result<Payload, WispError>> + Send + Unpin + 'static
|
Stream<Item = Result<Payload, WispError>> + Send + Unpin + 'static
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
impl<S: Stream<Item = Result<Payload, WispError>> + Send + Unpin + 'static> WebSocketRead for S {}
|
impl<S: Stream<Item = Result<Payload, WispError>> + Send + Unpin + 'static> TransportRead for S {}
|
||||||
|
|
||||||
pub(crate) trait WebSocketReadExt: WebSocketRead {
|
pub(crate) trait TransportReadExt: TransportRead {
|
||||||
async fn next_erroring(&mut self) -> Result<Payload, WispError> {
|
async fn next_erroring(&mut self) -> Result<Payload, WispError> {
|
||||||
self.next().await.ok_or(WispError::WsImplSocketClosed)?
|
self.next().await.ok_or(WispError::WsImplSocketClosed)?
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
impl<S: WebSocketRead> WebSocketReadExt for S {}
|
impl<S: TransportRead> TransportReadExt for S {}
|
||||||
|
|
||||||
pub trait WebSocketWrite: Sink<Payload, Error = WispError> + Send + Unpin + 'static {}
|
pub trait TransportWrite: Sink<Payload, Error = WispError> + Send + Unpin + 'static {}
|
||||||
impl<S: Sink<Payload, Error = WispError> + Send + Unpin + 'static> WebSocketWrite for S {}
|
impl<S: Sink<Payload, Error = WispError> + Send + Unpin + 'static> TransportWrite for S {}
|
||||||
|
|
||||||
pub trait WebSocketExt: WebSocketRead + WebSocketWrite + Sized {
|
pub trait TransportExt: TransportRead + TransportWrite + Sized {
|
||||||
fn split_fast(self) -> (WebSocketSplitRead<Self>, WebSocketSplitWrite<Self>) {
|
fn split_fast(self) -> (WebSocketSplitRead<Self>, WebSocketSplitWrite<Self>) {
|
||||||
split::split(self)
|
split::split(self)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
impl<S: WebSocketRead + WebSocketWrite + Sized> WebSocketExt for S {}
|
impl<S: TransportRead + TransportWrite + Sized> TransportExt for S {}
|
||||||
|
|
|
@ -2,13 +2,13 @@ use std::sync::{Arc, Mutex, MutexGuard};
|
||||||
|
|
||||||
use futures::{Sink, SinkExt, Stream, StreamExt};
|
use futures::{Sink, SinkExt, Stream, StreamExt};
|
||||||
|
|
||||||
use super::{WebSocketRead, WebSocketWrite};
|
use super::{TransportRead, TransportWrite};
|
||||||
|
|
||||||
fn lock<T>(mutex: &Mutex<T>) -> MutexGuard<'_, T> {
|
fn lock<T>(mutex: &Mutex<T>) -> MutexGuard<'_, T> {
|
||||||
mutex.lock().expect("WebSocketSplit mutex was poisoned")
|
mutex.lock().expect("WebSocketSplit mutex was poisoned")
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn split<S: WebSocketRead + WebSocketWrite>(
|
pub(crate) fn split<S: TransportRead + TransportWrite>(
|
||||||
s: S,
|
s: S,
|
||||||
) -> (WebSocketSplitRead<S>, WebSocketSplitWrite<S>) {
|
) -> (WebSocketSplitRead<S>, WebSocketSplitWrite<S>) {
|
||||||
let inner = Arc::new(Mutex::new(s));
|
let inner = Arc::new(Mutex::new(s));
|
||||||
|
@ -19,9 +19,9 @@ pub(crate) fn split<S: WebSocketRead + WebSocketWrite>(
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct WebSocketSplitRead<S: WebSocketRead + WebSocketWrite>(Arc<Mutex<S>>);
|
pub struct WebSocketSplitRead<S: TransportRead + TransportWrite>(Arc<Mutex<S>>);
|
||||||
|
|
||||||
impl<S: WebSocketRead + WebSocketWrite> Stream for WebSocketSplitRead<S> {
|
impl<S: TransportRead + TransportWrite> Stream for WebSocketSplitRead<S> {
|
||||||
type Item = S::Item;
|
type Item = S::Item;
|
||||||
|
|
||||||
fn poll_next(
|
fn poll_next(
|
||||||
|
@ -32,9 +32,9 @@ impl<S: WebSocketRead + WebSocketWrite> Stream for WebSocketSplitRead<S> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct WebSocketSplitWrite<S: WebSocketRead + WebSocketWrite>(Arc<Mutex<S>>);
|
pub struct WebSocketSplitWrite<S: TransportRead + TransportWrite>(Arc<Mutex<S>>);
|
||||||
|
|
||||||
impl<S: WebSocketRead + WebSocketWrite + Sink<T>, T> Sink<T> for WebSocketSplitWrite<S> {
|
impl<S: TransportRead + TransportWrite + Sink<T>, T> Sink<T> for WebSocketSplitWrite<S> {
|
||||||
type Error = <S as Sink<T>>::Error;
|
type Error = <S as Sink<T>>::Error;
|
||||||
|
|
||||||
fn poll_ready(
|
fn poll_ready(
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue