From 9cb6ccaa46f591e5fc59753e4eb226039083cf2a Mon Sep 17 00:00:00 2001 From: Stephen Birarda Date: Tue, 26 May 2015 16:49:18 -0700 Subject: [PATCH] thread safe timing of domain connection --- interface/src/ui/DomainConnectionDialog.cpp | 4 +++- libraries/networking/src/NodeList.cpp | 10 +++++++--- libraries/networking/src/NodeList.h | 5 ++++- 3 files changed, 14 insertions(+), 5 deletions(-) diff --git a/interface/src/ui/DomainConnectionDialog.cpp b/interface/src/ui/DomainConnectionDialog.cpp index 0e82b2ed93..f5fdc530d5 100644 --- a/interface/src/ui/DomainConnectionDialog.cpp +++ b/interface/src/ui/DomainConnectionDialog.cpp @@ -69,11 +69,12 @@ DomainConnectionDialog::DomainConnectionDialog(QWidget* parent) : } } + // setup a horizontal box layout QHBoxLayout* hBoxLayout = new QHBoxLayout; hBoxLayout->addWidget(timeTable); hBoxLayout->setSizeConstraint(QLayout::SetMinimumSize); - timeTable->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred); + // resize the table columns timeTable->resizeColumnsToContents(); // figure out the size of the table so we can size the dialog @@ -87,6 +88,7 @@ DomainConnectionDialog::DomainConnectionDialog(QWidget* parent) : tableHeight += timeTable->rowHeight(i); } + // set the minimum size of the table to whatever we got timeTable->setMinimumSize(tableWidth, tableHeight); setLayout(hBoxLayout); diff --git a/libraries/networking/src/NodeList.cpp b/libraries/networking/src/NodeList.cpp index 4bfedfd555..f9189e47d7 100644 --- a/libraries/networking/src/NodeList.cpp +++ b/libraries/networking/src/NodeList.cpp @@ -270,9 +270,6 @@ void NodeList::reset() { if (_dtlsSocket) { disconnect(_dtlsSocket, 0, this, 0); } - - // reset the connection times - _lastConnectionTimes.clear(); } void NodeList::addNodeTypeToInterestSet(NodeType_t nodeTypeToAdd) { @@ -673,6 +670,13 @@ void NodeList::flagTimeForConnectionStep(NodeList::ConnectionStep connectionStep } void NodeList::flagTimeForConnectionStep(NodeList::ConnectionStep connectionStep, quint64 timestamp) { + QWriteLocker writeLock(&_connectionTimeLock); + + if (connectionStep == NodeList::ConnectionStep::LookupAddress) { + // we clear the current times if the user just fired off a lookup + _lastConnectionTimes.clear(); + } + // we only add a timestamp on the first call for each NodeList::ConnectionStep if (!_lastConnectionTimes.contains(connectionStep)) { _lastConnectionTimes[connectionStep] = timestamp; diff --git a/libraries/networking/src/NodeList.h b/libraries/networking/src/NodeList.h index 8d40e252e5..acdfe535f1 100644 --- a/libraries/networking/src/NodeList.h +++ b/libraries/networking/src/NodeList.h @@ -84,8 +84,10 @@ public: int processDomainServerList(const QByteArray& packet); - const QMap getLastConnectionTimes() const { return _lastConnectionTimes; } + const QMap getLastConnectionTimes() const + { QReadLocker readLock(&_connectionTimeLock); return _lastConnectionTimes; } void flagTimeForConnectionStep(NodeList::ConnectionStep connectionStep); + void resetConnectionTimes() { QWriteLocker writeLock(&_connectionTimeLock); _lastConnectionTimes.clear(); } void setAssignmentServerSocket(const HifiSockAddr& serverSocket) { _assignmentServerSocket = serverSocket; } void sendAssignment(Assignment& assignment); @@ -128,6 +130,7 @@ private: bool _hasCompletedInitialSTUNFailure; unsigned int _stunRequestsSinceSuccess; + mutable QReadWriteLock _connectionTimeLock { }; QMap _lastConnectionTimes; friend class Application;