diff options
| author | Gustav Sörnäs <gustav@sornas.net> | 2021-04-11 22:53:04 +0200 |
|---|---|---|
| committer | Gustav Sörnäs <gustav@sornas.net> | 2021-04-11 22:53:04 +0200 |
| commit | 6a0349287066261d7953b4220de5dd4df05049c0 (patch) | |
| tree | 2f042d6bd14f925141ddb8b2269f90004adca9f8 /mumd/src/network | |
| parent | 30264e1fa0e2602d29141409ecc8326bce1917aa (diff) | |
| download | mum-6a0349287066261d7953b4220de5dd4df05049c0.tar.gz | |
use tokio timeout
Diffstat (limited to 'mumd/src/network')
| -rw-r--r-- | mumd/src/network/udp.rs | 25 |
1 files changed, 12 insertions, 13 deletions
diff --git a/mumd/src/network/udp.rs b/mumd/src/network/udp.rs index d8cbc2a..2ca8f85 100644 --- a/mumd/src/network/udp.rs +++ b/mumd/src/network/udp.rs @@ -14,9 +14,9 @@ use std::collections::{hash_map::Entry, HashMap}; use std::convert::TryFrom; use std::net::{Ipv6Addr, SocketAddr}; use std::sync::{atomic::{AtomicU64, Ordering}, Arc, RwLock}; -use tokio::{join, net::UdpSocket, select}; +use tokio::{join, net::UdpSocket}; use tokio::sync::{mpsc, oneshot, watch, Mutex}; -use tokio::time::{interval, Duration}; +use tokio::time::{interval, timeout, Duration}; use tokio_util::udp::UdpFramed; use super::{run_until, VoiceStreamType}; @@ -246,20 +246,19 @@ pub async fn handle_pings( } tokio::spawn(async move { - let rx = rx.fuse(); - let timeout = async { - tokio::time::sleep(tokio::time::Duration::from_millis(1000)).await; - }; - handle(select! { - r = rx => match r { - Ok(r) => Some(r), + handle( + match timeout(Duration::from_secs(1), rx).await { + Ok(Ok(r)) => Some(r), + Ok(Err(_)) => { + warn!("Ping response sender for server {}, ping id {} dropped", socket_addr, id); + None + } Err(_) => { - warn!("Ping response sender dropped"); + debug!("Server {} timed out when sending ping id {}", socket_addr, id); None } - }, - _ = timeout => None, - }); + } + ); }); } }; |
