mirror of
https://github.com/HifiExperiments/overte.git
synced 2025-08-09 07:59:10 +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
|
// 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"
|
qDebug() << "SendQueue to" << _destination << "reached" << NUM_TIMEOUTS_BEFORE_INACTIVE << "timeouts and is"
|
||||||
<< "considered inactive. It is now being stopped.";
|
<< "considered inactive. It is now being stopped.";
|
||||||
|
|
||||||
emit queueInactive();
|
emit queueInactive();
|
||||||
|
|
||||||
|
_isRunning = false;
|
||||||
|
|
||||||
return;
|
return;
|
||||||
} else {
|
} else {
|
||||||
// During our processing above we didn't send any packets
|
// 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
|
// this queue is inactive - emit that signal and stop the while
|
||||||
emit queueInactive();
|
emit queueInactive();
|
||||||
|
|
||||||
|
_isRunning = false;
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -143,6 +143,8 @@ qint64 Socket::writeDatagram(const QByteArray& datagram, const HifiSockAddr& soc
|
||||||
}
|
}
|
||||||
|
|
||||||
Connection& Socket::findOrCreateConnection(const HifiSockAddr& sockAddr) {
|
Connection& Socket::findOrCreateConnection(const HifiSockAddr& sockAddr) {
|
||||||
|
QWriteLocker locker(&_connectionsMutex);
|
||||||
|
|
||||||
auto it = _connectionsHash.find(sockAddr);
|
auto it = _connectionsHash.find(sockAddr);
|
||||||
|
|
||||||
if (it == _connectionsHash.end()) {
|
if (it == _connectionsHash.end()) {
|
||||||
|
@ -160,12 +162,16 @@ void Socket::clearConnections() {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QWriteLocker locker(&_connectionsMutex);
|
||||||
|
|
||||||
// clear all of the current connections in the socket
|
// clear all of the current connections in the socket
|
||||||
qDebug() << "Clearing all remaining connections in Socket.";
|
qDebug() << "Clearing all remaining connections in Socket.";
|
||||||
_connectionsHash.clear();
|
_connectionsHash.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
void Socket::cleanupConnection(HifiSockAddr sockAddr) {
|
void Socket::cleanupConnection(HifiSockAddr sockAddr) {
|
||||||
|
QWriteLocker locker(&_connectionsMutex);
|
||||||
|
|
||||||
qCDebug(networking) << "Socket::cleanupConnection called for UDT connection to" << sockAddr;
|
qCDebug(networking) << "Socket::cleanupConnection called for UDT connection to" << sockAddr;
|
||||||
_connectionsHash.erase(sockAddr);
|
_connectionsHash.erase(sockAddr);
|
||||||
}
|
}
|
||||||
|
|
|
@ -94,6 +94,8 @@ private:
|
||||||
std::unordered_map<HifiSockAddr, SequenceNumber> _unreliableSequenceNumbers;
|
std::unordered_map<HifiSockAddr, SequenceNumber> _unreliableSequenceNumbers;
|
||||||
std::unordered_map<HifiSockAddr, std::unique_ptr<Connection>> _connectionsHash;
|
std::unordered_map<HifiSockAddr, std::unique_ptr<Connection>> _connectionsHash;
|
||||||
|
|
||||||
|
QReadWriteLock _connectionsMutex; // guards concurrent access to connections hashs
|
||||||
|
|
||||||
int _synInterval = 10; // 10ms
|
int _synInterval = 10; // 10ms
|
||||||
QTimer _synTimer;
|
QTimer _synTimer;
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue