Implement change of the network throttling during a running sync run.

This commit is contained in:
Klaas Freitag 2014-01-31 17:29:50 +01:00
parent 08d08e1f29
commit 971caca5e8
8 changed files with 41 additions and 5 deletions

View file

@ -431,10 +431,6 @@ void CSyncThread::startSync()
} }
_abortRequestedMutex.unlock(); _abortRequestedMutex.unlock();
// maybe move this somewhere else where it can influence a running sync?
MirallConfigFile cfg;
if (!_journal->exists()) { if (!_journal->exists()) {
qDebug() << "=====sync looks new (no DB exists), activating recursive PROPFIND if csync supports it"; qDebug() << "=====sync looks new (no DB exists), activating recursive PROPFIND if csync supports it";
bool no_recursive_propfind = false; bool no_recursive_propfind = false;
@ -562,6 +558,17 @@ void CSyncThread::startSync()
connect(_propagator.data(), SIGNAL(progressChanged(qint64)), this, SLOT(slotProgressChanged(qint64))); connect(_propagator.data(), SIGNAL(progressChanged(qint64)), this, SLOT(slotProgressChanged(qint64)));
connect(_propagator.data(), SIGNAL(finished()), this, SLOT(slotFinished())); connect(_propagator.data(), SIGNAL(finished()), this, SLOT(slotFinished()));
setNetworkLimits();
_propagator->start(_syncedItems);
}
void CSyncThread::setNetworkLimits()
{
MirallConfigFile cfg;
if( !_propagator ) return;
int downloadLimit = 0; int downloadLimit = 0;
if (cfg.useDownloadLimit()) { if (cfg.useDownloadLimit()) {
downloadLimit = cfg.downloadLimit() * 1000; downloadLimit = cfg.downloadLimit() * 1000;
@ -577,7 +584,8 @@ void CSyncThread::startSync()
} }
_propagator->_uploadLimit = uploadLimit; _propagator->_uploadLimit = uploadLimit;
_propagator->start(_syncedItems); qDebug() << " N------N Network Limits changed!";
} }
void CSyncThread::transferCompleted(const SyncFileItem &item) void CSyncThread::transferCompleted(const SyncFileItem &item)

View file

@ -53,6 +53,7 @@ public:
static QString csyncErrorToString( CSYNC_STATUS); static QString csyncErrorToString( CSYNC_STATUS);
Q_INVOKABLE void startSync(); Q_INVOKABLE void startSync();
Q_INVOKABLE void setNetworkLimits();
/* Abort the sync. Called from the main thread */ /* Abort the sync. Called from the main thread */
void abort(); void abort();

View file

@ -600,6 +600,13 @@ void Folder::startSync(const QStringList &pathList)
emit syncStarted(); emit syncStarted();
} }
void Folder::setDirtyNetworkLimits()
{
if( _csync ) {
QMetaObject::invokeMethod(_csync, "setNetworkLimits", Qt::QueuedConnection);
}
}
void Folder::slotCSyncError(const QString& err) void Folder::slotCSyncError(const QString& err)
{ {
_errors.append( err ); _errors.append( err );

View file

@ -134,6 +134,8 @@ public:
void setSyncState(SyncResult::Status state); void setSyncState(SyncResult::Status state);
void setDirtyNetworkLimits();
signals: signals:
void syncStateChange(); void syncStateChange();
void syncStarted(); void syncStarted();

View file

@ -608,6 +608,16 @@ void FolderMan::setDirtyProxy(bool value)
} }
} }
void FolderMan::setDirtyNetworkLimits()
{
foreach( Folder *f, _folderMap.values() ) {
// set only in busy folders. Otherwise they read the config anyway.
if(f && f->isBusy()) {
f->setDirtyNetworkLimits();
}
}
}
SyncResult FolderMan::accountStatus(const QList<Folder*> &folders) SyncResult FolderMan::accountStatus(const QList<Folder*> &folders)
{ {

View file

@ -108,6 +108,7 @@ public slots:
void slotScheduleAllFolders(); void slotScheduleAllFolders();
void setDirtyProxy(bool value = true); void setDirtyProxy(bool value = true);
void setDirtyNetworkLimits();
// slot to add a folder to the syncing queue // slot to add a folder to the syncing queue
void slotScheduleSync( const QString & ); void slotScheduleSync( const QString & );

View file

@ -163,6 +163,8 @@ void NetworkSettings::saveBWLimitSettings()
cfgFile.setDownloadLimit(_ui->downloadSpinBox->value()); cfgFile.setDownloadLimit(_ui->downloadSpinBox->value());
cfgFile.setUploadLimit(_ui->uploadSpinBox->value()); cfgFile.setUploadLimit(_ui->uploadSpinBox->value());
FolderMan::instance()->setDirtyNetworkLimits();
} }
} // namespace Mirall } // namespace Mirall

View file

@ -30,6 +30,7 @@
#include <QDebug> #include <QDebug>
#include <QDateTime> #include <QDateTime>
#include <qstack.h> #include <qstack.h>
#include <QCoreApplication>
#include <neon/ne_basic.h> #include <neon/ne_basic.h>
#include <neon/ne_socket.h> #include <neon/ne_socket.h>
@ -418,6 +419,7 @@ void PropagateUploadFile::notify_status_cb(void* userdata, ne_session_status sta
that->_chunked_done + info->sr.progress, that->_chunked_done + info->sr.progress,
that->_chunked_total_size ? that->_chunked_total_size : info->sr.total ); that->_chunked_total_size ? that->_chunked_total_size : info->sr.total );
QCoreApplication::processEvents();
that->limitBandwidth(that->_chunked_done + info->sr.progress, that->_propagator->_uploadLimit); that->limitBandwidth(that->_chunked_done + info->sr.progress, that->_propagator->_uploadLimit);
} }
} }
@ -526,6 +528,7 @@ int PropagateDownloadFile::content_reader(void *userdata, const char *buf, size_
} }
return NE_OK; return NE_OK;
} }
return NE_ERROR; return NE_ERROR;
} }
@ -608,6 +611,8 @@ void PropagateDownloadFile::notify_status_cb(void* userdata, ne_session_status s
PropagateDownloadFile* that = reinterpret_cast<PropagateDownloadFile*>(userdata); PropagateDownloadFile* that = reinterpret_cast<PropagateDownloadFile*>(userdata);
if (status == ne_status_recving && info->sr.total > 0) { if (status == ne_status_recving && info->sr.total > 0) {
emit that->progress(Progress::Context, that->_item, info->sr.progress, info->sr.total ); emit that->progress(Progress::Context, that->_item, info->sr.progress, info->sr.total );
QCoreApplication::processEvents();
that->limitBandwidth(info->sr.progress, that->_propagator->_downloadLimit); that->limitBandwidth(info->sr.progress, that->_propagator->_downloadLimit);
} }
} }