From 30d04f31fd16a03ced7d9a95520a1c9175946c13 Mon Sep 17 00:00:00 2001 From: Arvid Norberg Date: Wed, 9 Feb 2011 04:54:22 +0000 Subject: [PATCH] client_test fixes --- examples/client_test.cpp | 26 +++++++++++++++++++------- 1 file changed, 19 insertions(+), 7 deletions(-) diff --git a/examples/client_test.cpp b/examples/client_test.cpp index 79636a844..6e7bbf38c 100644 --- a/examples/client_test.cpp +++ b/examples/client_test.cpp @@ -643,6 +643,7 @@ using boost::bind; // if it's no longer in that directory. void add_torrent(libtorrent::session& ses , handles_t& handles + , std::set& non_files , std::string const& torrent , float preferred_ratio , int allocation_mode @@ -692,6 +693,10 @@ void add_torrent(libtorrent::session& ses handles.insert(std::pair( torrent, h)); } + else + { + non_files.insert(h); + } h.set_max_connections(max_connections_per_torrent); h.set_max_uploads(-1); @@ -707,6 +712,7 @@ void add_torrent(libtorrent::session& ses void scan_dir(std::string const& dir_path , libtorrent::session& ses , handles_t& files + , std::set& non_files , float preferred_ratio , int allocation_mode , std::string const& save_path @@ -732,7 +738,7 @@ void scan_dir(std::string const& dir_path // the file has been added to the dir, start // downloading it. - add_torrent(ses, files, file, preferred_ratio, allocation_mode + add_torrent(ses, files, non_files, file, preferred_ratio, allocation_mode , save_path, true, torrent_upload_limit, torrent_download_limit); valid.insert(file); } @@ -815,7 +821,7 @@ int save_file(std::string const& filename, std::vector& v) } void handle_alert(libtorrent::session& ses, libtorrent::alert* a - , handles_t const& files) + , handles_t const& files, std::set const& non_files) { using namespace libtorrent; @@ -838,8 +844,9 @@ void handle_alert(libtorrent::session& ses, libtorrent::alert* a std::vector out; bencode(std::back_inserter(out), *p->resume_data); save_file(combine_path(h.save_path(), ".resume/" + h.name() + ".resume"), out); - if (std::find_if(files.begin(), files.end() - , boost::bind(&handles_t::value_type::second, _1) == h) == files.end()) + if (non_files.find(h) == non_files.end() + && std::find_if(files.begin(), files.end() + , boost::bind(&handles_t::value_type::second, _1) == h) == files.end()) ses.remove_torrent(h); } } @@ -945,6 +952,9 @@ int main(int argc, char* argv[]) // monitor when they're not in the directory anymore. std::vector handles; handles_t files; + // torrents that were not added via the monitor dir + std::set non_files; + int counters[torrents_max]; session ses(fingerprint("LT", LIBTORRENT_VERSION_MAJOR, LIBTORRENT_VERSION_MINOR, 0, 0) @@ -1172,6 +1182,7 @@ int main(int argc, char* argv[]) fprintf(stderr, "failed to add torrent: %s\n", ec.message().c_str()); continue; } + non_files.insert(h); h.set_max_connections(max_connections_per_torrent); h.set_max_uploads(-1); @@ -1202,6 +1213,7 @@ int main(int argc, char* argv[]) fprintf(stderr, "%s\n", ec.message().c_str()); continue; } + non_files.insert(h); h.set_max_connections(max_connections_per_torrent); h.set_max_uploads(-1); @@ -1213,7 +1225,7 @@ int main(int argc, char* argv[]) } // if it's a torrent file, open it as usual - add_torrent(ses, files, i->c_str(), preferred_ratio + add_torrent(ses, files, non_files, i->c_str(), preferred_ratio , allocation_mode, save_path, false , torrent_upload_limit, torrent_download_limit); } @@ -1438,7 +1450,7 @@ int main(int argc, char* argv[]) std::string event_string; ::print_alert(a.get(), event_string); - ::handle_alert(ses, a.get(), files); + ::handle_alert(ses, a.get(), files, non_files); events.push_back(event_string); if (events.size() >= 20) events.pop_front(); @@ -1480,7 +1492,7 @@ int main(int argc, char* argv[]) torrent_status& s = *i; if (!s.handle.is_valid()) { - handles.erase(i++); + i = handles.erase(i); continue; } else