From 662491fc586ea18cf5ad3aeb7e3baf0674647f0e Mon Sep 17 00:00:00 2001 From: EAimTY Date: Sat, 30 Jul 2022 23:51:32 +0900 Subject: [PATCH] distributing listening jobs to separated tasks --- server/src/connection/mod.rs | 12 ++++++------ server/src/connection/udp.rs | 10 ++++------ server/src/server.rs | 4 +--- 3 files changed, 11 insertions(+), 15 deletions(-) diff --git a/server/src/connection/mod.rs b/server/src/connection/mod.rs index a4c8ff0..be02a1b 100644 --- a/server/src/connection/mod.rs +++ b/server/src/connection/mod.rs @@ -68,14 +68,14 @@ impl Connection { }; let res = tokio::select! { - res = Self::listen_uni_streams(conn.clone(), uni_streams) => res, - res = Self::listen_bi_streams(conn.clone(), bi_streams) => res, - res = Self::listen_datagrams(conn.clone(), datagrams) => res, - res = Self::listen_received_udp_packet(conn.clone(), recv_pkt_rx) => res, - Err(err) = Self::handle_authentication_timeout(conn, auth_timeout) => Err(err), + res = tokio::spawn(Self::listen_uni_streams(conn.clone(), uni_streams)) => res, + res = tokio::spawn(Self::listen_bi_streams(conn.clone(), bi_streams)) => res, + res = tokio::spawn(Self::listen_datagrams(conn.clone(), datagrams)) => res, + res = tokio::spawn(Self::listen_received_udp_packet(conn.clone(), recv_pkt_rx)) => res, + Err(err) = Self::handle_authentication_timeout(conn, auth_timeout) => Ok(Err(err)), }; - match res { + match res.unwrap() { Ok(()) => unreachable!(), Err(err) => { is_closed.set_closed(); diff --git a/server/src/connection/udp.rs b/server/src/connection/udp.rs index 3aa5a14..08f1673 100644 --- a/server/src/connection/udp.rs +++ b/server/src/connection/udp.rs @@ -136,12 +136,10 @@ impl UdpSession { let (send_pkt_tx, send_pkt_rx) = mpsc::channel(1); tokio::spawn(async move { - let res = tokio::select! { - res = tokio::spawn(Self::listen_send_packet(socket.clone(), send_pkt_rx)) => res, - res = tokio::spawn(Self::listen_receive_packet(socket, assoc_id, recv_pkt_tx, max_pkt_size)) => res, - }; - - match res.unwrap() { + match tokio::select! { + res = Self::listen_send_packet(socket.clone(), send_pkt_rx) => res, + res = Self::listen_receive_packet(socket, assoc_id, recv_pkt_tx, max_pkt_size) => res, + } { Ok(()) => (), Err(err) => log::warn!("[{src_addr}] [udp-session] [{assoc_id}] {err}"), } diff --git a/server/src/server.rs b/server/src/server.rs index fd54edb..1c110b2 100644 --- a/server/src/server.rs +++ b/server/src/server.rs @@ -51,11 +51,9 @@ impl Server { log::info!("Server started. Listening: {}", self.listen_addr); while let Some(conn) = self.incoming.next().await { - let token = self.token.clone(); - tokio::spawn(Connection::handle( conn, - token, + self.token.clone(), self.authentication_timeout, self.max_pkt_size, ));