limit dowload bandwidth to 'Maximum bandwidth' setting

master
Andrew A. de Laix 2010-12-07 15:41:31 -08:00
parent 4d861ef022
commit 3c3683b884
6 changed files with 51 additions and 0 deletions

View File

@ -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;

View File

@ -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;
}

View File

@ -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;
};

View File

@ -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())
@ -542,6 +548,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)
{
mImpl->startChecking(install_if_ready);

View File

@ -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();

View File

@ -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)
{