mirror of
https://github.com/overte-org/overte.git
synced 2025-04-21 18:44:00 +02:00
guard connection addition by a mutex in Socket
This commit is contained in:
parent
539108dd45
commit
21c80e45c2
3 changed files with 15 additions and 0 deletions
|
@ -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 {
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -94,6 +94,8 @@ private:
|
|||
std::unordered_map<HifiSockAddr, SequenceNumber> _unreliableSequenceNumbers;
|
||||
std::unordered_map<HifiSockAddr, std::unique_ptr<Connection>> _connectionsHash;
|
||||
|
||||
QReadWriteLock _connectionsMutex; // guards concurrent access to connections hashs
|
||||
|
||||
int _synInterval = 10; // 10ms
|
||||
QTimer _synTimer;
|
||||
|
||||
|
|
Loading…
Reference in a new issue