]> git.lizzy.rs Git - mt_rudp.git/commitdiff
DropBomb to ensure close() is called
authorLizzy Fleckenstein <eliasfleckenstein@web.de>
Wed, 15 Feb 2023 21:18:49 +0000 (22:18 +0100)
committerLizzy Fleckenstein <eliasfleckenstein@web.de>
Wed, 15 Feb 2023 21:18:49 +0000 (22:18 +0100)
src/common.rs
src/share.rs

index 4e32edcce127c15236e7b8c6c63f24faa6d172c6..b888ed769c148c9754f6340ffc932bb1799a93a4 100644 (file)
@@ -81,6 +81,7 @@ macro_rules! impl_share {
             }
 
             pub async fn close(self) {
+                self.share.bomb.lock().await.defuse();
                 self.share.close_tx.send(true).ok();
 
                 let mut tasks = self.share.tasks.lock().await;
index ad63290c9efc96da75f17eab8129e9d022dbb51d..a2afc4c2f9c3bd40ff7c4e91aee5224e61fcbb21 100644 (file)
@@ -1,4 +1,5 @@
 use super::*;
+use drop_bomb::DropBomb;
 use std::{borrow::Cow, collections::HashMap, io, sync::Arc, time::Duration};
 use tokio::{
     sync::{mpsc, watch, Mutex, RwLock},
@@ -26,6 +27,7 @@ pub(crate) struct RudpShare<S: UdpSender> {
     pub(crate) udp_tx: S,
     pub(crate) close_tx: watch::Sender<bool>,
     pub(crate) tasks: Mutex<JoinSet<()>>,
+    pub(crate) bomb: Mutex<DropBomb>,
 }
 
 pub async fn new<S: UdpSender, R: UdpReceiver>(
@@ -51,6 +53,7 @@ pub async fn new<S: UdpSender, R: UdpReceiver>(
             })
             .collect(),
         tasks: Mutex::new(JoinSet::new()),
+        bomb: Mutex::new(DropBomb::new("rudp connection must be explicitly closed")),
     });
 
     let mut tasks = share.tasks.lock().await;