From 20d1244db4360f1f3cd789e18e3160beabc574dc Mon Sep 17 00:00:00 2001 From: Stephen Birarda Date: Fri, 28 Aug 2015 15:17:44 -0700 Subject: [PATCH] use a write lock for sync so it can be recursive --- libraries/networking/src/udt/Connection.cpp | 3 +++ libraries/networking/src/udt/Socket.cpp | 4 ++-- libraries/networking/src/udt/Socket.h | 2 +- 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/libraries/networking/src/udt/Connection.cpp b/libraries/networking/src/udt/Connection.cpp index 86b09ff56b..59c0618a83 100644 --- a/libraries/networking/src/udt/Connection.cpp +++ b/libraries/networking/src/udt/Connection.cpp @@ -146,6 +146,9 @@ void Connection::sync() { auto sinceLastReceive = duration_cast(high_resolution_clock::now() - _lastReceiveTime); if (sinceLastReceive.count() >= NUM_TIMEOUTS_FOR_EXPIRY * estimatedTimeout()) { + qDebug() << "Connection to" << _destination << "has not received any new data for" + << NUM_TIMEOUTS_FOR_EXPIRY << "timeouts. It is now considered inactive and will be cleaned up."; + // connection inactive - emit a signal so we will be cleaned up emit connectionInactive(_destination); diff --git a/libraries/networking/src/udt/Socket.cpp b/libraries/networking/src/udt/Socket.cpp index 94b6100dee..ee86560a9f 100644 --- a/libraries/networking/src/udt/Socket.cpp +++ b/libraries/networking/src/udt/Socket.cpp @@ -254,14 +254,14 @@ void Socket::connectToSendSignal(const HifiSockAddr& destinationAddr, QObject* r void Socket::rateControlSync() { - QReadLocker readLocker(&_connectionsMutex); + QWriteLocker writeLocker(&_connectionsMutex); // enumerate our list of connections and ask each of them to send off periodic ACK packet for rate control for (auto& connection : _connectionsHash) { connection.second->sync(); } - readLocker.unlock(); + writeLocker.unlock(); if (_synTimer.interval() != _synInterval) { // if the _synTimer interval doesn't match the current _synInterval (changes when the CC factory is changed) diff --git a/libraries/networking/src/udt/Socket.h b/libraries/networking/src/udt/Socket.h index fa6bf874a8..6e639d842d 100644 --- a/libraries/networking/src/udt/Socket.h +++ b/libraries/networking/src/udt/Socket.h @@ -94,7 +94,7 @@ private: std::unordered_map _unreliableSequenceNumbers; std::unordered_map> _connectionsHash; - QReadWriteLock _connectionsMutex; // guards concurrent access to connections hashs + QReadWriteLock _connectionsMutex { QReadWriteLock::Recursive }; // guards concurrent access to connections hashs int _synInterval = 10; // 10ms QTimer _synTimer;