iris update
This commit is contained in:
2
iris
2
iris
Submodule iris updated: 955e6b7588...c7b255be4f
@@ -121,7 +121,7 @@ async fn connect_the(handle: AppHandle, info: ConnectInfo) -> NetResult<()> {
|
||||
});
|
||||
|
||||
let recv = ServerRecv { handle };
|
||||
tokio::spawn(recv_uni(conn_, recv));
|
||||
tokio::spawn(recv_uni(conn_, recv.into()));
|
||||
|
||||
while let Some(msg) = ui_recv.recv().await {
|
||||
if send_uni(&conn, msg).await.is_err() {
|
||||
|
||||
@@ -93,7 +93,7 @@ async fn handle_connection(
|
||||
accepter: Arc<impl ConAccepter>,
|
||||
) -> std::io::Result<()> {
|
||||
let conn = conn.await?;
|
||||
let handler = accepter.accept(ClientSender { conn: conn.clone() }).await;
|
||||
let handler = Arc::new(accepter.accept(ClientSender { conn: conn.clone() }).await);
|
||||
let span = tracing::info_span!(
|
||||
"connection",
|
||||
remote = %conn.remote_address(),
|
||||
@@ -105,7 +105,8 @@ async fn handle_connection(
|
||||
.map_or_else(|| "<none>".into(), |x| String::from_utf8_lossy(&x).into_owned())
|
||||
);
|
||||
async {
|
||||
recv_uni(conn, handler).await;
|
||||
let res = recv_uni(conn, handler.clone()).await;
|
||||
handler.disconnect(res).await;
|
||||
}
|
||||
.instrument(span)
|
||||
.await;
|
||||
|
||||
@@ -7,6 +7,9 @@ use tracing::Instrument as _;
|
||||
|
||||
pub trait RecvHandler<M>: Send + Sync + 'static {
|
||||
fn msg(&self, msg: M) -> impl Future<Output = ()> + Send;
|
||||
fn disconnect(&self, reason: DisconnectReason) -> impl Future<Output = ()> + Send {
|
||||
async { drop(reason) }
|
||||
}
|
||||
}
|
||||
|
||||
pub type SendResult = Result<(), ()>;
|
||||
@@ -21,16 +24,27 @@ pub async fn send_uni<M: bincode::Encode>(conn: &Connection, msg: M) -> SendResu
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub async fn recv_uni<M: bincode::Decode<()>>(conn: Connection, handler: impl RecvHandler<M>) {
|
||||
let handler = Arc::new(handler);
|
||||
pub enum DisconnectReason {
|
||||
Closed,
|
||||
Timeout,
|
||||
Other(String),
|
||||
}
|
||||
|
||||
pub async fn recv_uni<M: bincode::Decode<()>>(
|
||||
conn: Connection,
|
||||
handler: Arc<impl RecvHandler<M>>,
|
||||
) -> DisconnectReason {
|
||||
loop {
|
||||
let mut recv = match conn.accept_uni().await {
|
||||
Err(quinn::ConnectionError::ApplicationClosed { .. }) => {
|
||||
return;
|
||||
return DisconnectReason::Closed;
|
||||
}
|
||||
Err(quinn::ConnectionError::TimedOut) => {
|
||||
return DisconnectReason::Timeout;
|
||||
}
|
||||
Err(e) => {
|
||||
eprintln!("connection error: {e}");
|
||||
return;
|
||||
return DisconnectReason::Other(e.to_string());
|
||||
}
|
||||
Ok(s) => s,
|
||||
};
|
||||
|
||||
@@ -2,7 +2,7 @@ use crate::{
|
||||
net::{
|
||||
ClientMsg, Msg, ServerMsg,
|
||||
server::{ClientSender, ConAccepter, listen},
|
||||
transfer::RecvHandler,
|
||||
transfer::{DisconnectReason, RecvHandler},
|
||||
},
|
||||
rsc::DataDir,
|
||||
};
|
||||
@@ -82,4 +82,11 @@ impl RecvHandler<ClientMsg> for ClientHandler {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
async fn disconnect(&self, reason: DisconnectReason) -> () {
|
||||
match reason {
|
||||
DisconnectReason::Closed | DisconnectReason::Timeout => (),
|
||||
DisconnectReason::Other(e) => println!("connection issue: {e}"),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user