From 36c9add0671ebbdced02351acea200febce05057 Mon Sep 17 00:00:00 2001 From: Arvid Norberg Date: Sun, 26 Jan 2014 08:18:13 +0000 Subject: [PATCH] don't print stuff to stdout in debug builds. when waking up from completing a connection attempt, exit immediately if the connection is disconnecting, or disconnect if we're in graceful pause mode. some test cleanups --- src/bt_peer_connection.cpp | 14 ++++++++++++++ src/disk_io_thread.cpp | 3 --- test/setup_transfer.cpp | 32 ++++++++++++++++++-------------- test/test_transfer.cpp | 15 ++++++++++++--- 4 files changed, 44 insertions(+), 20 deletions(-) diff --git a/src/bt_peer_connection.cpp b/src/bt_peer_connection.cpp index c5f5500ae..981c0ec67 100644 --- a/src/bt_peer_connection.cpp +++ b/src/bt_peer_connection.cpp @@ -159,6 +159,20 @@ namespace libtorrent void bt_peer_connection::on_connected() { + if (is_disconnecting()) return; + + boost::shared_ptr t = associated_torrent().lock(); + TORRENT_ASSERT(t); + + if (t->graceful_pause()) + { +#ifdef TORRENT_VERBOSE_LOGGING + peer_log("*** ON_CONNECTED [ graceful-paused ]"); +#endif + disconnect(error_code(errors::torrent_paused), 0); + return; + } + #ifndef TORRENT_DISABLE_ENCRYPTION boost::uint8_t out_enc_policy = m_ses.get_pe_settings().out_enc_policy; diff --git a/src/disk_io_thread.cpp b/src/disk_io_thread.cpp index 693c4bb00..111a0f2aa 100644 --- a/src/disk_io_thread.cpp +++ b/src/disk_io_thread.cpp @@ -1389,9 +1389,6 @@ namespace libtorrent j.str.clear(); j.error = ec; j.error_file = j.storage->error_file(); -#ifdef TORRENT_DEBUG - printf("ERROR: '%s' in %s\n", ec.message().c_str(), j.error_file.c_str()); -#endif j.storage->clear_error(); return true; } diff --git a/test/setup_transfer.cpp b/test/setup_transfer.cpp index 66a523481..f9fe6f4cc 100644 --- a/test/setup_transfer.cpp +++ b/test/setup_transfer.cpp @@ -279,25 +279,29 @@ void print_ses_rate(float time , libtorrent::torrent_status const* st2 , libtorrent::torrent_status const* st3) { - fprintf(stderr, "%3.1fs | %dkB/s %dkB/s %d%% %d", time + fprintf(stderr, "%3.1fs | %dkB/s %dkB/s %d%% %d cc:%d%s", time , int(st1->download_payload_rate / 1000) , int(st1->upload_payload_rate / 1000) , int(st1->progress * 100) - , st1->num_peers); + , st1->num_peers + , st1->connect_candidates + , st1->error.empty() ? "" : (" [" + st1->error + "]").c_str()); if (st2) - std::cerr << " : " - << int(st2->download_payload_rate / 1000.f) << "kB/s " - << int(st2->upload_payload_rate / 1000.f) << "kB/s " - << int(st2->progress * 100) << "% " - << st2->num_peers - << " cc: " << st2->connect_candidates; + fprintf(stderr, " : %3.1fs | %dkB/s %dkB/s %d%% %d cc:%d%s", time + , int(st2->download_payload_rate / 1000) + , int(st2->upload_payload_rate / 1000) + , int(st2->progress * 100) + , st2->num_peers + , st2->connect_candidates + , st2->error.empty() ? "" : (" [" + st2->error + "]").c_str()); if (st3) - std::cerr << " : " - << int(st3->download_payload_rate / 1000.f) << "kB/s " - << int(st3->upload_payload_rate / 1000.f) << "kB/s " - << int(st3->progress * 100) << "% " - << st3->num_peers - << " cc: " << st3->connect_candidates; + fprintf(stderr, " : %3.1fs | %dkB/s %dkB/s %d%% %d cc:%d%s", time + , int(st3->download_payload_rate / 1000) + , int(st3->upload_payload_rate / 1000) + , int(st3->progress * 100) + , st3->num_peers + , st3->connect_candidates + , st3->error.empty() ? "" : (" [" + st3->error + "]").c_str()); fprintf(stderr, "\n"); } diff --git a/test/test_transfer.cpp b/test/test_transfer.cpp index c347a1b48..0319f6f01 100644 --- a/test/test_transfer.cpp +++ b/test/test_transfer.cpp @@ -172,6 +172,7 @@ storage_interface* test_storage_constructor(file_storage const& fs void test_transfer(int proxy_type, bool test_disk_full = false, bool test_allowed_fast = false) { + static int listen_port = 0; char const* test_name[] = {"no", "SOCKS4", "SOCKS5", "SOCKS5 password", "HTTP", "HTTP password"}; @@ -191,8 +192,11 @@ void test_transfer(int proxy_type, bool test_disk_full = false, bool test_allowe session_proxy p1; session_proxy p2; - session ses1(fingerprint("LT", 0, 1, 0, 0), std::make_pair(48075, 49000), "0.0.0.0", 0, alert_mask); - session ses2(fingerprint("LT", 0, 1, 0, 0), std::make_pair(49075, 50000), "0.0.0.0", 0, alert_mask); + session ses1(fingerprint("LT", 0, 1, 0, 0) + , std::make_pair(48075 + listen_port, 49000), "0.0.0.0", 0, alert_mask); + session ses2(fingerprint("LT", 0, 1, 0, 0) + , std::make_pair(49075 + listen_port, 50000), "0.0.0.0", 0, alert_mask); + ++listen_port; proxy_settings ps; if (proxy_type) @@ -316,11 +320,16 @@ void test_transfer(int proxy_type, bool test_disk_full = false, bool test_allowe // upload mode to false test_sleep(500); + // then we need to drain the alert queue, so the peer_disconnects + // counter doesn't get incremented by old alerts + print_alerts(ses1, "ses1", true, true, true, &on_alert); + print_alerts(ses2, "ses2", true, true, true, &on_alert); + tor2.set_upload_mode(false); TEST_CHECK(tor2.status().is_finished == false); TEST_EQUAL(peer_disconnects, 2); fprintf(stderr, "%s: discovered disk full mode. Raise limit and disable upload-mode\n", time_now_string()); - peer_disconnects = -1; + peer_disconnects = 0; test_sleep(100); continue; }