persistence + proper disconnect

This commit is contained in:
2025-11-28 17:29:33 -05:00
parent 029d62cb53
commit 7557507f27
16 changed files with 413 additions and 67 deletions

View File

@@ -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,
}

View File

@@ -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;
}