From fe7dead2df1cc7f60c90304c6b234c9455b297b6 Mon Sep 17 00:00:00 2001 From: Andrew Resch Date: Tue, 10 Jun 2008 08:02:15 +0000 Subject: [PATCH] lt sync 2397 --- libtorrent/bindings/python/src/alert.cpp | 4 ++ libtorrent/bindings/python/src/session.cpp | 2 +- .../bindings/python/src/session_settings.cpp | 7 ++ libtorrent/include/libtorrent/alert_types.hpp | 9 +++ .../include/libtorrent/disk_io_thread.hpp | 7 ++ libtorrent/include/libtorrent/session.hpp | 2 +- libtorrent/include/libtorrent/storage.hpp | 1 + libtorrent/src/disk_io_thread.cpp | 66 ++++++++++++++++++- libtorrent/src/torrent.cpp | 13 ++++ 9 files changed, 107 insertions(+), 4 deletions(-) diff --git a/libtorrent/bindings/python/src/alert.cpp b/libtorrent/bindings/python/src/alert.cpp index 397071e21..85a4fae2f 100755 --- a/libtorrent/bindings/python/src/alert.cpp +++ b/libtorrent/bindings/python/src/alert.cpp @@ -271,4 +271,8 @@ void bind_alert() ) .def_readonly("name", &file_renamed_alert::name) ; + + class_, noncopyable>( + "torrent_resumed_alert", no_init + ); } diff --git a/libtorrent/bindings/python/src/session.cpp b/libtorrent/bindings/python/src/session.cpp index 424de0508..50d433dd0 100755 --- a/libtorrent/bindings/python/src/session.cpp +++ b/libtorrent/bindings/python/src/session.cpp @@ -236,8 +236,8 @@ void bind_session() enum_("storage_mode_t") .value("storage_mode_allocate", storage_mode_allocate) - .value("storage_mode_compact", storage_mode_compact) .value("storage_mode_sparse", storage_mode_sparse) + .value("storage_mode_compact", storage_mode_compact) ; enum_("options_t") diff --git a/libtorrent/bindings/python/src/session_settings.cpp b/libtorrent/bindings/python/src/session_settings.cpp index 0d8a8be02..d697295b5 100755 --- a/libtorrent/bindings/python/src/session_settings.cpp +++ b/libtorrent/bindings/python/src/session_settings.cpp @@ -34,6 +34,13 @@ void bind_session_settings() .def_readwrite("lazy_bitfields", &session_settings::lazy_bitfields) .def_readwrite("inactivity_timeout", &session_settings::inactivity_timeout) .def_readwrite("unchoke_interval", &session_settings::unchoke_interval) + .def_readwrite("active_downloads", &session_settings::active_downloads) + .def_readwrite("active_seeds", &session_settings::active_seeds) + .def_readwrite("auto_manage_interval", &session_settings::auto_manage_interval) + .def_readwrite("share_ratio_limit", &session_settings::share_ratio_limit) + .def_readwrite("seed_time_ratio_limit", &session_settings::seed_time_ratio_limit) + .def_readwrite("seed_time_limit", &session_settings::seed_time_limit) + .def_readwrite("auto_scraped_interval", &session_settings::auto_scrape_interval) #ifndef TORRENT_DISABLE_DHT .def_readwrite("use_dht_as_fallback", &session_settings::use_dht_as_fallback) #endif diff --git a/libtorrent/include/libtorrent/alert_types.hpp b/libtorrent/include/libtorrent/alert_types.hpp index 042ec1683..1fc8116ff 100755 --- a/libtorrent/include/libtorrent/alert_types.hpp +++ b/libtorrent/include/libtorrent/alert_types.hpp @@ -544,6 +544,15 @@ namespace libtorrent { return std::auto_ptr(new peer_blocked_alert(*this)); } }; + struct TORRENT_EXPORT torrent_resumed_alert: torrent_alert + { + torrent_resumed_alert(torrent_handle const& h, std::string const& msg) + : torrent_alert(h, alert::warning, msg) + {} + + virtual std::auto_ptr clone() const + { return std::auto_ptr(new torrent_resumed_alert(*this)); } + }; } diff --git a/libtorrent/include/libtorrent/disk_io_thread.hpp b/libtorrent/include/libtorrent/disk_io_thread.hpp index 198915588..68bb8a61a 100644 --- a/libtorrent/include/libtorrent/disk_io_thread.hpp +++ b/libtorrent/include/libtorrent/disk_io_thread.hpp @@ -83,6 +83,7 @@ namespace libtorrent , check_files , save_resume_data , rename_file + , abort_thread }; action_t action; @@ -206,6 +207,12 @@ namespace libtorrent int num_blocks; // the pointers to the block data boost::shared_array blocks; +#ifndef NDEBUG + ~cached_piece_entry() + { + TORRENT_ASSERT(storage == 0); + } +#endif }; typedef boost::recursive_mutex mutex_t; diff --git a/libtorrent/include/libtorrent/session.hpp b/libtorrent/include/libtorrent/session.hpp index fcae0be32..ebd6b7ea5 100755 --- a/libtorrent/include/libtorrent/session.hpp +++ b/libtorrent/include/libtorrent/session.hpp @@ -129,7 +129,7 @@ namespace libtorrent , resume_data(0) , storage_mode(storage_mode_sparse) , paused(true) - , auto_managed(true) + , auto_managed(false) , duplicate_is_error(false) , storage(sc) , userdata(0) diff --git a/libtorrent/include/libtorrent/storage.hpp b/libtorrent/include/libtorrent/storage.hpp index 1c27388f7..a1fbdc2ba 100755 --- a/libtorrent/include/libtorrent/storage.hpp +++ b/libtorrent/include/libtorrent/storage.hpp @@ -252,6 +252,7 @@ namespace libtorrent no_error = 0, need_full_check = -1, fatal_disk_error = -2, + disk_check_aborted = -3 }; private: diff --git a/libtorrent/src/disk_io_thread.cpp b/libtorrent/src/disk_io_thread.cpp index 57aa52877..bd0cd49fb 100644 --- a/libtorrent/src/disk_io_thread.cpp +++ b/libtorrent/src/disk_io_thread.cpp @@ -79,7 +79,9 @@ namespace libtorrent void disk_io_thread::join() { mutex_t::scoped_lock l(m_mutex); - m_abort = true; + disk_io_job j; + j.action = disk_io_job::abort_thread; + m_jobs.insert(m_jobs.begin(), j); m_signal.notify_all(); l.unlock(); @@ -146,6 +148,13 @@ namespace libtorrent m_jobs.erase(i++); continue; } + if (i->action == disk_io_job::check_files) + { + if (i->callback) m_ios.post(bind(i->callback + , piece_manager::disk_check_aborted, *i)); + m_jobs.erase(i++); + continue; + } ++i; } m_signal.notify_all(); @@ -223,6 +232,9 @@ namespace libtorrent --m_cache_stats.cache_size; --m_cache_stats.read_cache_size; } + l.unlock(); + p.storage = 0; + l.lock(); } bool disk_io_thread::clear_oldest_read_piece( @@ -331,6 +343,9 @@ namespace libtorrent for (int i = 0; i < blocks_in_piece; ++i) TORRENT_ASSERT(p.blocks[i] == 0); #endif + l.unlock(); + p.storage = 0; + l.lock(); } void disk_io_thread::cache_block(disk_io_job& j, mutex_t::scoped_lock& l) @@ -353,6 +368,9 @@ namespace libtorrent p.blocks[block] = j.buffer; ++m_cache_stats.cache_size; m_pieces.push_back(p); +#ifndef NDEBUG + p.storage = 0; +#endif } // fills a piece with data from disk, returns the total number of bytes @@ -466,6 +484,9 @@ namespace libtorrent else m_read_pieces.push_back(p); +#ifndef NDEBUG + p.storage = 0; +#endif return ret; } @@ -479,6 +500,7 @@ namespace libtorrent cached_piece_entry const& p = *i; TORRENT_ASSERT(p.blocks); + if (!p.storage) continue; int piece_size = p.storage->info()->piece_size(p.piece); int blocks_in_piece = (piece_size + m_block_size - 1) / m_block_size; int blocks = 0; @@ -727,7 +749,21 @@ namespace libtorrent while (m_jobs.empty() && !m_abort) m_signal.wait(l); - if (m_abort && m_jobs.empty()) return; + if (m_abort && m_jobs.empty()) + { + // flush all disk caches + for (cache_t::iterator i = m_pieces.begin() + , end(m_pieces.end()); i != end; ++i) + flush(i, l); + for (cache_t::iterator i = m_read_pieces.begin() + , end(m_read_pieces.end()); i != end; ++i) + free_piece(*i, l); + l.unlock(); + m_pieces.clear(); + m_read_pieces.clear(); + l.lock(); + return; + } // if there's a buffer in this job, it will be freed // when this holder is destructed, unless it has been @@ -741,6 +777,32 @@ namespace libtorrent disk_io_job j = m_jobs.front(); m_jobs.pop_front(); + + if (j.action == disk_io_job::abort_thread) + { + m_abort = true; + + for (std::list::iterator i = m_jobs.begin(); + i != m_jobs.end();) + { + if (i->action == disk_io_job::read) + { + if (i->callback) m_ios.post(bind(i->callback, -1, *i)); + m_jobs.erase(i++); + continue; + } + if (i->action == disk_io_job::check_files) + { + if (i->callback) m_ios.post(bind(i->callback + , piece_manager::disk_check_aborted, *i)); + m_jobs.erase(i++); + continue; + } + ++i; + } + continue; + } + m_queue_buffer_size -= j.buffer_size; flush_expired_pieces(l); diff --git a/libtorrent/src/torrent.cpp b/libtorrent/src/torrent.cpp index e5a5d721b..b3a81fdfc 100755 --- a/libtorrent/src/torrent.cpp +++ b/libtorrent/src/torrent.cpp @@ -675,6 +675,12 @@ namespace libtorrent { session_impl::mutex_t::scoped_lock l(m_ses.m_mutex); + if (ret == piece_manager::disk_check_aborted) + { + m_error = "aborted"; + m_ses.done_checking(shared_from_this()); + return; + } if (ret == piece_manager::fatal_disk_error) { if (m_ses.m_alerts.should_post(alert::fatal)) @@ -3049,6 +3055,7 @@ namespace libtorrent { INVARIANT_CHECK; + TORRENT_ASSERT(!is_finished()); m_state = torrent_status::downloading; set_queue_position((std::numeric_limits::max)()); } @@ -3385,6 +3392,7 @@ namespace libtorrent void torrent::set_queue_position(int p) { + if (is_finished() && p != -1) return; if (p == m_sequence_number) return; session_impl::torrent_map& torrents = m_ses.m_torrents; @@ -3686,6 +3694,11 @@ namespace libtorrent m_started = time_now(); m_error.clear(); + if (alerts().should_post(alert::warning)) + { + alerts().post_alert(torrent_resumed_alert(get_handle(), "torrent resumed")); + } + // tell the tracker that we're back m_event = tracker_request::started; force_tracker_request();