From bf63f32a5e82eb0a69aca84616993be89831ebee Mon Sep 17 00:00:00 2001 From: chriseth Date: Fri, 7 Aug 2015 22:15:33 +0200 Subject: [PATCH] Cleanup m_sessions. --- libp2p/Host.cpp | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/libp2p/Host.cpp b/libp2p/Host.cpp index 4bd5a126c..b3b3d5bf3 100644 --- a/libp2p/Host.cpp +++ b/libp2p/Host.cpp @@ -742,9 +742,14 @@ void Host::keepAlivePeers() return; RecursiveGuard l(x_sessions); - for (auto p: m_sessions) - if (auto pp = p.second.lock()) - pp->ping(); + for (auto it = m_sessions.begin(); it != m_sessions.end();) + if (auto p = it->second.lock()) + { + p->ping(); + ++it; + } + else + it = m_sessions.erase(it); m_lastPing = chrono::steady_clock::now(); }