From 21c80e45c2ef9823ccc9ae5ed0813095f19ada96 Mon Sep 17 00:00:00 2001 From: Stephen Birarda Date: Fri, 28 Aug 2015 09:42:52 -0700 Subject: [PATCH] guard connection addition by a mutex in Socket --- libraries/networking/src/udt/SendQueue.cpp | 7 +++++++ libraries/networking/src/udt/Socket.cpp | 6 ++++++ libraries/networking/src/udt/Socket.h | 2 ++ 3 files changed, 15 insertions(+) diff --git a/libraries/networking/src/udt/SendQueue.cpp b/libraries/networking/src/udt/SendQueue.cpp index d627937761..3ee4d48d1d 100644 --- a/libraries/networking/src/udt/SendQueue.cpp +++ b/libraries/networking/src/udt/SendQueue.cpp @@ -335,7 +335,11 @@ void SendQueue::run() { // then signal the queue is inactive and return so it can be cleaned up qDebug() << "SendQueue to" << _destination << "reached" << NUM_TIMEOUTS_BEFORE_INACTIVE << "timeouts and is" << "considered inactive. It is now being stopped."; + emit queueInactive(); + + _isRunning = false; + return; } else { // During our processing above we didn't send any packets @@ -366,6 +370,9 @@ void SendQueue::run() { // this queue is inactive - emit that signal and stop the while emit queueInactive(); + + _isRunning = false; + return; } } else { diff --git a/libraries/networking/src/udt/Socket.cpp b/libraries/networking/src/udt/Socket.cpp index 4b1f5f8a83..c9a681abfc 100644 --- a/libraries/networking/src/udt/Socket.cpp +++ b/libraries/networking/src/udt/Socket.cpp @@ -143,6 +143,8 @@ qint64 Socket::writeDatagram(const QByteArray& datagram, const HifiSockAddr& soc } Connection& Socket::findOrCreateConnection(const HifiSockAddr& sockAddr) { + QWriteLocker locker(&_connectionsMutex); + auto it = _connectionsHash.find(sockAddr); if (it == _connectionsHash.end()) { @@ -160,12 +162,16 @@ void Socket::clearConnections() { return; } + QWriteLocker locker(&_connectionsMutex); + // clear all of the current connections in the socket qDebug() << "Clearing all remaining connections in Socket."; _connectionsHash.clear(); } void Socket::cleanupConnection(HifiSockAddr sockAddr) { + QWriteLocker locker(&_connectionsMutex); + qCDebug(networking) << "Socket::cleanupConnection called for UDT connection to" << sockAddr; _connectionsHash.erase(sockAddr); } diff --git a/libraries/networking/src/udt/Socket.h b/libraries/networking/src/udt/Socket.h index f421b98288..fa6bf874a8 100644 --- a/libraries/networking/src/udt/Socket.h +++ b/libraries/networking/src/udt/Socket.h @@ -94,6 +94,8 @@ private: std::unordered_map _unreliableSequenceNumbers; std::unordered_map> _connectionsHash; + QReadWriteLock _connectionsMutex; // guards concurrent access to connections hashs + int _synInterval = 10; // 10ms QTimer _synTimer;