summaryrefslogtreecommitdiff
path: root/src/OptionHandlerImpl.cc
diff options
context:
space:
mode:
authoroliviercommelarbre <oliviercommelarbre@gmail.com>2016-02-11 00:04:49 +0100
committerTatsuhiro Tsujikawa <tatsuhiro.t@gmail.com>2016-03-16 21:22:49 +0900
commit9e05371fb6a70d7d5e9d49db31b879e79c1b56e7 (patch)
treede5e25d3a5b89c932f897e6c4905ba7b507337ec /src/OptionHandlerImpl.cc
parentf0f1b8ef47c391550ff99982f1cad3dd4e1d410d (diff)
Added support for a dynamic management of the number of concurrent downloads as a function of the overall bandwidth observed
Diffstat (limited to 'src/OptionHandlerImpl.cc')
-rw-r--r--src/OptionHandlerImpl.cc55
1 files changed, 55 insertions, 0 deletions
diff --git a/src/OptionHandlerImpl.cc b/src/OptionHandlerImpl.cc
index a01c111e..305493a2 100644
--- a/src/OptionHandlerImpl.cc
+++ b/src/OptionHandlerImpl.cc
@@ -586,6 +586,61 @@ std::string PrioritizePieceOptionHandler::createPossibleValuesString() const
return "head[=SIZE], tail[=SIZE]";
}
+OptimizeConcurrentDownloadsOptionHandler::OptimizeConcurrentDownloadsOptionHandler(
+ PrefPtr pref, const char* description, const std::string& defaultValue, char shortName)
+ : AbstractOptionHandler(pref, description, defaultValue,
+ OptionHandler::OPT_ARG, shortName)
+{
+}
+
+void OptimizeConcurrentDownloadsOptionHandler::parseArg(Option& option,
+ const std::string& optarg) const
+{
+ if (optarg == "true" || optarg.empty()) {
+ option.put(pref_, A2_V_TRUE);
+ }
+ else if (optarg == "false") {
+ option.put(pref_, A2_V_FALSE);
+ }
+ else {
+ auto p = util::divide(std::begin(optarg), std::end(optarg), ':');
+
+ std::string coeff_b(p.second.first,p.second.second);
+ if(coeff_b.empty()) {
+ std::string msg = pref_->k;
+ msg += " ";
+ msg += _("must be either 'true', 'false' or a pair numeric coefficients A and B under the form 'A:B'.");
+ throw DL_ABORT_EX(msg);
+ }
+
+ std::string coeff_a(p.first.first,p.first.second);
+
+
+ PrefPtr pref=PREF_OPTIMIZE_CONCURRENT_DOWNLOADS_COEFFA;
+ std::string *sptr = &coeff_a;
+ for(;;) {
+ try {
+ double dbl = std::stod(*sptr);
+ } catch(std::invalid_argument & ex) {
+ throw DL_ABORT_EX(fmt("Bad number '%s'", sptr->c_str()));
+ }
+ option.put(pref,*sptr);
+
+ if(pref == PREF_OPTIMIZE_CONCURRENT_DOWNLOADS_COEFFB) {
+ break;
+ }
+ pref = PREF_OPTIMIZE_CONCURRENT_DOWNLOADS_COEFFB;
+ sptr = &coeff_b;
+ }
+ option.put(pref_, A2_V_TRUE);
+ }
+}
+
+std::string OptimizeConcurrentDownloadsOptionHandler::createPossibleValuesString() const
+{
+ return "true, false, A:B";
+}
+
DeprecatedOptionHandler::DeprecatedOptionHandler(
OptionHandler* depOptHandler, const OptionHandler* repOptHandler,
bool stillWork, std::string additionalMessage)