From e8e592d1ace5413a1e7d8b59b9467c78d8d68ea9 Mon Sep 17 00:00:00 2001
From: Florent Le Coz <louiz@louiz.org>
Date: Fri, 27 Dec 2013 12:01:26 +0100
Subject: Remove disconnected IrcClients

---
 src/bridge/bridge.cpp | 13 +++++++++++++
 src/bridge/bridge.hpp |  5 ++++-
 2 files changed, 17 insertions(+), 1 deletion(-)

(limited to 'src/bridge')

diff --git a/src/bridge/bridge.cpp b/src/bridge/bridge.cpp
index 3a755a3..c93d710 100644
--- a/src/bridge/bridge.cpp
+++ b/src/bridge/bridge.cpp
@@ -29,6 +29,19 @@ void Bridge::shutdown()
   }
 }
 
+void Bridge::clean()
+{
+  auto it = this->irc_clients.begin();
+  while (it != this->irc_clients.end())
+  {
+    IrcClient* client = it->second.get();
+    if (!client->is_connected())
+      it = this->irc_clients.erase(it);
+    else
+      ++it;
+  }
+}
+
 Xmpp::body Bridge::make_xmpp_body(const std::string& str)
 {
   std::string res;
diff --git a/src/bridge/bridge.hpp b/src/bridge/bridge.hpp
index 7a36b59..1e1149b 100644
--- a/src/bridge/bridge.hpp
+++ b/src/bridge/bridge.hpp
@@ -28,7 +28,10 @@ public:
    * QUIT all connected IRC servers.
    */
   void shutdown();
-
+  /**
+   * Remove all inactive IrcClients
+   */
+  void clean();
   static Xmpp::body make_xmpp_body(const std::string& str);
   /***
    **
-- 
cgit v1.2.3