From 3988a443ff14cb286abd7c2662925ca352ffffa8 Mon Sep 17 00:00:00 2001 From: arvidn Date: Sun, 22 May 2016 02:20:49 -0400 Subject: [PATCH 1/5] add test of paused session --- test/test_session.cpp | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/test/test_session.cpp b/test/test_session.cpp index e5632d7b2..b535ce88d 100644 --- a/test/test_session.cpp +++ b/test/test_session.cpp @@ -125,6 +125,25 @@ TORRENT_TEST(session_stats) } } +TORRENT_TEST(paused_session) +{ + lt::session s; + s.pause(); + + lt::add_torrent_params ps; + ps.info_hash.assign("abababababababababab"); + ps.flags = lt::add_torrent_params::flag_paused; + ps.save_path = "."; + + torrent_handle h = s.add_torrent(ps); + + test_sleep(2000); + h.resume(); + test_sleep(1000); + + TEST_CHECK(!h.is_paused()); +} + #if __cplusplus >= 201103L template From b5fc367d17686c71e79564581c7bbea1eb8ed7b6 Mon Sep 17 00:00:00 2001 From: Arvid Norberg Date: Sun, 22 May 2016 13:46:37 -0400 Subject: [PATCH 2/5] fix incorrect comparison function when deciding which peer to disconnect (#746) fix incorrect comparison function when deciding which peer to disconnect --- src/session_impl.cpp | 8 ++++++-- test/test_session.cpp | 10 ++++++++-- test/test_torrent_info.cpp | 8 +++++++- 3 files changed, 21 insertions(+), 5 deletions(-) diff --git a/src/session_impl.cpp b/src/session_impl.cpp index 5f1bc81b6..13cc7a3b2 100644 --- a/src/session_impl.cpp +++ b/src/session_impl.cpp @@ -2555,8 +2555,12 @@ retry: { // now, disconnect a random peer torrent_map::iterator i = std::max_element(m_torrents.begin() - , m_torrents.end(), boost::bind(&torrent::num_peers - , boost::bind(&torrent_map::value_type::second, _1))); + , m_torrents.end() + , boost::bind(&torrent::num_peers + , boost::bind(&torrent_map::value_type::second, _1)) + < boost::bind(&torrent::num_peers + , boost::bind(&torrent_map::value_type::second, _2)) + ); if (m_alerts.should_post()) m_alerts.emplace_alert( diff --git a/test/test_session.cpp b/test/test_session.cpp index b535ce88d..e062ec69e 100644 --- a/test/test_session.cpp +++ b/test/test_session.cpp @@ -31,7 +31,13 @@ POSSIBILITY OF SUCH DAMAGE. */ #include "libtorrent/session.hpp" + +#include "libtorrent/aux_/disable_warnings_push.hpp" + #include +#include + +#include "libtorrent/aux_/disable_warnings_pop.hpp" #include "test.hpp" #include "setup_transfer.hpp" @@ -101,7 +107,7 @@ TORRENT_TEST(load_empty_file) add_torrent_params atp; error_code ignore_errors; - atp.ti = boost::make_shared("", 0, ignore_errors); + atp.ti = boost::make_shared("", 0, boost::ref(ignore_errors)); atp.save_path = "."; error_code ec; torrent_handle h = ses.add_torrent(atp, ec); @@ -141,7 +147,7 @@ TORRENT_TEST(paused_session) h.resume(); test_sleep(1000); - TEST_CHECK(!h.is_paused()); + TEST_CHECK(!h.status().paused); } #if __cplusplus >= 201103L diff --git a/test/test_torrent_info.cpp b/test/test_torrent_info.cpp index d43c296d2..51f8ff471 100644 --- a/test/test_torrent_info.cpp +++ b/test/test_torrent_info.cpp @@ -36,7 +36,13 @@ POSSIBILITY OF SUCH DAMAGE. #include "libtorrent/create_torrent.hpp" #include "libtorrent/announce_entry.hpp" #include "libtorrent/aux_/escape_string.hpp" // for convert_path_to_posix + +#include "libtorrent/aux_/disable_warnings_push.hpp" + #include +#include + +#include "libtorrent/aux_/disable_warnings_pop.hpp" #if TORRENT_USE_IOSTREAM #include @@ -857,7 +863,7 @@ TORRENT_TEST(resolve_duplicates) TORRENT_TEST(empty_file) { error_code ec; - boost::shared_ptr ti = boost::make_shared("", 0, ec); + boost::shared_ptr ti = boost::make_shared("", 0, boost::ref(ec)); TEST_CHECK(ec); } From f6b18c709794b4d90e5d7b2c4f2a653ec933e95a Mon Sep 17 00:00:00 2001 From: arvidn Date: Sun, 22 May 2016 20:35:04 -0400 Subject: [PATCH 3/5] improve documentation for alert_cast --- include/libtorrent/alert.hpp | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/include/libtorrent/alert.hpp b/include/libtorrent/alert.hpp index ab6cba6cb..06b48eea5 100644 --- a/include/libtorrent/alert.hpp +++ b/include/libtorrent/alert.hpp @@ -299,8 +299,12 @@ namespace libtorrent { time_point m_timestamp; }; -// When you get an alert, you can use ``alert_cast<>`` to attempt to cast the pointer to a -// more specific alert type, in order to query it for more information. +// When you get an alert, you can use ``alert_cast<>`` to attempt to cast the +// pointer to a specific alert type, in order to query it for more +// information. +// +// .. note:: +// ``alert_cast<>`` can only cast to an exact alert type, not a base class template T* alert_cast(alert* a) { if (a == 0) return 0; From 62fb7209ef5e98d5e94d7fdee2f1495c6ee84c78 Mon Sep 17 00:00:00 2001 From: Arvid Norberg Date: Sun, 22 May 2016 22:58:11 -0400 Subject: [PATCH 4/5] fix invariant check issue with a paused session (#750) fix invariant check issue with a paused session --- src/torrent.cpp | 6 +++++- test/test_session.cpp | 5 ++++- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/src/torrent.cpp b/src/torrent.cpp index 911b0a828..8769d2b55 100644 --- a/src/torrent.cpp +++ b/src/torrent.cpp @@ -9986,7 +9986,11 @@ namespace libtorrent void torrent::do_resume() { TORRENT_ASSERT(is_single_thread()); - if (is_paused()) return; + if (is_paused()) + { + update_want_tick(); + return; + } #ifndef TORRENT_DISABLE_EXTENSIONS for (extension_list_t::iterator i = m_extensions.begin() diff --git a/test/test_session.cpp b/test/test_session.cpp index e062ec69e..21a88f6bb 100644 --- a/test/test_session.cpp +++ b/test/test_session.cpp @@ -48,6 +48,8 @@ POSSIBILITY OF SUCH DAMAGE. #include "libtorrent/bencode.hpp" #include "libtorrent/torrent_info.hpp" +#include + using namespace libtorrent; namespace lt = libtorrent; @@ -137,7 +139,8 @@ TORRENT_TEST(paused_session) s.pause(); lt::add_torrent_params ps; - ps.info_hash.assign("abababababababababab"); + std::ofstream file("temporary"); + ps.ti = ::create_torrent(&file, "temporary", 16 * 1024, 13, false); ps.flags = lt::add_torrent_params::flag_paused; ps.save_path = "."; From 3106f6f8a59d3d354a176c468a5688166330f41e Mon Sep 17 00:00:00 2001 From: Arvid Norberg Date: Mon, 23 May 2016 00:36:24 -0400 Subject: [PATCH 5/5] restore debug-iterators to be enabled by default when building the tests (#751) restore debug-iterators to be enabled by default when building the tests --- test/Jamfile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/Jamfile b/test/Jamfile index ca9e15602..819b19561 100644 --- a/test/Jamfile +++ b/test/Jamfile @@ -73,11 +73,9 @@ lib libtorrent_test windows:advapi32 @link_libtorrent darwin:-Wno-unused-command-line-argument - on : # default build shared - on : # user-requirements shared:TORRENT_LINK_TEST_SHARED @@ -98,6 +96,8 @@ project full shared on + on + on ; feature launcher : none valgrind : composite ;