deprecated a bunch of query functions on torrent_handle in favor of using status() to get as much information as possible in fewer calls, and saving time on synchronizing with the main thread

This commit is contained in:
Arvid Norberg
2010-10-30 17:23:30 +00:00
parent 415cd7fc4f
commit a76570b563
14 changed files with 171 additions and 134 deletions

View File

@@ -99,7 +99,7 @@ bool print_alerts(libtorrent::session& ses, char const* name
peer_error_alert* pea = alert_cast<peer_error_alert>(a.get());
TEST_CHECK(pea == 0
|| (!handles.empty() && h.is_seed())
|| (!handles.empty() && h.status().is_seeding)
|| pea->error.message() == "connecting to peer"
|| pea->error.message() == "closing connection to ourself"
|| pea->error.message() == "duplicate connection"

View File

@@ -61,9 +61,9 @@ void report_failure(char const* str, char const* file, int line);
TEST_REPORT_AUX("TEST_CHECK failed: \"" #x "\"", __FILE__, __LINE__);
#define TEST_EQUAL(x, y) \
if (x != y) { \
std::stringstream s; \
s << "TEST_EQUAL_ERROR: " << #x << ": " << x << " expected: " << y << std::endl; \
TEST_REPORT_AUX(s.str().c_str(), __FILE__, __LINE__); \
std::stringstream s__; \
s__ << "TEST_EQUAL_ERROR: " << #x << ": " << x << " expected: " << y << std::endl; \
TEST_REPORT_AUX(s__.str().c_str(), __FILE__, __LINE__); \
}
#else
#define TEST_CHECK(x) \
@@ -84,9 +84,9 @@ void report_failure(char const* str, char const* file, int line);
#define TEST_EQUAL(x, y) \
try { \
if (x != y) { \
std::stringstream s; \
s << "TEST_EQUAL_ERROR: " << #x << ": " << x << " expected: " << y << std::endl; \
TEST_REPORT_AUX(s.str().c_str(), __FILE__, __LINE__); \
std::stringstream s__; \
s__ << "TEST_EQUAL_ERROR: " << #x << ": " << x << " expected: " << y << std::endl; \
TEST_REPORT_AUX(s__.str().c_str(), __FILE__, __LINE__); \
} \
} \
catch (std::exception& e) \

View File

@@ -75,13 +75,13 @@ void test_lsd()
<< "\033[0m" << int(st2.progress * 100) << "% "
<< std::endl;
if (tor2.is_seed() /*&& tor3.is_seed()*/) break;
if (st2.is_seeding /*&& st3.is_seeding*/) break;
test_sleep(1000);
}
TEST_CHECK(tor2.is_seed());
TEST_CHECK(tor2.status().is_seeding);
if (tor2.is_seed()) std::cerr << "done\n";
if (tor2.status().is_seeding) std::cerr << "done\n";
}
int test_main()

View File

@@ -73,13 +73,13 @@ void test_transfer(bool clear_files, bool disconnect
print_alerts(ses2, "ses2", false, true);
if (disconnect && tor2.is_valid()) ses2.remove_torrent(tor2);
if (!disconnect && tor2.has_metadata()) break;
if (!disconnect && tor2.status().has_metadata) break;
test_sleep(100);
}
if (disconnect) return;
TEST_CHECK(tor2.has_metadata());
TEST_CHECK(tor2.status().has_metadata);
std::cerr << "waiting for transfer to complete\n";
for (int i = 0; i < 30; ++i)
@@ -95,12 +95,12 @@ void test_transfer(bool clear_files, bool disconnect
<< "\033[0m" << int(st2.progress * 100) << "% "
<< st2.num_peers
<< std::endl;
if (tor2.is_seed()) break;
if (st2.is_seeding) break;
test_sleep(1000);
}
TEST_CHECK(tor2.is_seed());
if (tor2.is_seed()) std::cerr << "done\n";
TEST_CHECK(tor2.status().is_seeding);
if (tor2.status().is_seeding) std::cerr << "done\n";
error_code ec;
remove_all("./tmp1_meta", ec);

View File

@@ -112,16 +112,16 @@ void test_transfer(libtorrent::pe_settings::enc_policy policy,
for (int i = 0; i < 50; ++i)
{
tor2.status();
torrent_status s = tor2.status();
print_alerts(ses1, "ses1");
print_alerts(ses2, "ses2");
if (tor2.is_seed()) break;
if (s.is_seeding) break;
test_sleep(1000);
}
TEST_CHECK(tor2.is_seed());
if (tor2.is_seed()) std::cerr << "done\n";
TEST_CHECK(tor2.status().is_seeding);
if (tor2.status().is_seeding) std::cerr << "done\n";
ses1.remove_torrent(tor1);
ses2.remove_torrent(tor2);

View File

@@ -135,7 +135,7 @@ void test_pex()
TEST_CHECK(st1.num_peers == 2 && st2.num_peers == 2 && st3.num_peers == 2)
if (!tor2.is_seed() && tor3.is_seed()) std::cerr << "done\n";
if (!tor2.status().is_seeding && tor3.status().is_seeding) std::cerr << "done\n";
}
int test_main()

View File

@@ -144,12 +144,12 @@ void test_swarm(bool super_seeding = false, bool strict = false, bool seed_mode
<< st3.num_peers
<< std::endl;
if (tor2.is_seed() && tor3.is_seed()) break;
if (st2.is_seeding && st3.is_seeding) break;
test_sleep(1000);
}
TEST_CHECK(tor2.is_seed());
TEST_CHECK(tor3.is_seed());
TEST_CHECK(tor2.status().is_seeding);
TEST_CHECK(tor3.status().is_seeding);
float average2 = sum_dl_rate2 / float(count_dl_rates2);
float average3 = sum_dl_rate3 / float(count_dl_rates3);
@@ -158,7 +158,7 @@ void test_swarm(bool super_seeding = false, bool strict = false, bool seed_mode
std::cerr << "average rate: " << (average2 / 1000.f) << "kB/s - "
<< (average3 / 1000.f) << "kB/s" << std::endl;
if (tor2.is_seed() && tor3.is_seed()) std::cerr << "done\n";
if (tor2.status().is_seeding && tor3.status().is_seeding) std::cerr << "done\n";
// make sure the files are deleted
ses1.remove_torrent(tor1, session::delete_files);

View File

@@ -99,11 +99,11 @@ void test_rate()
<< std::endl;
}
if (tor2.is_seed()) break;
if (st2.is_seeding) break;
test_sleep(100);
}
TEST_CHECK(tor2.is_seed());
TEST_CHECK(tor2.status().is_seeding);
time_duration dt = time_now() - start;
@@ -377,7 +377,7 @@ void test_transfer(int proxy_type, bool test_disk_full = false, bool test_allowe
continue;
}
if (!test_disk_full && tor2.is_finished()) break;
if (!test_disk_full && st2.is_finished) break;
TEST_CHECK(st1.state == torrent_status::seeding
|| st1.state == torrent_status::checking_files);
@@ -390,9 +390,9 @@ void test_transfer(int proxy_type, bool test_disk_full = false, bool test_allowe
// 1 announce per tracker to start
TEST_CHECK(tracker_responses >= 2);
TEST_CHECK(!tor2.is_seed());
TEST_CHECK(tor2.is_finished());
if (tor2.is_finished())
TEST_CHECK(!tor2.status().is_seeding);
TEST_CHECK(tor2.status().is_finished);
if (tor2.status().is_finished)
std::cerr << "torrent is finished (50% complete)" << std::endl;
std::cerr << "force recheck" << std::endl;
@@ -500,7 +500,7 @@ void test_transfer(int proxy_type, bool test_disk_full = false, bool test_allowe
test_sleep(100);
}
TEST_CHECK(!tor2.is_seed());
TEST_CHECK(!tor2.status().is_seeding);
std::fill(priorities.begin(), priorities.end(), 1);
tor2.prioritize_pieces(priorities);
@@ -530,7 +530,7 @@ void test_transfer(int proxy_type, bool test_disk_full = false, bool test_allowe
<< std::endl;
}
if (tor2.is_finished()) break;
if (tor2.status().is_finished) break;
TEST_CHECK(st1.state == torrent_status::seeding);
TEST_CHECK(st2.state == torrent_status::downloading);
@@ -538,7 +538,7 @@ void test_transfer(int proxy_type, bool test_disk_full = false, bool test_allowe
test_sleep(100);
}
TEST_CHECK(tor2.is_seed());
TEST_CHECK(tor2.status().is_seeding);
stop_tracker();
stop_web_server();

View File

@@ -120,10 +120,9 @@ void test_transfer(boost::intrusive_ptr<torrent_info> torrent_file
print_alerts(ses, " >> ses");
if (th.is_seed()/* && ss.download_rate == 0.f*/)
if (s.is_seeding /* && ss.download_rate == 0.f*/)
{
torrent_status st = th.status();
TEST_EQUAL(st.total_payload_download - st.total_redundant_bytes, total_size);
TEST_EQUAL(s.total_payload_download - s.total_redundant_bytes, total_size);
// we need to sleep here a bit to let the session sync with the torrent stats
test_sleep(1000);
TEST_EQUAL(ses.status().total_payload_download - ses.status().total_redundant_bytes
@@ -148,7 +147,7 @@ void test_transfer(boost::intrusive_ptr<torrent_info> torrent_file
// TEST_CHECK(fabs(rate_sum - total_size) < total_size * .1f);
// TEST_CHECK(fabs(ses_rate_sum - total_size) < total_size * .1f);
TEST_CHECK(th.is_seed());
TEST_CHECK(th.status().is_seeding);
if (proxy) stop_proxy(8002);