From 96700c15ff541452cc477c06d11ccada6444bb63 Mon Sep 17 00:00:00 2001 From: d_komarov Date: Wed, 16 May 2018 23:05:25 +0300 Subject: [PATCH 1/3] Set http request timeout to 5 seconds Fixes random test failures in test_http_connection. --- test/test_http_connection.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/test_http_connection.cpp b/test/test_http_connection.cpp index 722c45338..66d1fdedd 100644 --- a/test/test_http_connection.cpp +++ b/test/test_http_connection.cpp @@ -121,7 +121,7 @@ void run_test(std::string const& url, int size, int status, int connected boost::shared_ptr h(new http_connection(ios , res, &::http_handler, true, 1024*1024, &::http_connect_handler)); - h->get(url, seconds(1), 0, &ps, 5, "test/user-agent", boost::none, 0, auth); + h->get(url, seconds(5), 0, &ps, 5, "test/user-agent", boost::none, 0, auth); ios.reset(); error_code e; ios.run(e); From 5f74b6e35328a07e2b2544a24c802c7cea02dd32 Mon Sep 17 00:00:00 2001 From: d_komarov Date: Mon, 14 May 2018 22:00:35 +0300 Subject: [PATCH 2/3] Bump `file_error_alert` priority This alert's priority must be higher than `block_downloading_alert`'s to allow custom handling of file errors. With progress notifications enabled, network thread might fully load alerts queue, so file errors from disk thread won't have a chance to be delivered. --- include/libtorrent/alert_types.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/libtorrent/alert_types.hpp b/include/libtorrent/alert_types.hpp index 061a67cdb..b44831327 100644 --- a/include/libtorrent/alert_types.hpp +++ b/include/libtorrent/alert_types.hpp @@ -1158,7 +1158,7 @@ namespace libtorrent , char const* op , torrent_handle const& h); - TORRENT_DEFINE_ALERT(file_error_alert, 43) + TORRENT_DEFINE_ALERT_PRIO(file_error_alert, 43, alert_priority_high) static const int static_category = alert::status_notification | alert::error_notification From 54f00ce09dadae5d265c209a13d1e87322d68577 Mon Sep 17 00:00:00 2001 From: Steven Siloti Date: Fri, 18 May 2018 09:57:36 -0700 Subject: [PATCH 3/3] don't change state to downloading if the torrent is finished Move the transition to downloading after the torrent has been checked for being finished. This prevents a spurious state_changed_alert when adding a torrent which is already completed. Also move the posting of the torrent_checked_alert to maintain the historical ordering of that alert with respect to the transition out of checking_resume_data. --- src/torrent.cpp | 36 ++++++++++++++++++------------------ 1 file changed, 18 insertions(+), 18 deletions(-) diff --git a/src/torrent.cpp b/src/torrent.cpp index fee1f047b..99fcc5781 100644 --- a/src/torrent.cpp +++ b/src/torrent.cpp @@ -8829,24 +8829,6 @@ namespace { return; } - // we might be finished already, in which case we should - // not switch to downloading mode. If all files are - // filtered, we're finished when we start. - if (m_state != torrent_status::finished - && m_state != torrent_status::seeding - && !m_seed_mode) - { - set_state(torrent_status::downloading); - } - - INVARIANT_CHECK; - - if (m_ses.alerts().should_post()) - { - m_ses.alerts().emplace_alert( - get_handle()); - } - // calling pause will also trigger the auto managed // recalculation // if we just got here by downloading the metadata, @@ -8883,6 +8865,24 @@ namespace { finished(); } + // we might be finished already, in which case we should + // not switch to downloading mode. If all files are + // filtered, we're finished when we start. + if (m_state != torrent_status::finished + && m_state != torrent_status::seeding + && !m_seed_mode) + { + set_state(torrent_status::downloading); + } + + INVARIANT_CHECK; + + if (m_ses.alerts().should_post()) + { + m_ses.alerts().emplace_alert( + get_handle()); + } + #ifndef TORRENT_DISABLE_EXTENSIONS for (extension_list_t::iterator i = m_extensions.begin() , end(m_extensions.end()); i != end; ++i)