Added --wait option to set delay for http requests

May help with some errors that could be caused by too many requests in short time
This commit is contained in:
Sude 2014-06-10 12:16:49 +03:00
parent dee83494c0
commit f25c37074a
3 changed files with 6 additions and 0 deletions

View File

@ -52,6 +52,7 @@ class Config
unsigned int iInstallerType;
unsigned int iInstallerLanguage;
int iRetries;
int iWait;
size_t iChunkSize;
curl_off_t iDownloadRate;
long int iTimeout;

View File

@ -154,6 +154,7 @@ int main(int argc, char *argv[])
("insecure", bpo::value<bool>(&bInsecure)->zero_tokens()->default_value(false), "Don't verify authenticity of SSL certificates")
("timeout", bpo::value<long int>(&config.iTimeout)->default_value(10), "Set timeout for connection\nMaximum time in seconds that connection phase is allowed to take")
("retries", bpo::value<int>(&config.iRetries)->default_value(3), "Set maximum number of retries on failed download")
("wait", bpo::value<int>(&config.iWait)->default_value(0), "Time to wait between requests (milliseconds)")
;
// Options read from config file
options_cfg_only.add_options()
@ -206,6 +207,9 @@ int main(int argc, char *argv[])
if (config.sOrphanRegex.empty())
config.sOrphanRegex = orphans_regex_default;
if (config.iWait > 0)
config.iWait *= 1000;
config.bVerifyPeer = !bInsecure;
config.bColor = !bNoColor;
config.bUnicode = !bNoUnicode;

View File

@ -1402,6 +1402,7 @@ std::string Downloader::getResponse(const std::string& url)
CURLcode result;
do
{
usleep(config.iWait); // Delay the request by specified time
result = curl_easy_perform(curlhandle);
response = memory.str();
memory.str(std::string());