Fix connection notification races. (#130)

Use a mutex on the connection state and one-shot all change notifications.

Fixes #127.
This commit is contained in:
Peter Johnson
2016-10-21 19:40:56 -07:00
committed by GitHub
parent 5c1b7ecd17
commit 86c43df8d1
3 changed files with 38 additions and 19 deletions

View File

@@ -193,10 +193,7 @@ std::vector<ConnectionInfo> DispatcherBase::GetConnections() const {
void DispatcherBase::NotifyConnections(
ConnectionListenerCallback callback) const {
std::lock_guard<std::mutex> lock(m_user_mutex);
for (auto& conn : m_connections) {
if (conn->state() != NetworkConnection::kActive) continue;
m_notifier.NotifyConnection(true, conn->info(), callback);
}
for (const auto& conn : m_connections) conn->NotifyIfActive(callback);
}
void DispatcherBase::DispatchThreadMain() {