summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rwxr-xr-xlibtorrent/src/session_impl.cpp20
-rwxr-xr-xlibtorrent/src/torrent.cpp44
2 files changed, 43 insertions, 21 deletions
diff --git a/libtorrent/src/session_impl.cpp b/libtorrent/src/session_impl.cpp
index 5ca6c7c59..86515aee4 100755
--- a/libtorrent/src/session_impl.cpp
+++ b/libtorrent/src/session_impl.cpp
@@ -1817,23 +1817,35 @@ namespace aux {
void session_impl::check_torrent(boost::shared_ptr<torrent> const& t)
{
if (m_abort) return;
+ TORRENT_ASSERT(t->should_check_files());
+ TORRENT_ASSERT(t->state() != torrent_status::checking_files);
if (m_queued_for_checking.empty()) t->start_checking();
+ else t->set_state(torrent_status::queued_for_checking);
+ TORRENT_ASSERT(std::find(m_queued_for_checking.begin()
+ , m_queued_for_checking.end(), t) == m_queued_for_checking.end());
m_queued_for_checking.push_back(t);
}
void session_impl::done_checking(boost::shared_ptr<torrent> const& t)
{
+ INVARIANT_CHECK;
+
if (m_queued_for_checking.empty()) return;
- check_queue_t::iterator next_check = m_queued_for_checking.begin();
+ boost::shared_ptr<torrent> next_check = *m_queued_for_checking.begin();
check_queue_t::iterator done = m_queued_for_checking.end();
for (check_queue_t::iterator i = m_queued_for_checking.begin()
, end(m_queued_for_checking.end()); i != end; ++i)
{
+ TORRENT_ASSERT(*i == t || (*i)->should_check_files());
if (*i == t) done = i;
- if (next_check == done || (*next_check)->queue_position() > (*i)->queue_position())
- next_check = i;
+ if (next_check == t || next_check->queue_position() > (*i)->queue_position())
+ next_check = *i;
}
- if (next_check != done) (*next_check)->start_checking();
+ // only start a new one if we removed the one that is checking
+ if (done == m_queued_for_checking.end()) return;
+
+ if (next_check != t && t->state() == torrent_status::checking_files)
+ next_check->start_checking();
m_queued_for_checking.erase(done);
}
diff --git a/libtorrent/src/torrent.cpp b/libtorrent/src/torrent.cpp
index 8e333f9e5..1cc896aa1 100755
--- a/libtorrent/src/torrent.cpp
+++ b/libtorrent/src/torrent.cpp
@@ -519,13 +519,13 @@ namespace libtorrent
if (m_ses.m_alerts.should_post<file_error_alert>())
{
m_ses.m_alerts.post_alert(file_error_alert(j.error_file, get_handle(), j.str));
+ }
#if defined TORRENT_VERBOSE_LOGGING || defined TORRENT_LOGGING || defined TORRENT_ERROR_LOGGING
- (*m_ses.m_logger) << time_now_string() << ": fatal disk error ["
- " error: " << j.str <<
- " torrent: " << torrent_file().name() <<
- " ]\n";
+ (*m_ses.m_logger) << time_now_string() << ": fatal disk error ["
+ " error: " << j.str <<
+ " torrent: " << torrent_file().name() <<
+ " ]\n";
#endif
- }
set_error(j.str);
pause();
@@ -702,13 +702,13 @@ namespace libtorrent
if (m_ses.m_alerts.should_post<file_error_alert>())
{
m_ses.m_alerts.post_alert(file_error_alert(j.error_file, get_handle(), j.str));
+ }
#if defined TORRENT_VERBOSE_LOGGING || defined TORRENT_LOGGING || defined TORRENT_ERROR_LOGGING
- (*m_ses.m_logger) << time_now_string() << ": fatal disk error ["
- " error: " << j.str <<
- " torrent: " << torrent_file().name() <<
- " ]\n";
+ (*m_ses.m_logger) << time_now_string() << ": fatal disk error ["
+ " error: " << j.str <<
+ " torrent: " << torrent_file().name() <<
+ " ]\n";
#endif
- }
set_error(j.str);
pause();
return;
@@ -718,6 +718,7 @@ namespace libtorrent
void torrent::start_checking()
{
+ TORRENT_ASSERT(should_check_files());
set_state(torrent_status::checking_files);
m_storage->async_check_files(bind(
@@ -733,7 +734,6 @@ namespace libtorrent
if (ret == piece_manager::disk_check_aborted)
{
set_error("aborted");
- m_ses.done_checking(shared_from_this());
return;
}
if (ret == piece_manager::fatal_disk_error)
@@ -741,16 +741,15 @@ namespace libtorrent
if (m_ses.m_alerts.should_post<file_error_alert>())
{
m_ses.m_alerts.post_alert(file_error_alert(j.error_file, get_handle(), j.str));
+ }
#if defined TORRENT_VERBOSE_LOGGING || defined TORRENT_LOGGING || defined TORRENT_ERROR_LOGGING
- (*m_ses.m_logger) << time_now_string() << ": fatal disk error ["
- " error: " << j.str <<
- " torrent: " << torrent_file().name() <<
- " ]\n";
+ (*m_ses.m_logger) << time_now_string() << ": fatal disk error ["
+ " error: " << j.str <<
+ " torrent: " << torrent_file().name() <<
+ " ]\n";
#endif
- }
set_error(j.str);
pause();
- if (!m_abort) m_ses.done_checking(shared_from_this());
return;
}
@@ -3872,10 +3871,21 @@ namespace libtorrent
INVARIANT_CHECK;
if (m_auto_managed == a) return;
+ bool checking_files = should_check_files();
m_auto_managed = a;
// recalculate which torrents should be
// paused
m_ses.m_auto_manage_time_scaler = 0;
+
+ if (!checking_files && should_check_files())
+ m_ses.check_torrent(shared_from_this());
+ else if (checking_files && !should_check_files())
+ {
+ // stop checking
+ m_storage->abort_disk_io();
+ m_ses.done_checking(shared_from_this());
+ set_state(torrent_status::queued_for_checking);
+ }
}
// the higher seed rank, the more important to seed