* 'I' key set the download to ignore the start/stop_try commands.

* Added options for timeout_sync/safe_sync and max_chunks_queued.


git-svn-id: svn://rakshasa.no/libtorrent/trunk/rtorrent@739 e378c898-3ddf-0310-93e7-cc216c733640
This commit is contained in:
rakshasa
2006-07-07 22:19:20 +00:00
parent 63311270c9
commit 52bf80d704
8 changed files with 102 additions and 81 deletions
+38 -57
View File
@@ -118,74 +118,54 @@ apply_load_start_verbose(Control* m, const std::string& arg) {
}
void
apply_start_tied(Control* m, const std::string& arg) {
std::vector<std::string> paths;
paths.reserve(256);
apply_start_tied(Control* m) {
for (core::DownloadList::iterator itr = m->core()->download_list()->begin(); itr != m->core()->download_list()->end(); ++itr) {
if ((*itr)->variable_value("state") == 1)
continue;
core::path_expand(&paths, arg);
rak::file_stat fs;
const std::string& tiedToFile = (*itr)->variable_string("tied_to_file");
for (std::vector<std::string>::iterator itr = paths.begin(); itr != paths.end(); ++itr) {
core::DownloadList::iterator dItr = std::find_if(m->core()->download_list()->begin(), m->core()->download_list()->end(),
rak::equal(*itr, rak::bind2nd(std::mem_fun(&core::Download::variable_string), "tied_to_file")));
if (dItr != m->core()->download_list()->end())
m->core()->download_list()->start_try(*dItr);
if (!tiedToFile.empty() && fs.update(rak::path_expand(tiedToFile)))
m->core()->download_list()->start_try(*itr);
}
}
void
apply_stop_untied(Control* m) {
core::Manager::DListItr itr = m->core()->download_list()->begin();
for (core::DownloadList::iterator itr = m->core()->download_list()->begin(); itr != m->core()->download_list()->end(); ++itr) {
if ((*itr)->variable_value("state") == 0)
continue;
while ((itr = std::find_if(itr, m->core()->download_list()->end(), rak::on(rak::bind2nd(std::mem_fun(&core::Download::variable_string), "tied_to_file"),
std::not1(std::mem_fun_ref(&std::string::empty)))))
!= m->core()->download_list()->end()) {
rak::file_stat fs;
const std::string& tiedToFile = (*itr)->variable_string("tied_to_file");
if (!fs.update(rak::path_expand((*itr)->variable_string("tied_to_file")))) {
// (*itr)->variable()->set("tied_to_file", std::string());
m->core()->download_list()->stop(*itr);
}
++itr;
if (!tiedToFile.empty() && !fs.update(rak::path_expand(tiedToFile)))
m->core()->download_list()->stop_try(*itr);
}
}
void
apply_close_untied(Control* m) {
core::Manager::DListItr itr = m->core()->download_list()->begin();
while ((itr = std::find_if(itr, m->core()->download_list()->end(), rak::on(rak::bind2nd(std::mem_fun(&core::Download::variable_string), "tied_to_file"),
std::not1(std::mem_fun_ref(&std::string::empty)))))
!= m->core()->download_list()->end()) {
for (core::DownloadList::iterator itr = m->core()->download_list()->begin(); itr != m->core()->download_list()->end(); ++itr) {
rak::file_stat fs;
const std::string& tiedToFile = (*itr)->variable_string("tied_to_file");
if (!fs.update(rak::path_expand((*itr)->variable_string("tied_to_file")))) {
// (*itr)->variable()->set("tied_to_file", std::string());
if (!tiedToFile.empty() && !fs.update(rak::path_expand(tiedToFile)) && m->core()->download_list()->stop_try(*itr))
m->core()->download_list()->close(*itr);
}
++itr;
}
}
void
apply_remove_untied(Control* m) {
core::Manager::DListItr itr = m->core()->download_list()->begin();
while ((itr = std::find_if(itr, m->core()->download_list()->end(), rak::on(rak::bind2nd(std::mem_fun(&core::Download::variable_string), "tied_to_file"),
std::not1(std::mem_fun_ref(&std::string::empty)))))
!= m->core()->download_list()->end()) {
for (core::DownloadList::iterator itr = m->core()->download_list()->begin(); itr != m->core()->download_list()->end(); ) {
rak::file_stat fs;
const std::string& tiedToFile = (*itr)->variable_string("tied_to_file");
if (!fs.update(rak::path_expand((*itr)->variable_string("tied_to_file")))) {
// (*itr)->variable()->set("tied_to_file", std::string());
m->core()->download_list()->stop(*itr);
if (!tiedToFile.empty() && !fs.update(rak::path_expand(tiedToFile)) && m->core()->download_list()->stop_try(*itr))
itr = m->core()->download_list()->erase(itr);
} else {
else
++itr;
}
}
}
@@ -193,8 +173,7 @@ void
apply_close_low_diskspace(Control* m, int64_t arg) {
core::Manager::DListItr itr = m->core()->download_list()->begin();
while ((itr = std::find_if(itr, m->core()->download_list()->end(), rak::equal(true, std::mem_fun(&core::Download::is_downloading))))
!= m->core()->download_list()->end()) {
while ((itr = std::find_if(itr, m->core()->download_list()->end(), std::mem_fun(&core::Download::is_downloading))) != m->core()->download_list()->end()) {
rak::fs_stat stat;
std::string path = (*itr)->file_list()->root_dir() + (*itr)->file_list()->get(0).path()->as_string();
@@ -203,6 +182,8 @@ apply_close_low_diskspace(Control* m, int64_t arg) {
} else if (stat.bytes_avail() < arg) {
m->core()->download_list()->close(*itr);
(*itr)->set_hash_failed(true);
(*itr)->set_message(std::string("Low diskspace"));
}
@@ -212,32 +193,28 @@ apply_close_low_diskspace(Control* m, int64_t arg) {
void
apply_stop_on_ratio(Control* m, const std::string& arg) {
int64_t min_Ratio = 0; // first argument: minimum ratio to reach
int64_t min_Upload = 0; // second argument: minimum upload amount to reach [optional]
int64_t max_Ratio = 0; // third argument: maximum ratio to reach [optional]
int64_t minRatio = 0; // first argument: minimum ratio to reach
int64_t minUpload = 0; // second argument: minimum upload amount to reach [optional]
int64_t maxRatio = 0; // third argument: maximum ratio to reach [optional]
rak::split_iterator_t<std::string> sitr = rak::split_iterator(arg, ',');
utils::Variable::string_to_value_unit(rak::trim(*sitr).c_str(), &min_Ratio, 0, 1);
utils::Variable::string_to_value_unit(rak::trim(*sitr).c_str(), &minRatio, 0, 1);
if (++sitr != rak::split_iterator(arg))
utils::Variable::string_to_value_unit(rak::trim(*sitr).c_str(), &min_Upload, 0, 1);
utils::Variable::string_to_value_unit(rak::trim(*sitr).c_str(), &minUpload, 0, 1);
if (++sitr != rak::split_iterator(arg))
utils::Variable::string_to_value_unit(rak::trim(*sitr).c_str(), &max_Ratio, 0, 1);
utils::Variable::string_to_value_unit(rak::trim(*sitr).c_str(), &maxRatio, 0, 1);
core::Manager::DListItr itr = m->core()->download_list()->begin();
while ((itr = std::find_if(itr, m->core()->download_list()->end(), rak::equal(true, std::mem_fun(&core::Download::is_seeding))))
!= m->core()->download_list()->end()) {
while ((itr = std::find_if(itr, m->core()->download_list()->end(), std::mem_fun(&core::Download::is_seeding))) != m->core()->download_list()->end()) {
int64_t totalUpload = (*itr)->download()->up_rate()->total();
int64_t totalDone = (*itr)->download()->bytes_done();
if ((totalUpload >= min_Upload && totalUpload * 100 >= totalDone * min_Ratio) ||
(max_Ratio > 0 && totalUpload * 100 > totalDone * max_Ratio)) {
if ((*itr)->variable()->get_value("ignore_ratio") == 0)
m->core()->download_list()->stop(*itr);
}
if ((totalUpload >= minUpload && totalUpload * 100 >= totalDone * minRatio) || (maxRatio > 0 && totalUpload * 100 > totalDone * maxRatio))
m->core()->download_list()->stop_try(*itr);
++itr;
}
@@ -446,6 +423,10 @@ initialize_option_handler(Control* c) {
variables->insert("min_peers", new utils::VariableValue(40));
variables->insert("max_peers", new utils::VariableValue(100));
variables->insert("max_uploads", new utils::VariableValue(15));
variables->insert("max_chunks_queued", new utils::VariableValue(0));
variables->insert("timeout_sync", new utils::VariableValue(0));
variables->insert("timeout_safe_sync", new utils::VariableValue(0));
variables->insert("download_rate", new utils::VariableValueSlot(rak::ptr_fn(&torrent::down_throttle), rak::mem_fn(control->ui(), &ui::Root::set_down_throttle_i64),
0, (1 << 10)));
@@ -496,7 +477,7 @@ initialize_option_handler(Control* c) {
variables->insert("load_start", new utils::VariableStringSlot(rak::value_fn(std::string()), rak::bind_ptr_fn(&apply_load_start, c)));
variables->insert("load_start_verbose", new utils::VariableStringSlot(rak::value_fn(std::string()), rak::bind_ptr_fn(&apply_load_start_verbose, c)));
variables->insert("start_tied", new utils::VariableStringSlot(rak::value_fn(std::string()), rak::bind_ptr_fn(&apply_start_tied, c)));
variables->insert("start_tied", new utils::VariableVoidSlot(rak::bind_ptr_fn(&apply_start_tied, c)));
variables->insert("stop_untied", new utils::VariableVoidSlot(rak::bind_ptr_fn(&apply_stop_untied, c)));
variables->insert("close_untied", new utils::VariableVoidSlot(rak::bind_ptr_fn(&apply_close_untied, c)));
variables->insert("remove_untied", new utils::VariableVoidSlot(rak::bind_ptr_fn(&apply_remove_untied, c)));