diff --git a/examples/client_test.cpp b/examples/client_test.cpp index adc36d99b..857dd5f11 100644 --- a/examples/client_test.cpp +++ b/examples/client_test.cpp @@ -651,6 +651,7 @@ int poll_interval = 5; int max_connections_per_torrent = 50; bool share_mode = false; +bool disable_storage = false; using boost::bind; @@ -683,6 +684,7 @@ void add_torrent(libtorrent::session& ses printf("%s\n", t->name().c_str()); add_torrent_params p; + if (disable_storage) p.storage = disabled_storage_constructor; p.share_mode = share_mode; lazy_entry resume_data; @@ -1034,6 +1036,7 @@ int main(int argc, char* argv[]) " -O Disallow disk job reordering\n" " -j disable disk read-ahead\n" " -z disable piece hash checks (used for benchmarking)\n" + " -0 disable disk I/O, read garbage and don't flush to disk\n" "\n\n" "TORRENT is a path to a .torrent file\n" "MAGNETURL is a magnet link\n" @@ -1110,6 +1113,7 @@ int main(int argc, char* argv[]) from_hex(argv[i], 40, (char*)&info_hash[0]); add_torrent_params p; + if (disable_storage) p.storage = disabled_storage_constructor; p.share_mode = share_mode; p.tracker_url = argv[i] + 41; p.info_hash = info_hash; @@ -1253,6 +1257,7 @@ int main(int argc, char* argv[]) settings.active_limit = (std::max)(atoi(arg) * 2, settings.active_limit); break; case 'q': loop_limit = atoi(arg); break; + case '0': disable_storage = true; --i; } ++i; // skip the argument } @@ -1330,6 +1335,7 @@ int main(int argc, char* argv[]) || std::strstr(i->c_str(), "magnet:") == i->c_str()) { add_torrent_params p; + if (disable_storage) p.storage = disabled_storage_constructor; p.share_mode = share_mode; p.save_path = save_path; p.storage_mode = (storage_mode_t)allocation_mode; diff --git a/examples/connection_tester.cpp b/examples/connection_tester.cpp index 20758148a..4a709ce5b 100644 --- a/examples/connection_tester.cpp +++ b/examples/connection_tester.cpp @@ -356,8 +356,9 @@ void print_usage() fprintf(stderr, "usage: connection_tester command ...\n\n" "command is one of:\n" " gen-torrent generate a test torrent\n" - " this command takes one extra argument, specifying the file to save\n" - " the .torrent file to\n\n" + " this command takes two extra arguments:\n" + " 1. the size of the torrent in megabytes\n" + " 2. the file to save the .torrent file to\n\n" " upload start an uploader test\n" " download start a downloader test\n" " dual start a download and upload test\n" @@ -367,20 +368,20 @@ void print_usage() " 3. destination-port - the port the target listens on\n" " 4. torrent-file - the torrent file previously generated by gen-torrent\n\n" "examples:\n\n" - "connection_tester gen-torrent test.torrent\n" + "connection_tester gen-torrent 1024 test.torrent\n" "connection_tester upload 200 127.0.0.1 6881 test.torrent\n" "connection_tester download 200 127.0.0.1 6881 test.torrent\n" "connection_tester dual 200 127.0.0.1 6881 test.torrent\n"); exit(1); } -void generate_torrent(std::vector& buf) +// size is in megabytes +void generate_torrent(std::vector& buf, int size) { file_storage fs; // 1 MiB piece size const int piece_size = 1024 * 1024; - // 30 GiB should be enough to not fit in physical RAM - const int num_pieces = 30 * 1024; + const int num_pieces = size; const size_type total_size = size_type(piece_size) * num_pieces; fs.add_file("stress_test_file", total_size); libtorrent::create_torrent t(fs, piece_size); @@ -413,14 +414,15 @@ int main(int argc, char* argv[]) if (strcmp(argv[1], "gen-torrent") == 0) { - if (argc != 3) print_usage(); + if (argc != 4) print_usage(); + int size = atoi(argv[2]); std::vector tmp; - generate_torrent(tmp); + generate_torrent(tmp, size ? size : 1024); FILE* output = stdout; - if (strcmp("-", argv[2]) != 0) - output = fopen(argv[2], "wb+"); + if (strcmp("-", argv[3]) != 0) + output = fopen(argv[3], "wb+"); fwrite(&tmp[0], 1, tmp.size(), output); if (output != stdout) fclose(output);