From f7799bcf8fc8b45e3ec6cea14e889ea61d77fa55 Mon Sep 17 00:00:00 2001 From: Stephen Birarda Date: Mon, 24 Aug 2015 17:00:56 -0700 Subject: [PATCH] add TODO for settings fail, cleanup --- assignment-client/src/audio/AudioMixer.cpp | 2 ++ libraries/networking/src/DomainHandler.cpp | 37 ++-------------------- libraries/networking/src/DomainHandler.h | 1 - libraries/networking/src/udt/SendQueue.cpp | 2 +- libraries/networking/src/udt/SendQueue.h | 2 +- 5 files changed, 7 insertions(+), 37 deletions(-) diff --git a/assignment-client/src/audio/AudioMixer.cpp b/assignment-client/src/audio/AudioMixer.cpp index c1d0cc2215..9fa0ac2faf 100644 --- a/assignment-client/src/audio/AudioMixer.cpp +++ b/assignment-client/src/audio/AudioMixer.cpp @@ -666,6 +666,8 @@ void AudioMixer::run() { connect(&domainHandler, &DomainHandler::settingsReceiveFail, &loop, &QEventLoop::quit); domainHandler.requestDomainSettings(); loop.exec(); + + domainHandler.requestDomainSettings(); if (domainHandler.getSettingsObject().isEmpty()) { qDebug() << "Failed to retreive settings object from domain-server. Bailing on assignment."; diff --git a/libraries/networking/src/DomainHandler.cpp b/libraries/networking/src/DomainHandler.cpp index 62b00a8c98..df024b361d 100644 --- a/libraries/networking/src/DomainHandler.cpp +++ b/libraries/networking/src/DomainHandler.cpp @@ -227,6 +227,9 @@ void DomainHandler::setIsConnected(bool isConnected) { } void DomainHandler::requestDomainSettings() { + // TODO: the nodes basically lock if they don't get a response - add a timeout to this so that they at least restart + // if they can't get settings + NodeType_t owningNodeType = DependencyManager::get()->getOwnerType(); if (owningNodeType == NodeType::Agent) { // for now the agent nodes don't need any settings - this allows local assignment-clients @@ -248,40 +251,6 @@ void DomainHandler::requestDomainSettings() { } } -const int MAX_SETTINGS_REQUEST_FAILED_ATTEMPTS = 5; - -void DomainHandler::settingsRequestFinished() { - QNetworkReply* settingsReply = reinterpret_cast(sender()); - - int replyCode = settingsReply->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt(); - - if (settingsReply->error() == QNetworkReply::NoError && replyCode != 301 && replyCode != 302) { - // parse the JSON to a QJsonObject and save it - _settingsObject = QJsonDocument::fromJson(settingsReply->readAll()).object(); - - qCDebug(networking) << "Received domain settings."; - emit settingsReceived(_settingsObject); - - // reset failed settings requests to 0, we got them - _failedSettingsRequests = 0; - } else { - // error grabbing the settings - in some cases this means we are stuck - // so we should retry until we get it - qCDebug(networking) << "Error getting domain settings -" << settingsReply->errorString() << "- retrying"; - - if (++_failedSettingsRequests >= MAX_SETTINGS_REQUEST_FAILED_ATTEMPTS) { - qCDebug(networking) << "Failed to retreive domain-server settings" << MAX_SETTINGS_REQUEST_FAILED_ATTEMPTS - << "times. Re-setting connection to domain."; - clearSettings(); - clearConnectionInfo(); - emit settingsReceiveFail(); - } else { - requestDomainSettings(); - } - } - settingsReply->deleteLater(); -} - void DomainHandler::processSettingsPacketList(QSharedPointer packetList) { auto data = packetList->getMessage(); diff --git a/libraries/networking/src/DomainHandler.h b/libraries/networking/src/DomainHandler.h index 349b3934eb..9dd4254c30 100644 --- a/libraries/networking/src/DomainHandler.h +++ b/libraries/networking/src/DomainHandler.h @@ -95,7 +95,6 @@ public slots: private slots: void completedHostnameLookup(const QHostInfo& hostInfo); void completedIceServerHostnameLookup(); - void settingsRequestFinished(); signals: void hostnameChanged(const QString& hostname); diff --git a/libraries/networking/src/udt/SendQueue.cpp b/libraries/networking/src/udt/SendQueue.cpp index fcede6fe03..5e0e8312f2 100644 --- a/libraries/networking/src/udt/SendQueue.cpp +++ b/libraries/networking/src/udt/SendQueue.cpp @@ -330,7 +330,7 @@ void SendQueue::run() { // both are empty - let's use a condition_variable_any to wait _emptyCondition.wait(doubleLock); - // we have the double lock again - it'll be unlock once it goes out of scope + // we have the double lock again - it'll be unlocked once it goes out of scope // skip to the next iteration continue; } diff --git a/libraries/networking/src/udt/SendQueue.h b/libraries/networking/src/udt/SendQueue.h index af53ef79ec..1987dee9dc 100644 --- a/libraries/networking/src/udt/SendQueue.h +++ b/libraries/networking/src/udt/SendQueue.h @@ -106,7 +106,7 @@ private: MessageNumber _currentMessageNumber { 0 }; SequenceNumber _currentSequenceNumber; // Last sequence number sent out - std::atomic _atomicCurrentSequenceNumber;// Atomic for last sequence number sent out + std::atomic _atomicCurrentSequenceNumber { 0 };// Atomic for last sequence number sent out std::atomic _packetSendPeriod; // Interval between two packet send event in microseconds, set from CC std::chrono::high_resolution_clock::time_point _lastSendTimestamp; // Record last time of packet departure