summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrew A. de Laix <alain@lindenlab.com>2010-12-07 15:41:31 -0800
committerAndrew A. de Laix <alain@lindenlab.com>2010-12-07 15:41:31 -0800
commit3c3683b884542e5aa85099f4ce0c1b556613795d (patch)
treeca2fa9b4bf5e50ab4641a64c62eb072c81698a69
parent4d861ef022f6c22837de4c76ee3e7f2b191b8a5e (diff)
limit dowload bandwidth to 'Maximum bandwidth' setting
-rw-r--r--indra/newview/llappviewer.cpp9
-rw-r--r--indra/viewer_components/updater/llupdatedownloader.cpp26
-rw-r--r--indra/viewer_components/updater/llupdatedownloader.h3
-rw-r--r--indra/viewer_components/updater/llupdaterservice.cpp11
-rw-r--r--indra/viewer_components/updater/llupdaterservice.h1
-rw-r--r--indra/viewer_components/updater/tests/llupdaterservice_test.cpp1
6 files changed, 51 insertions, 0 deletions
diff --git a/indra/newview/llappviewer.cpp b/indra/newview/llappviewer.cpp
index 08e40168c3..38422621ef 100644
--- a/indra/newview/llappviewer.cpp
+++ b/indra/newview/llappviewer.cpp
@@ -2413,6 +2413,12 @@ namespace {
// let others also handle this event by default
return false;
}
+
+ bool on_bandwidth_throttle(LLUpdaterService * updater, LLSD const & evt)
+ {
+ updater->setBandwidthLimit(evt.asInteger() * (1024/8));
+ return false; // Let others receive this event.
+ };
};
void LLAppViewer::initUpdater()
@@ -2435,6 +2441,9 @@ void LLAppViewer::initUpdater()
channel,
version);
mUpdater->setCheckPeriod(check_period);
+ mUpdater->setBandwidthLimit((int)gSavedSettings.getF32("ThrottleBandwidthKBPS") * (1024/8));
+ gSavedSettings.getControl("ThrottleBandwidthKBPS")->getSignal()->
+ connect(boost::bind(&on_bandwidth_throttle, mUpdater.get(), _2));
if(gSavedSettings.getBOOL("UpdaterServiceActive"))
{
bool install_if_ready = true;
diff --git a/indra/viewer_components/updater/llupdatedownloader.cpp b/indra/viewer_components/updater/llupdatedownloader.cpp
index ce6b488ecb..d67de1c83b 100644
--- a/indra/viewer_components/updater/llupdatedownloader.cpp
+++ b/indra/viewer_components/updater/llupdatedownloader.cpp
@@ -54,8 +54,10 @@ public:
size_t onBody(void * header, size_t size);
int onProgress(double downloadSize, double bytesDownloaded);
void resume(void);
+ void setBandwidthLimit(U64 bytesPerSecond);
private:
+ curl_off_t mBandwidthLimit;
bool mCancelled;
LLUpdateDownloader::Client & mClient;
CURL * mCurl;
@@ -136,6 +138,12 @@ void LLUpdateDownloader::resume(void)
}
+void LLUpdateDownloader::setBandwidthLimit(U64 bytesPerSecond)
+{
+ mImplementation->setBandwidthLimit(bytesPerSecond);
+}
+
+
// LLUpdateDownloader::Implementation
//-----------------------------------------------------------------------------
@@ -170,6 +178,7 @@ namespace {
LLUpdateDownloader::Implementation::Implementation(LLUpdateDownloader::Client & client):
LLThread("LLUpdateDownloader"),
+ mBandwidthLimit(0),
mCancelled(false),
mClient(client),
mCurl(0),
@@ -264,6 +273,20 @@ void LLUpdateDownloader::Implementation::resume(void)
}
+void LLUpdateDownloader::Implementation::setBandwidthLimit(U64 bytesPerSecond)
+{
+ if((mBandwidthLimit != bytesPerSecond) && isDownloading()) {
+ llassert(mCurl != 0);
+ mBandwidthLimit = bytesPerSecond;
+ CURLcode code = curl_easy_setopt(mCurl, CURLOPT_MAX_RECV_SPEED_LARGE, &mBandwidthLimit);
+ if(code != CURLE_OK) LL_WARNS("UpdateDownload") <<
+ "unable to change dowload bandwidth" << LL_ENDL;
+ } else {
+ mBandwidthLimit = bytesPerSecond;
+ }
+}
+
+
size_t LLUpdateDownloader::Implementation::onHeader(void * buffer, size_t size)
{
char const * headerPtr = reinterpret_cast<const char *> (buffer);
@@ -388,6 +411,9 @@ void LLUpdateDownloader::Implementation::initializeCurlGet(std::string const & u
throwOnCurlError(curl_easy_setopt(mCurl, CURLOPT_PROGRESSFUNCTION, &progress_callback));
throwOnCurlError(curl_easy_setopt(mCurl, CURLOPT_PROGRESSDATA, this));
throwOnCurlError(curl_easy_setopt(mCurl, CURLOPT_NOPROGRESS, false));
+ if(mBandwidthLimit != 0) {
+ throwOnCurlError(curl_easy_setopt(mCurl, CURLOPT_MAX_RECV_SPEED_LARGE, mBandwidthLimit));
+ }
mDownloadPercent = 0;
}
diff --git a/indra/viewer_components/updater/llupdatedownloader.h b/indra/viewer_components/updater/llupdatedownloader.h
index 09ea1676d5..4e20b307b8 100644
--- a/indra/viewer_components/updater/llupdatedownloader.h
+++ b/indra/viewer_components/updater/llupdatedownloader.h
@@ -60,6 +60,9 @@ public:
// Resume a partial download.
void resume(void);
+ // Set a limit on the dowload rate.
+ void setBandwidthLimit(U64 bytesPerSecond);
+
private:
boost::shared_ptr<Implementation> mImplementation;
};
diff --git a/indra/viewer_components/updater/llupdaterservice.cpp b/indra/viewer_components/updater/llupdaterservice.cpp
index 7d180ff649..b29356b968 100644
--- a/indra/viewer_components/updater/llupdaterservice.cpp
+++ b/indra/viewer_components/updater/llupdaterservice.cpp
@@ -114,6 +114,7 @@ public:
const std::string& version);
void setCheckPeriod(unsigned int seconds);
+ void setBandwidthLimit(U64 bytesPerSecond);
void startChecking(bool install_if_ready);
void stopChecking();
@@ -189,6 +190,11 @@ void LLUpdaterServiceImpl::setCheckPeriod(unsigned int seconds)
mCheckPeriod = seconds;
}
+void LLUpdaterServiceImpl::setBandwidthLimit(U64 bytesPerSecond)
+{
+ mUpdateDownloader.setBandwidthLimit(bytesPerSecond);
+}
+
void LLUpdaterServiceImpl::startChecking(bool install_if_ready)
{
if(mUrl.empty() || mChannel.empty() || mVersion.empty())
@@ -541,6 +547,11 @@ void LLUpdaterService::setCheckPeriod(unsigned int seconds)
{
mImpl->setCheckPeriod(seconds);
}
+
+void LLUpdaterService::setBandwidthLimit(U64 bytesPerSecond)
+{
+ mImpl->setBandwidthLimit(bytesPerSecond);
+}
void LLUpdaterService::startChecking(bool install_if_ready)
{
diff --git a/indra/viewer_components/updater/llupdaterservice.h b/indra/viewer_components/updater/llupdaterservice.h
index 8b76a9d1e7..1ffa609019 100644
--- a/indra/viewer_components/updater/llupdaterservice.h
+++ b/indra/viewer_components/updater/llupdaterservice.h
@@ -76,6 +76,7 @@ public:
const std::string& version);
void setCheckPeriod(unsigned int seconds);
+ void setBandwidthLimit(U64 bytesPerSecond);
void startChecking(bool install_if_ready = false);
void stopChecking();
diff --git a/indra/viewer_components/updater/tests/llupdaterservice_test.cpp b/indra/viewer_components/updater/tests/llupdaterservice_test.cpp
index 050bb774f7..fbdf9a4993 100644
--- a/indra/viewer_components/updater/tests/llupdaterservice_test.cpp
+++ b/indra/viewer_components/updater/tests/llupdaterservice_test.cpp
@@ -101,6 +101,7 @@ std::string LLUpdateDownloader::downloadMarkerPath(void)
void LLUpdateDownloader::resume(void) {}
void LLUpdateDownloader::cancel(void) {}
+void LLUpdateDownloader::setBandwidthLimit(U64 bytesPerSecond) {}
int ll_install_update(std::string const &, std::string const &, LLInstallScriptMode)
{