improved disk error handling and expanded use of error_code in error reporting
This commit is contained in:
@@ -55,12 +55,12 @@ void test_transfer(boost::intrusive_ptr<torrent_info> torrent_file, int proxy)
|
||||
session ses(fingerprint(" ", 0,0,0,0), 0);
|
||||
session_settings settings;
|
||||
settings.ignore_limits_on_local_network = false;
|
||||
settings.max_outstanding_disk_bytes_per_connection = 256 * 1024;
|
||||
settings.max_queued_disk_bytes = 256 * 1024;
|
||||
ses.set_settings(settings);
|
||||
ses.set_alert_mask(~alert::progress_notification);
|
||||
ses.listen_on(std::make_pair(51000, 52000));
|
||||
ses.set_download_rate_limit(torrent_file->total_size() / 10);
|
||||
remove_all("./tmp1");
|
||||
remove_all("./tmp2_web_seed");
|
||||
|
||||
char const* test_name[] = {"no", "SOCKS4", "SOCKS5", "SOCKS5 password", "HTTP", "HTTP password"};
|
||||
|
||||
@@ -78,7 +78,7 @@ void test_transfer(boost::intrusive_ptr<torrent_info> torrent_file, int proxy)
|
||||
ses.set_web_seed_proxy(ps);
|
||||
}
|
||||
|
||||
torrent_handle th = ses.add_torrent(*torrent_file, "./tmp1");
|
||||
torrent_handle th = ses.add_torrent(*torrent_file, "./tmp2_web_seed");
|
||||
|
||||
std::vector<announce_entry> empty;
|
||||
th.replace_trackers(empty);
|
||||
@@ -94,12 +94,20 @@ void test_transfer(boost::intrusive_ptr<torrent_info> torrent_file, int proxy)
|
||||
session_status ss = ses.status();
|
||||
rate_sum += s.download_payload_rate;
|
||||
ses_rate_sum += ss.payload_download_rate;
|
||||
|
||||
cache_status cs = ses.get_cache_status();
|
||||
if (cs.blocks_read < 1) cs.blocks_read = 1;
|
||||
if (cs.blocks_written < 1) cs.blocks_written = 1;
|
||||
|
||||
std::cerr << (s.progress * 100.f) << " %"
|
||||
<< " torrent rate: " << (s.download_rate / 1000.f) << " kB/s"
|
||||
<< " session rate: " << (ss.download_rate / 1000.f) << " kB/s"
|
||||
<< " session total: " << ss.total_payload_download
|
||||
<< " torrent total: " << s.total_payload_download
|
||||
<< " rate sum:" << ses_rate_sum
|
||||
<< " cache: " << cs.cache_size
|
||||
<< " rcache: " << cs.read_cache_size
|
||||
<< " buffers: " << cs.total_used_buffers
|
||||
<< std::endl;
|
||||
|
||||
print_alerts(ses, "ses");
|
||||
@@ -126,8 +134,8 @@ void test_transfer(boost::intrusive_ptr<torrent_info> torrent_file, int proxy)
|
||||
|
||||
if (proxy) stop_proxy(8002);
|
||||
|
||||
TEST_CHECK(exists("./tmp1" / torrent_file->file_at(0).path));
|
||||
remove_all("./tmp1");
|
||||
TEST_CHECK(exists("./tmp2_web_seed" / torrent_file->file_at(0).path));
|
||||
remove_all("./tmp2_web_seed");
|
||||
}
|
||||
|
||||
int test_main()
|
||||
@@ -136,54 +144,45 @@ int test_main()
|
||||
using namespace boost::filesystem;
|
||||
|
||||
try {
|
||||
create_directory("test_torrent_dir");
|
||||
create_directory("./tmp1_web_seed");
|
||||
} catch (std::exception&) {}
|
||||
|
||||
try {
|
||||
create_directory("./tmp1_web_seed/test_torrent_dir");
|
||||
} catch (std::exception&) {}
|
||||
|
||||
char random_data[300000];
|
||||
std::srand(std::time(0));
|
||||
std::srand(10);
|
||||
// memset(random_data, 1, sizeof(random_data));
|
||||
std::generate(random_data, random_data + sizeof(random_data), &std::rand);
|
||||
std::ofstream("./test_torrent_dir/test1").write(random_data, 35);
|
||||
std::ofstream("./test_torrent_dir/test2").write(random_data, 16536 - 35);
|
||||
std::ofstream("./test_torrent_dir/test3").write(random_data, 16536);
|
||||
std::ofstream("./test_torrent_dir/test4").write(random_data, 17);
|
||||
std::ofstream("./test_torrent_dir/test5").write(random_data, 16536);
|
||||
std::ofstream("./test_torrent_dir/test6").write(random_data, 300000);
|
||||
std::ofstream("./test_torrent_dir/test7").write(random_data, 300000);
|
||||
std::ofstream("./tmp1_web_seed/test_torrent_dir/test1").write(random_data, 35);
|
||||
std::ofstream("./tmp1_web_seed/test_torrent_dir/test2").write(random_data, 16536 - 35);
|
||||
std::ofstream("./tmp1_web_seed/test_torrent_dir/test3").write(random_data, 16536);
|
||||
std::ofstream("./tmp1_web_seed/test_torrent_dir/test4").write(random_data, 17);
|
||||
std::ofstream("./tmp1_web_seed/test_torrent_dir/test5").write(random_data, 16536);
|
||||
std::ofstream("./tmp1_web_seed/test_torrent_dir/test6").write(random_data, 300000);
|
||||
std::ofstream("./tmp1_web_seed/test_torrent_dir/test7").write(random_data, 300000);
|
||||
|
||||
file_storage fs;
|
||||
add_files(fs, path("test_torrent_dir"));
|
||||
add_files(fs, path("./tmp1_web_seed/test_torrent_dir"));
|
||||
|
||||
libtorrent::create_torrent t(fs, 16 * 1024);
|
||||
t.add_url_seed("http://127.0.0.1:8000/");
|
||||
t.add_url_seed("http://127.0.0.1:8000/tmp1_web_seed");
|
||||
|
||||
start_web_server(8000);
|
||||
|
||||
// calculate the hash for all pieces
|
||||
int num = t.num_pieces();
|
||||
char* buf = page_aligned_allocator::malloc(t.piece_length());
|
||||
|
||||
file_pool fp;
|
||||
boost::scoped_ptr<storage_interface> s(default_storage_constructor(
|
||||
fs, ".", fp));
|
||||
|
||||
for (int i = 0; i < num; ++i)
|
||||
{
|
||||
s->read(buf, i, 0, fs.piece_size(i));
|
||||
hasher h(buf, fs.piece_size(i));
|
||||
t.set_hash(i, h.final());
|
||||
}
|
||||
|
||||
set_piece_hashes(t, "./tmp1_web_seed");
|
||||
boost::intrusive_ptr<torrent_info> torrent_file(new torrent_info(t.generate()));
|
||||
|
||||
for (int i = 0; i < 6; ++i)
|
||||
test_transfer(torrent_file, i);
|
||||
|
||||
torrent_file->rename_file(0, "./test_torrent_dir/renamed_test1");
|
||||
torrent_file->rename_file(0, "./tmp2_web_seed/test_torrent_dir/renamed_test1");
|
||||
test_transfer(torrent_file, 0);
|
||||
|
||||
stop_web_server(8000);
|
||||
remove_all("./test_torrent_dir");
|
||||
page_aligned_allocator::free(buf);
|
||||
remove_all("./tmp1_web_seed");
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user