Просмотр исходного кода

add missing stop() method for p2p

narodnik 4 лет назад
Родитель
Сommit
9a7c47f856
2 измененных файлов с 9 добавлено и 3 удалено
  1. 3 1
      bin/ircd/src/main.rs
  2. 6 2
      src/net/p2p.rs

+ 3 - 1
bin/ircd/src/main.rs

@@ -187,7 +187,7 @@ async fn realmain(settings: Args, executor: Arc<Executor<'_>>) -> Result<()> {
     let (p2p_send_channel, p2p_recv_channel) = async_channel::unbounded::<Privmsg>();
 
     let p2p = net::P2p::new(net_settings.into()).await;
-    let p2p = p2p.clone();
+    let p2p2 = p2p.clone();
 
     let registry = p2p.protocol_registry();
 
@@ -324,5 +324,7 @@ async fn realmain(settings: Args, executor: Arc<Executor<'_>>) -> Result<()> {
     print!("\r");
     info!("Caught termination signal, cleaning up and exiting...");
 
+    p2p2.stop().await;
+
     Ok(())
 }

+ 6 - 2
src/net/p2p.rs

@@ -58,7 +58,7 @@ pub struct P2p {
     channels: ConnectedChannels,
     channel_subscriber: SubscriberPtr<Result<ChannelPtr>>,
     // Used both internally and externally
-    stop_subscriber: SubscriberPtr<Error>,
+    stop_subscriber: SubscriberPtr<()>,
     hosts: HostsPtr,
     protocol_registry: ProtocolRegistry,
 
@@ -183,6 +183,10 @@ impl P2p {
         Ok(())
     }
 
+    pub async fn stop(&self) {
+        self.stop_subscriber.notify(()).await
+    }
+
     /// Broadcasts a message across all channels.
     pub async fn broadcast<M: Message + Clone>(&self, message: M) -> Result<()> {
         for channel in self.channels.lock().await.values() {
@@ -258,7 +262,7 @@ impl P2p {
     }
 
     /// Subscribe to a stop signal.
-    pub async fn subscribe_stop(&self) -> Subscription<Error> {
+    pub async fn subscribe_stop(&self) -> Subscription<()> {
         self.stop_subscriber.clone().subscribe().await
     }