From 26a7d2489d0cc5b04bfee46cdec0366af1c3cea4 Mon Sep 17 00:00:00 2001 From: EAimTY Date: Sun, 31 Jul 2022 00:36:04 +0900 Subject: [PATCH] reverting changes on server since `0.8.1` --- server/src/connection/mod.rs | 12 ++++++------ server/src/connection/udp.rs | 14 +++----------- 2 files changed, 9 insertions(+), 17 deletions(-) diff --git a/server/src/connection/mod.rs b/server/src/connection/mod.rs index be02a1b..a4c8ff0 100644 --- a/server/src/connection/mod.rs +++ b/server/src/connection/mod.rs @@ -68,14 +68,14 @@ impl Connection { }; let res = tokio::select! { - 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)), + 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), }; - match res.unwrap() { + match res { Ok(()) => unreachable!(), Err(err) => { is_closed.set_closed(); diff --git a/server/src/connection/udp.rs b/server/src/connection/udp.rs index 08f1673..d89fb24 100644 --- a/server/src/connection/udp.rs +++ b/server/src/connection/udp.rs @@ -1,11 +1,11 @@ use bytes::Bytes; use crossbeam_utils::atomic::AtomicCell; use parking_lot::Mutex; -use socket2::{Domain, Protocol, SockAddr, Socket, Type}; + use std::{ collections::HashMap, io::Result, - net::{Ipv6Addr, SocketAddr, UdpSocket as StdUdpSocket}, + net::{Ipv4Addr, SocketAddr}, sync::Arc, }; use tokio::{ @@ -124,15 +124,7 @@ impl UdpSession { src_addr: SocketAddr, max_pkt_size: usize, ) -> Result { - let socket = Arc::new({ - let socket = Socket::new(Domain::IPV6, Type::DGRAM, Some(Protocol::UDP))?; - socket.set_only_v6(false)?; - socket.bind(&SockAddr::from(SocketAddr::from(( - Ipv6Addr::UNSPECIFIED, - 0, - ))))?; - UdpSocket::from_std(StdUdpSocket::from(socket))? - }); + let socket = Arc::new(UdpSocket::bind(SocketAddr::from((Ipv4Addr::UNSPECIFIED, 0))).await?); let (send_pkt_tx, send_pkt_rx) = mpsc::channel(1); tokio::spawn(async move {