persistence + proper disconnect
This commit is contained in:
@@ -11,20 +11,20 @@ pub const BINCODE_CONFIG: Configuration = bincode::config::standard();
|
||||
|
||||
#[derive(Debug, bincode::Encode, bincode::Decode)]
|
||||
pub enum ClientMsg {
|
||||
SendMsg(Msg),
|
||||
SendMsg(NetMsg),
|
||||
RequestMsgs,
|
||||
}
|
||||
|
||||
#[derive(Debug, bincode::Encode, bincode::Decode)]
|
||||
pub enum ServerMsg {
|
||||
SendMsg(Msg),
|
||||
LoadMsgs(Vec<Msg>),
|
||||
SendMsg(NetMsg),
|
||||
LoadMsgs(Vec<NetMsg>),
|
||||
}
|
||||
|
||||
pub type ServerResp<T> = Result<T, String>;
|
||||
|
||||
#[derive(Debug, Clone, bincode::Encode, bincode::Decode)]
|
||||
pub struct Msg {
|
||||
pub struct NetMsg {
|
||||
pub content: String,
|
||||
pub user: String,
|
||||
}
|
||||
|
||||
@@ -6,9 +6,13 @@ use tokio::io::{AsyncReadExt as _, AsyncWriteExt};
|
||||
use tracing::Instrument as _;
|
||||
|
||||
pub trait RecvHandler<M>: Send + Sync + 'static {
|
||||
fn connect(&self) -> impl Future<Output = ()> + Send {
|
||||
async {}
|
||||
}
|
||||
fn msg(&self, msg: M) -> impl Future<Output = ()> + Send;
|
||||
#[allow(unused)]
|
||||
fn disconnect(&self, reason: DisconnectReason) -> impl Future<Output = ()> + Send {
|
||||
async { drop(reason) }
|
||||
async {}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -39,6 +43,7 @@ pub async fn recv_uni<M: bincode::Decode<()>>(
|
||||
Err(quinn::ConnectionError::ApplicationClosed { .. }) => {
|
||||
return DisconnectReason::Closed;
|
||||
}
|
||||
Err(quinn::ConnectionError::LocallyClosed) => return DisconnectReason::Closed,
|
||||
Err(quinn::ConnectionError::TimedOut) => {
|
||||
return DisconnectReason::Timeout;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user