From a7e6ec4b06648f9bdcfda3f5510dbc856dc451a1 Mon Sep 17 00:00:00 2001 From: Andrew Resch Date: Thu, 29 Nov 2007 06:02:33 +0000 Subject: [PATCH] Sync libtorrent to 0.13RC Update python bindings to support wait_for_alert() and scrape_tracker() plus associated alerts. This modifies lt's wait_for_alert() to return a std::auto_ptr. --- TODO | 2 ++ libtorrent/bindings/python/src/alert.cpp | 13 +++++++++++ libtorrent/bindings/python/src/docstrings.cpp | 13 +++++++++++ libtorrent/bindings/python/src/session.cpp | 3 +++ .../bindings/python/src/torrent_handle.cpp | 1 + libtorrent/include/libtorrent/alert.hpp | 2 +- .../include/libtorrent/aux_/session_impl.hpp | 2 +- libtorrent/include/libtorrent/session.hpp | 2 +- libtorrent/src/alert.cpp | 10 ++++----- libtorrent/src/session.cpp | 2 +- libtorrent/src/session_impl.cpp | 22 ++++++++++++++++++- 11 files changed, 62 insertions(+), 10 deletions(-) diff --git a/TODO b/TODO index c60a020ce..252720714 100644 --- a/TODO +++ b/TODO @@ -23,4 +23,6 @@ * Add filtering to torrentview to use with the sidebar * Fix up preferences for when using a remote host.. the download folders, etc.. * Add decay items to statusbar.. items that will disappear after X seconds +* Do not update UI when minimized or hidden +* Add command line option to change config dir.. --config diff --git a/libtorrent/bindings/python/src/alert.cpp b/libtorrent/bindings/python/src/alert.cpp index 722cee461..aec3884e0 100755 --- a/libtorrent/bindings/python/src/alert.cpp +++ b/libtorrent/bindings/python/src/alert.cpp @@ -39,6 +39,8 @@ extern char const* portmap_error_alert_doc; extern char const* portmap_alert_doc; extern char const* fastresume_rejected_alert_doc; extern char const* peer_blocked_alert_doc; +extern char const* scrape_reply_alert_doc; +extern char const* scrape_failed_alert_doc; void bind_alert() { @@ -210,4 +212,15 @@ void bind_alert() ) .def_readonly("ip", &peer_blocked_alert::ip) ; + + class_, noncopyable>( + "scrape_reply_alert", scrape_reply_alert_doc, no_init + ) + .def_readonly("incomplete", &scrape_reply_alert::incomplete) + .def_readonly("complete", &scrape_reply_alert::complete) + ; + + class_, noncopyable>( + "scrape_failed_alert", scrape_failed_alert_doc, no_init + ); } diff --git a/libtorrent/bindings/python/src/docstrings.cpp b/libtorrent/bindings/python/src/docstrings.cpp index 7b6b9d640..f2aa7bfd0 100755 --- a/libtorrent/bindings/python/src/docstrings.cpp +++ b/libtorrent/bindings/python/src/docstrings.cpp @@ -177,6 +177,9 @@ char const* session_start_natpmp_doc = ""; char const* session_stop_natpmp_doc = ""; +char const* session_wait_for_alert_doc = + ""; + // -- alert ----------------------------------------------------------------- char const* alert_doc = @@ -321,3 +324,13 @@ char const* fastresume_rejected_alert_doc = char const* peer_blocked_alert_doc = ""; + +char const* scrape_reply_alert_doc = + "This alert is generated when a scrape request succeeds.\n" + "incomplete and complete is the data returned in the scrape\n" + "response. These numbers may be -1 if the reponse was malformed."; + +char const* scrape_failed_alert_doc = + "If a scrape request fails, this alert is generated. This might\n" + "be due to the tracker timing out, refusing connection or returning\n" + "an http response code indicating an error."; diff --git a/libtorrent/bindings/python/src/session.cpp b/libtorrent/bindings/python/src/session.cpp index 481348730..1b9f0ffc3 100755 --- a/libtorrent/bindings/python/src/session.cpp +++ b/libtorrent/bindings/python/src/session.cpp @@ -5,6 +5,7 @@ #include #include #include +#include #include #include "gil.hpp" @@ -56,6 +57,7 @@ extern char const* session_stop_lsd_doc; extern char const* session_stop_upnp_doc; extern char const* session_start_natpmp_doc; extern char const* session_stop_natpmp_doc; +extern char const* session_wait_for_alert_doc; namespace { @@ -248,6 +250,7 @@ void bind_session() .def("stop_lsd", allow_threads(&session::stop_lsd), session_stop_lsd_doc) .def("start_natpmp", allow_threads(&session::start_natpmp), session_start_natpmp_doc) .def("stop_natpmp", allow_threads(&session::stop_natpmp), session_stop_natpmp_doc) + .def("wait_for_alert", allow_threads(&session::wait_for_alert), session_wait_for_alert_doc) ; register_ptr_to_python >(); diff --git a/libtorrent/bindings/python/src/torrent_handle.cpp b/libtorrent/bindings/python/src/torrent_handle.cpp index 98540a5f8..b199e86c8 100755 --- a/libtorrent/bindings/python/src/torrent_handle.cpp +++ b/libtorrent/bindings/python/src/torrent_handle.cpp @@ -190,6 +190,7 @@ void bind_torrent_handle() .def("prioritize_files", prioritize_files) .def("get_peer_info", get_peer_info) .def("get_download_queue", get_download_queue) + .def("scrape_tracker", (&torrent_handle::scrape_tracker)) ; } diff --git a/libtorrent/include/libtorrent/alert.hpp b/libtorrent/include/libtorrent/alert.hpp index ab8065f1f..896443aaa 100755 --- a/libtorrent/include/libtorrent/alert.hpp +++ b/libtorrent/include/libtorrent/alert.hpp @@ -100,7 +100,7 @@ namespace libtorrent { void set_severity(alert::severity_t severity); bool should_post(alert::severity_t severity) const; - alert const* wait_for_alert(time_duration max_wait); + std::auto_ptr wait_for_alert(time_duration max_wait); private: std::queue m_alerts; diff --git a/libtorrent/include/libtorrent/aux_/session_impl.hpp b/libtorrent/include/libtorrent/aux_/session_impl.hpp index cf627c70b..803d78e00 100644 --- a/libtorrent/include/libtorrent/aux_/session_impl.hpp +++ b/libtorrent/include/libtorrent/aux_/session_impl.hpp @@ -280,7 +280,7 @@ namespace libtorrent void set_severity_level(alert::severity_t s); std::auto_ptr pop_alert(); - alert const* wait_for_alert(time_duration max_wait); + std::auto_ptr wait_for_alert(time_duration max_wait); int upload_rate_limit() const; int download_rate_limit() const; diff --git a/libtorrent/include/libtorrent/session.hpp b/libtorrent/include/libtorrent/session.hpp index d2ab6ab2e..b9a726fb8 100755 --- a/libtorrent/include/libtorrent/session.hpp +++ b/libtorrent/include/libtorrent/session.hpp @@ -265,7 +265,7 @@ namespace libtorrent std::auto_ptr pop_alert(); void set_severity_level(alert::severity_t s); - alert const* wait_for_alert(time_duration max_wait); + std::auto_ptr wait_for_alert(time_duration max_wait); connection_queue& get_connection_queue(); diff --git a/libtorrent/src/alert.cpp b/libtorrent/src/alert.cpp index cb89147da..5b0f892f8 100755 --- a/libtorrent/src/alert.cpp +++ b/libtorrent/src/alert.cpp @@ -78,11 +78,11 @@ namespace libtorrent { } } - alert const* alert_manager::wait_for_alert(time_duration max_wait) + std::auto_ptr alert_manager::wait_for_alert(time_duration max_wait) { boost::mutex::scoped_lock lock(m_mutex); - if (!m_alerts.empty()) return m_alerts.front(); + if (!m_alerts.empty()) return std::auto_ptr(m_alerts.front()); int secs = total_seconds(max_wait); max_wait -= seconds(secs); @@ -96,10 +96,10 @@ namespace libtorrent { xt.sec += 1; } xt.nsec = nsec; - if (!m_condition.timed_wait(lock, xt)) return 0; + if (!m_condition.timed_wait(lock, xt)) return std::auto_ptr(NULL); TORRENT_ASSERT(!m_alerts.empty()); - if (m_alerts.empty()) return 0; - return m_alerts.front(); + if (m_alerts.empty()) return std::auto_ptr(NULL); + return std::auto_ptr(m_alerts.front()); } void alert_manager::post_alert(const alert& alert_) diff --git a/libtorrent/src/session.cpp b/libtorrent/src/session.cpp index 331ffa377..8efad6b0d 100755 --- a/libtorrent/src/session.cpp +++ b/libtorrent/src/session.cpp @@ -422,7 +422,7 @@ namespace libtorrent return m_impl->pop_alert(); } - alert const* session::wait_for_alert(time_duration max_wait) + std::auto_ptr session::wait_for_alert(time_duration max_wait) { return m_impl->wait_for_alert(max_wait); } diff --git a/libtorrent/src/session_impl.cpp b/libtorrent/src/session_impl.cpp index 833d49777..fdaacfabc 100755 --- a/libtorrent/src/session_impl.cpp +++ b/libtorrent/src/session_impl.cpp @@ -766,6 +766,8 @@ namespace detail mutex::scoped_lock l2(m_checker_impl.m_mutex); // abort the checker thread m_checker_impl.m_abort = true; + + m_io_service.stop(); } void session_impl::set_port_filter(port_filter const& f) @@ -1572,6 +1574,24 @@ namespace detail } while (!m_abort); + ptime end = time_now() + seconds(m_settings.stop_tracker_timeout); + while (time_now() < end && !m_tracker_manager.empty()) + { + m_io_service.reset(); + m_io_service.poll(); + // sleep 200 milliseconds + boost::xtime xt; + boost::xtime_get(&xt, boost::TIME_UTC); + boost::int64_t nsec = xt.nsec + 200 * 1000000; + if (nsec > 1000000000) + { + nsec -= 1000000000; + xt.sec += 1; + } + xt.nsec = nsec; + boost::thread::sleep(xt); + } + #if defined(TORRENT_VERBOSE_LOGGING) || defined(TORRENT_LOGGING) (*m_logger) << time_now_string() << " locking mutex\n"; #endif @@ -2252,7 +2272,7 @@ namespace detail return std::auto_ptr(0); } - alert const* session_impl::wait_for_alert(time_duration max_wait) + std::auto_ptr session_impl::wait_for_alert(time_duration max_wait) { return m_alerts.wait_for_alert(max_wait); }