From fe70090b742b334fefd1dbb6a3b16a567e9ad6a7 Mon Sep 17 00:00:00 2001 From: Sude Date: Mon, 10 Jun 2013 15:15:08 +0300 Subject: [PATCH] Added --timeout option to set timeout for connection phase --- include/api.h | 2 +- include/config.h | 1 + main.cpp | 1 + src/api.cpp | 4 ++-- src/downloader.cpp | 4 ++-- 5 files changed, 7 insertions(+), 5 deletions(-) diff --git a/include/api.h b/include/api.h index b30f38b..25f70fd 100644 --- a/include/api.h +++ b/include/api.h @@ -73,7 +73,7 @@ class API public: userDetails user; - API(const std::string& token,const std::string& secret, const bool& verbose = false, const bool& bVerifyPeer = true); + API(const std::string& token,const std::string& secret, const bool& verbose = false, const bool& bVerifyPeer = true, const long int& iTimeout = 10); int init(); int login(const std::string& email, const std::string& password); int getAPIConfig(); diff --git a/include/config.h b/include/config.h index 0384920..1bae724 100644 --- a/include/config.h +++ b/include/config.h @@ -45,6 +45,7 @@ class Config unsigned int iInstallerLanguage; size_t iChunkSize; curl_off_t iDownloadRate; + long int iTimeout; }; #endif // CONFIG_H__ diff --git a/main.cpp b/main.cpp index d434499..24c2038 100644 --- a/main.cpp +++ b/main.cpp @@ -103,6 +103,7 @@ int main(int argc, char *argv[]) ("no-color", bpo::value(&config.bNoColor)->zero_tokens()->default_value(false), "Don't use coloring in the progress bar") ("verbose", bpo::value(&config.bVerbose)->zero_tokens()->default_value(false), "Print lots of information") ("unsecure", bpo::value(&bUnsecure)->zero_tokens()->default_value(false), "Don't verify authenticity of SSL certificates") + ("timeout", bpo::value(&config.iTimeout)->default_value(10), "Set timeout for connection\nMaximum time in seconds that connection phase is allowed to take") ; bpo::store(bpo::parse_command_line(argc, argv, desc), vm); diff --git a/src/api.cpp b/src/api.cpp index d2da5bc..7f6abcf 100644 --- a/src/api.cpp +++ b/src/api.cpp @@ -33,13 +33,13 @@ gameFile::~gameFile() } -API::API(const std::string& token, const std::string& secret, const bool& verbose, const bool& bVerifyPeer) +API::API(const std::string& token, const std::string& secret, const bool& verbose, const bool& bVerifyPeer, const long int& iTimeout) { curlhandle = curl_easy_init(); curl_easy_setopt(curlhandle, CURLOPT_VERBOSE, verbose); curl_easy_setopt(curlhandle, CURLOPT_FOLLOWLOCATION, 1); curl_easy_setopt(curlhandle, CURLOPT_NOPROGRESS, 1); - curl_easy_setopt(curlhandle, CURLOPT_CONNECTTIMEOUT, 10); + curl_easy_setopt(curlhandle, CURLOPT_CONNECTTIMEOUT, iTimeout); curl_easy_setopt(curlhandle, CURLOPT_PROGRESSDATA, this); curl_easy_setopt(curlhandle, CURLOPT_FAILONERROR, true); curl_easy_setopt(curlhandle, CURLOPT_SSL_VERIFYPEER, bVerifyPeer); diff --git a/src/downloader.cpp b/src/downloader.cpp index 069f3e5..20def7e 100644 --- a/src/downloader.cpp +++ b/src/downloader.cpp @@ -52,7 +52,7 @@ int Downloader::init() curl_easy_setopt(curlhandle, CURLOPT_FOLLOWLOCATION, 1); curl_easy_setopt(curlhandle, CURLOPT_USERAGENT, config.sVersionString.c_str()); curl_easy_setopt(curlhandle, CURLOPT_NOPROGRESS, 0); - curl_easy_setopt(curlhandle, CURLOPT_CONNECTTIMEOUT, 10); + curl_easy_setopt(curlhandle, CURLOPT_CONNECTTIMEOUT, config.iTimeout); curl_easy_setopt(curlhandle, CURLOPT_PROGRESSDATA, this); curl_easy_setopt(curlhandle, CURLOPT_FAILONERROR, true); curl_easy_setopt(curlhandle, CURLOPT_COOKIEFILE, config.sCookiePath.c_str()); @@ -66,7 +66,7 @@ int Downloader::init() curl_easy_setopt(curlhandle, CURLOPT_MAX_RECV_SPEED_LARGE, config.iDownloadRate); #endif - gogAPI = new API(config.sToken, config.sSecret, config.bVerbose, config.bVerifyPeer); + gogAPI = new API(config.sToken, config.sSecret, config.bVerbose, config.bVerifyPeer, config.iTimeout); progressbar = new ProgressBar(!config.bNoUnicode, !config.bNoColor); if (config.bLogin || !gogAPI->init())