mirror of
https://github.com/MercuryWorkshop/epoxy-tls.git
synced 2025-05-17 16:10:01 -04:00
move the wisp logic into wisp lib
This commit is contained in:
parent
379e07d643
commit
2a5684192a
8 changed files with 314 additions and 198 deletions
|
@ -1,10 +1,14 @@
|
|||
use bytes::Bytes;
|
||||
use futures::lock::Mutex;
|
||||
use std::sync::Arc;
|
||||
|
||||
#[derive(Debug, PartialEq, Clone, Copy)]
|
||||
pub enum OpCode {
|
||||
Text,
|
||||
Binary,
|
||||
Close,
|
||||
Ping,
|
||||
Pong,
|
||||
}
|
||||
|
||||
pub struct Frame {
|
||||
|
@ -38,3 +42,37 @@ impl Frame {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub trait WebSocketRead {
|
||||
fn wisp_read_frame(
|
||||
&mut self,
|
||||
tx: &mut crate::ws::LockedWebSocketWrite<impl crate::ws::WebSocketWrite>,
|
||||
) -> impl std::future::Future<Output = Result<Frame, crate::WispError>>;
|
||||
}
|
||||
|
||||
pub trait WebSocketWrite {
|
||||
fn wisp_write_frame(
|
||||
&mut self,
|
||||
frame: Frame,
|
||||
) -> impl std::future::Future<Output = Result<(), crate::WispError>>;
|
||||
}
|
||||
|
||||
pub struct LockedWebSocketWrite<S>(Arc<Mutex<S>>)
|
||||
where
|
||||
S: WebSocketWrite;
|
||||
|
||||
impl<S: WebSocketWrite> LockedWebSocketWrite<S> {
|
||||
pub fn new(ws: S) -> Self {
|
||||
Self(Arc::new(Mutex::new(ws)))
|
||||
}
|
||||
|
||||
pub async fn write_frame(&self, frame: Frame) -> Result<(), crate::WispError> {
|
||||
self.0.lock().await.wisp_write_frame(frame).await
|
||||
}
|
||||
}
|
||||
|
||||
impl<S: WebSocketWrite> Clone for LockedWebSocketWrite<S> {
|
||||
fn clone(&self) -> Self {
|
||||
Self(self.0.clone())
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue