Propagator: Fix bw limiting bug, be less verbose in logging

This commit is contained in:
Markus Goetz 2014-10-07 17:42:50 +02:00
parent 89971925ca
commit bf18ecae13
2 changed files with 18 additions and 19 deletions

View file

@ -153,13 +153,13 @@ void BandwidthManager::unregisterDownloadJob(QObject* o)
void BandwidthManager::relativeUploadMeasuringTimerExpired() void BandwidthManager::relativeUploadMeasuringTimerExpired()
{ {
if (!usingRelativeUploadLimit()) { if (!usingRelativeUploadLimit() || _relativeUploadDeviceList.count() == 0) {
// Not in this limiting mode, just wait 1 sec to continue the cycle // Not in this limiting mode, just wait 1 sec to continue the cycle
_relativeUploadDelayTimer.setInterval(1000); _relativeUploadDelayTimer.setInterval(1000);
_relativeUploadDelayTimer.start(); _relativeUploadDelayTimer.start();
return; return;
} }
if (_relativeLimitCurrentMeasuredDevice == 0 || _relativeUploadDeviceList.count()) { if (_relativeLimitCurrentMeasuredDevice == 0) {
qDebug() << Q_FUNC_INFO << "No device set, just waiting 1 sec"; qDebug() << Q_FUNC_INFO << "No device set, just waiting 1 sec";
_relativeUploadDelayTimer.setInterval(1000); _relativeUploadDelayTimer.setInterval(1000);
_relativeUploadDelayTimer.start(); _relativeUploadDelayTimer.start();
@ -247,13 +247,13 @@ void BandwidthManager::relativeUploadDelayTimerExpired()
// for downloads: // for downloads:
void BandwidthManager::relativeDownloadMeasuringTimerExpired() void BandwidthManager::relativeDownloadMeasuringTimerExpired()
{ {
if (!usingRelativeDownloadLimit()) { if (!usingRelativeDownloadLimit() || _downloadJobList.count() == 0) {
// Not in this limiting mode, just wait 1 sec to continue the cycle // Not in this limiting mode, just wait 1 sec to continue the cycle
_relativeDownloadDelayTimer.setInterval(1000); _relativeDownloadDelayTimer.setInterval(1000);
_relativeDownloadDelayTimer.start(); _relativeDownloadDelayTimer.start();
return; return;
} }
if (_relativeLimitCurrentMeasuredJob == 0 || _downloadJobList.count() == 0) { if (_relativeLimitCurrentMeasuredJob == 0) {
qDebug() << Q_FUNC_INFO << "No job set, just waiting 1 sec"; qDebug() << Q_FUNC_INFO << "No job set, just waiting 1 sec";
_relativeDownloadDelayTimer.setInterval(1000); _relativeDownloadDelayTimer.setInterval(1000);
_relativeDownloadDelayTimer.start(); _relativeDownloadDelayTimer.start();
@ -315,7 +315,7 @@ void BandwidthManager::relativeDownloadDelayTimerExpired()
} }
if (_downloadJobList.isEmpty()) { if (_downloadJobList.isEmpty()) {
qDebug() << Q_FUNC_INFO << _downloadJobList.count() << "No jobs?"; //qDebug() << Q_FUNC_INFO << _downloadJobList.count() << "No jobs?";
return; return;
} }

View file

@ -121,7 +121,7 @@ bool PollJob::finished()
bool ok = false; bool ok = false;
QByteArray jsonData = reply()->readAll().trimmed(); QByteArray jsonData = reply()->readAll().trimmed();
qDebug() << Q_FUNC_INFO << ">" << jsonData << "<"; qDebug() << Q_FUNC_INFO << ">" << jsonData << "<" << reply()->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt();
QVariantMap status = QtJson::parse(QString::fromUtf8(jsonData), ok).toMap(); QVariantMap status = QtJson::parse(QString::fromUtf8(jsonData), ok).toMap();
if (!ok || status.isEmpty()) { if (!ok || status.isEmpty()) {
_item._errorString = tr("Invalid json reply from the poll URL"); _item._errorString = tr("Invalid json reply from the poll URL");
@ -213,7 +213,7 @@ qint64 UploadDevice::readData(char* data, qint64 maxlen) {
return -1; return -1;
} }
_file.data()->seek(_start + _read); _file.data()->seek(_start + _read);
qDebug() << Q_FUNC_INFO << maxlen << _read << _size << _bandwidthQuota; //qDebug() << Q_FUNC_INFO << maxlen << _read << _size << _bandwidthQuota;
if (_size - _read <= 0) { if (_size - _read <= 0) {
// at end // at end
qDebug() << Q_FUNC_INFO << _read << _size << _bandwidthQuota << "at end"; qDebug() << Q_FUNC_INFO << _read << _size << _bandwidthQuota << "at end";
@ -222,7 +222,6 @@ qint64 UploadDevice::readData(char* data, qint64 maxlen) {
} }
maxlen = qMin(maxlen, _size - _read); maxlen = qMin(maxlen, _size - _read);
if (maxlen == 0) { if (maxlen == 0) {
qDebug() << Q_FUNC_INFO << "FUUUUUU" << maxlen << _size - _read;
return 0; return 0;
} }
if (isChoked()) { if (isChoked()) {
@ -242,19 +241,19 @@ qint64 UploadDevice::readData(char* data, qint64 maxlen) {
qDebug() << Q_FUNC_INFO << "reading limited=" << isBandwidthLimited() qDebug() << Q_FUNC_INFO << "reading limited=" << isBandwidthLimited()
<< "maxlen=" << maxlen << "quota=" << _bandwidthQuota; << "maxlen=" << maxlen << "quota=" << _bandwidthQuota;
qint64 ret = _file.data()->read(data, maxlen); qint64 ret = _file.data()->read(data, maxlen);
qDebug() << Q_FUNC_INFO << "returning " << ret; //qDebug() << Q_FUNC_INFO << "returning " << ret;
if (ret < 0) if (ret < 0)
return -1; return -1;
_read += ret; _read += ret;
qDebug() << Q_FUNC_INFO << "returning2 " << ret << _read; //qDebug() << Q_FUNC_INFO << "returning2 " << ret << _read;
return ret; return ret;
} }
void UploadDevice::slotJobUploadProgress(qint64 sent, qint64 t) void UploadDevice::slotJobUploadProgress(qint64 sent, qint64 t)
{ {
qDebug() << Q_FUNC_INFO << sent << _read << t << _size << _bandwidthQuota; //qDebug() << Q_FUNC_INFO << sent << _read << t << _size << _bandwidthQuota;
if (sent == 0 || t == 0) { if (sent == 0 || t == 0) {
return; return;
} }
@ -266,21 +265,21 @@ bool UploadDevice::atEnd() const {
qDebug() << Q_FUNC_INFO << "Upload file object deleted during upload"; qDebug() << Q_FUNC_INFO << "Upload file object deleted during upload";
return true; return true;
} }
qDebug() << this << Q_FUNC_INFO << _read << chunkSize() // qDebug() << this << Q_FUNC_INFO << _read << chunkSize()
<< (_read >= chunkSize() || _file.data()->atEnd()) // << (_read >= chunkSize() || _file.data()->atEnd())
<< (_read >= _size); // << (_read >= _size);
return _file.data()->atEnd() || (_read >= _size); return _file.data()->atEnd() || (_read >= _size);
} }
qint64 UploadDevice::size() const{ qint64 UploadDevice::size() const{
qDebug() << this << Q_FUNC_INFO << _size; // qDebug() << this << Q_FUNC_INFO << _size;
return _size; return _size;
} }
qint64 UploadDevice::bytesAvailable() const qint64 UploadDevice::bytesAvailable() const
{ {
qDebug() << this << Q_FUNC_INFO << _size << _read << QIODevice::bytesAvailable() // qDebug() << this << Q_FUNC_INFO << _size << _read << QIODevice::bytesAvailable()
<< _size - _read + QIODevice::bytesAvailable(); // << _size - _read + QIODevice::bytesAvailable();
return _size - _read + QIODevice::bytesAvailable(); return _size - _read + QIODevice::bytesAvailable();
} }
@ -301,10 +300,10 @@ bool UploadDevice::seek ( qint64 pos ) {
} }
void UploadDevice::giveBandwidthQuota(qint64 bwq) { void UploadDevice::giveBandwidthQuota(qint64 bwq) {
qDebug() << Q_FUNC_INFO << bwq; // qDebug() << Q_FUNC_INFO << bwq;
if (!atEnd()) { if (!atEnd()) {
_bandwidthQuota = bwq; _bandwidthQuota = bwq;
qDebug() << Q_FUNC_INFO << bwq << "emitting readyRead()" << _read << _readWithProgress; // qDebug() << Q_FUNC_INFO << bwq << "emitting readyRead()" << _read << _readWithProgress;
QMetaObject::invokeMethod(this, "readyRead", Qt::QueuedConnection); // tell QNAM that we have quota QMetaObject::invokeMethod(this, "readyRead", Qt::QueuedConnection); // tell QNAM that we have quota
} }
} }