mirror of
https://github.com/overte-org/overte.git
synced 2025-04-25 20:16:16 +02:00
remove timer forced timeouts in ARR, occasionally ouput DL progress
This commit is contained in:
parent
826c2f1a9f
commit
a0c27e2130
3 changed files with 26 additions and 58 deletions
|
@ -11,10 +11,12 @@
|
||||||
|
|
||||||
#include "AssetResourceRequest.h"
|
#include "AssetResourceRequest.h"
|
||||||
|
|
||||||
|
#include <QtCore/qloggingcategory.h>
|
||||||
|
|
||||||
#include "AssetClient.h"
|
#include "AssetClient.h"
|
||||||
#include "AssetUtils.h"
|
#include "AssetUtils.h"
|
||||||
#include "MappingRequest.h"
|
#include "MappingRequest.h"
|
||||||
#include <QtCore/qloggingcategory.h>
|
#include "NetworkLogging.h"
|
||||||
|
|
||||||
AssetResourceRequest::~AssetResourceRequest() {
|
AssetResourceRequest::~AssetResourceRequest() {
|
||||||
if (_assetMappingRequest) {
|
if (_assetMappingRequest) {
|
||||||
|
@ -24,10 +26,6 @@ AssetResourceRequest::~AssetResourceRequest() {
|
||||||
if (_assetRequest) {
|
if (_assetRequest) {
|
||||||
_assetRequest->deleteLater();
|
_assetRequest->deleteLater();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (_sendTimer) {
|
|
||||||
cleanupTimer();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool AssetResourceRequest::urlIsAssetHash() const {
|
bool AssetResourceRequest::urlIsAssetHash() const {
|
||||||
|
@ -37,24 +35,6 @@ bool AssetResourceRequest::urlIsAssetHash() const {
|
||||||
return hashRegex.exactMatch(_url.toString());
|
return hashRegex.exactMatch(_url.toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
void AssetResourceRequest::setupTimer() {
|
|
||||||
Q_ASSERT(!_sendTimer);
|
|
||||||
static const int TIMEOUT_MS = 15000;
|
|
||||||
|
|
||||||
_sendTimer = new QTimer(this);
|
|
||||||
connect(_sendTimer, &QTimer::timeout, this, &AssetResourceRequest::onTimeout);
|
|
||||||
|
|
||||||
_sendTimer->setSingleShot(true);
|
|
||||||
_sendTimer->start(TIMEOUT_MS);
|
|
||||||
}
|
|
||||||
|
|
||||||
void AssetResourceRequest::cleanupTimer() {
|
|
||||||
Q_ASSERT(_sendTimer);
|
|
||||||
disconnect(_sendTimer, 0, this, 0);
|
|
||||||
_sendTimer->deleteLater();
|
|
||||||
_sendTimer = nullptr;
|
|
||||||
}
|
|
||||||
|
|
||||||
void AssetResourceRequest::doSend() {
|
void AssetResourceRequest::doSend() {
|
||||||
// We'll either have a hash or an ATP path to a file (that maps to a hash)
|
// We'll either have a hash or an ATP path to a file (that maps to a hash)
|
||||||
if (urlIsAssetHash()) {
|
if (urlIsAssetHash()) {
|
||||||
|
@ -81,8 +61,6 @@ void AssetResourceRequest::requestMappingForPath(const AssetPath& path) {
|
||||||
Q_ASSERT(_state == InProgress);
|
Q_ASSERT(_state == InProgress);
|
||||||
Q_ASSERT(request == _assetMappingRequest);
|
Q_ASSERT(request == _assetMappingRequest);
|
||||||
|
|
||||||
cleanupTimer();
|
|
||||||
|
|
||||||
switch (request->getError()) {
|
switch (request->getError()) {
|
||||||
case MappingRequest::NoError:
|
case MappingRequest::NoError:
|
||||||
// we have no error, we should have a resulting hash - use that to send of a request for that asset
|
// we have no error, we should have a resulting hash - use that to send of a request for that asset
|
||||||
|
@ -118,7 +96,6 @@ void AssetResourceRequest::requestMappingForPath(const AssetPath& path) {
|
||||||
_assetMappingRequest = nullptr;
|
_assetMappingRequest = nullptr;
|
||||||
});
|
});
|
||||||
|
|
||||||
setupTimer();
|
|
||||||
_assetMappingRequest->start();
|
_assetMappingRequest->start();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -133,8 +110,6 @@ void AssetResourceRequest::requestHash(const AssetHash& hash) {
|
||||||
Q_ASSERT(_state == InProgress);
|
Q_ASSERT(_state == InProgress);
|
||||||
Q_ASSERT(req == _assetRequest);
|
Q_ASSERT(req == _assetRequest);
|
||||||
Q_ASSERT(req->getState() == AssetRequest::Finished);
|
Q_ASSERT(req->getState() == AssetRequest::Finished);
|
||||||
|
|
||||||
cleanupTimer();
|
|
||||||
|
|
||||||
switch (req->getError()) {
|
switch (req->getError()) {
|
||||||
case AssetRequest::Error::NoError:
|
case AssetRequest::Error::NoError:
|
||||||
|
@ -162,35 +137,30 @@ void AssetResourceRequest::requestHash(const AssetHash& hash) {
|
||||||
_assetRequest = nullptr;
|
_assetRequest = nullptr;
|
||||||
});
|
});
|
||||||
|
|
||||||
setupTimer();
|
|
||||||
_assetRequest->start();
|
_assetRequest->start();
|
||||||
}
|
}
|
||||||
|
|
||||||
void AssetResourceRequest::onDownloadProgress(qint64 bytesReceived, qint64 bytesTotal) {
|
void AssetResourceRequest::onDownloadProgress(qint64 bytesReceived, qint64 bytesTotal) {
|
||||||
Q_ASSERT(_state == InProgress);
|
Q_ASSERT(_state == InProgress);
|
||||||
|
|
||||||
// We've received data, so reset the timer
|
|
||||||
_sendTimer->start();
|
|
||||||
|
|
||||||
emit progress(bytesReceived, bytesTotal);
|
emit progress(bytesReceived, bytesTotal);
|
||||||
|
|
||||||
|
static const int DOWNLOAD_PROGRESS_LOG_INTERVAL_SECONDS = 5;
|
||||||
|
auto now = p_high_resolution_clock::now();
|
||||||
|
|
||||||
|
// if we haven't received the full asset check if it is time to output progress to log
|
||||||
|
// we do so every X seconds to assist with ATP download tracking
|
||||||
|
|
||||||
|
if (bytesReceived != bytesTotal
|
||||||
|
&& now - _lastProgressDebug > std::chrono::seconds(DOWNLOAD_PROGRESS_LOG_INTERVAL_SECONDS)) {
|
||||||
|
|
||||||
|
int percentage = roundf((float) bytesReceived / (float) bytesTotal * 100.0f);
|
||||||
|
|
||||||
|
qCDebug(networking).nospace() << "Progress for " << _url.path() << " - "
|
||||||
|
<< bytesReceived << " bytes of " << bytesTotal << " - " << percentage << "%";
|
||||||
|
|
||||||
|
_lastProgressDebug = now;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void AssetResourceRequest::onTimeout() {
|
|
||||||
if (_state == InProgress) {
|
|
||||||
qWarning() << "Asset request timed out: " << _url;
|
|
||||||
if (_assetRequest) {
|
|
||||||
disconnect(_assetRequest, 0, this, 0);
|
|
||||||
_assetRequest->deleteLater();
|
|
||||||
_assetRequest = nullptr;
|
|
||||||
}
|
|
||||||
if (_assetMappingRequest) {
|
|
||||||
disconnect(_assetMappingRequest, 0, this, 0);
|
|
||||||
_assetMappingRequest->deleteLater();
|
|
||||||
_assetMappingRequest = nullptr;
|
|
||||||
}
|
|
||||||
_result = Timeout;
|
|
||||||
_state = Finished;
|
|
||||||
emit finished();
|
|
||||||
}
|
|
||||||
cleanupTimer();
|
|
||||||
}
|
|
||||||
|
|
|
@ -14,6 +14,8 @@
|
||||||
|
|
||||||
#include <QUrl>
|
#include <QUrl>
|
||||||
|
|
||||||
|
#include <PortableHighResolutionClock.h>
|
||||||
|
|
||||||
#include "AssetRequest.h"
|
#include "AssetRequest.h"
|
||||||
#include "ResourceRequest.h"
|
#include "ResourceRequest.h"
|
||||||
|
|
||||||
|
@ -28,21 +30,17 @@ protected:
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
void onDownloadProgress(qint64 bytesReceived, qint64 bytesTotal);
|
void onDownloadProgress(qint64 bytesReceived, qint64 bytesTotal);
|
||||||
void onTimeout();
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void setupTimer();
|
|
||||||
void cleanupTimer();
|
|
||||||
|
|
||||||
bool urlIsAssetHash() const;
|
bool urlIsAssetHash() const;
|
||||||
|
|
||||||
void requestMappingForPath(const AssetPath& path);
|
void requestMappingForPath(const AssetPath& path);
|
||||||
void requestHash(const AssetHash& hash);
|
void requestHash(const AssetHash& hash);
|
||||||
|
|
||||||
QTimer* _sendTimer { nullptr };
|
|
||||||
|
|
||||||
GetMappingRequest* _assetMappingRequest { nullptr };
|
GetMappingRequest* _assetMappingRequest { nullptr };
|
||||||
AssetRequest* _assetRequest { nullptr };
|
AssetRequest* _assetRequest { nullptr };
|
||||||
|
|
||||||
|
p_high_resolution_clock::time_point _lastProgressDebug;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -54,7 +54,7 @@ void ReceivedMessage::appendPacket(NLPacket& packet) {
|
||||||
"We should not be appending to a complete message");
|
"We should not be appending to a complete message");
|
||||||
|
|
||||||
// Limit progress signal to every X packets
|
// Limit progress signal to every X packets
|
||||||
const int EMIT_PROGRESS_EVERY_X_PACKETS = 5;
|
const int EMIT_PROGRESS_EVERY_X_PACKETS = 50;
|
||||||
|
|
||||||
++_numPackets;
|
++_numPackets;
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue