fixed crashing bug when removing torrents while checking

This commit is contained in:
Arvid Norberg 2006-09-24 11:22:25 +00:00
parent 1bde539d67
commit 80dc56d388
5 changed files with 47 additions and 13 deletions

View File

@ -1,3 +1,4 @@
* fixed crasing bug when closing while checking a torrent
* fixed bug causing a crash with a torrent with piece length 0
* added an extension to the DHT network protocol to support the
exchange of nodes with IPv6 addresses.

View File

@ -163,6 +163,10 @@ namespace libtorrent
piece_checker_data* find_torrent(const sha1_hash& info_hash);
void remove_torrent(sha1_hash const& info_hash);
#ifndef NDEBUG
void check_invariant() const;
#endif
// when the files has been checked
// the torrent is added to the session
session_impl& m_ses;

View File

@ -112,6 +112,8 @@ namespace libtorrent { namespace detail
{
boost::mutex::scoped_lock l(m_mutex);
INVARIANT_CHECK;
// if the job queue is empty and
// we shouldn't abort
// wait for a signal
@ -160,7 +162,8 @@ namespace libtorrent { namespace detail
if (t)
{
std::string error_msg;
t->parse_resume_data(t->resume_data, t->torrent_ptr->torrent_file(), error_msg);
t->parse_resume_data(t->resume_data, t->torrent_ptr->torrent_file()
, error_msg);
if (!error_msg.empty() && m_ses.m_alerts.should_post(alert::warning))
{
@ -185,6 +188,7 @@ namespace libtorrent { namespace detail
// lock the session to add the new torrent
session_impl::mutex_t::scoped_lock l(m_ses.m_mutex);
mutex::scoped_lock l2(m_mutex);
INVARIANT_CHECK;
assert(m_torrents.front() == t);
@ -276,6 +280,9 @@ namespace libtorrent { namespace detail
{
mutex::scoped_lock l(m_mutex);
INVARIANT_CHECK;
processing->progress = progress;
if (processing->abort)
{
@ -299,7 +306,9 @@ namespace libtorrent { namespace detail
// lock the session to add the new torrent
session_impl::mutex_t::scoped_lock l(m_ses.m_mutex);
mutex::scoped_lock l2(m_mutex);
INVARIANT_CHECK;
assert(!m_processing.empty());
assert(m_processing.front() == processing);
@ -388,6 +397,7 @@ namespace libtorrent { namespace detail
detail::piece_checker_data* checker_impl::find_torrent(sha1_hash const& info_hash)
{
INVARIANT_CHECK;
for (std::deque<boost::shared_ptr<piece_checker_data> >::iterator i
= m_torrents.begin(); i != m_torrents.end(); ++i)
{
@ -405,6 +415,7 @@ namespace libtorrent { namespace detail
void checker_impl::remove_torrent(sha1_hash const& info_hash)
{
INVARIANT_CHECK;
for (std::deque<boost::shared_ptr<piece_checker_data> >::iterator i
= m_torrents.begin(); i != m_torrents.end(); ++i)
{
@ -421,7 +432,7 @@ namespace libtorrent { namespace detail
if ((*i)->info_hash == info_hash)
{
assert((*i)->processing == false);
m_torrents.erase(i);
m_processing.erase(i);
return;
}
}
@ -429,6 +440,24 @@ namespace libtorrent { namespace detail
assert(false);
}
#ifndef NDEBUG
void checker_impl::check_invariant() const
{
for (std::deque<boost::shared_ptr<piece_checker_data> >::const_iterator i
= m_torrents.begin(); i != m_torrents.end(); ++i)
{
assert(*i);
assert((*i)->torrent_ptr);
}
for (std::deque<boost::shared_ptr<piece_checker_data> >::const_iterator i
= m_processing.begin(); i != m_processing.end(); ++i)
{
assert(*i);
assert((*i)->torrent_ptr);
}
}
#endif
session_impl::session_impl(
std::pair<int, int> listen_port_range
, fingerprint const& cl_fprint

View File

@ -1528,10 +1528,10 @@ namespace libtorrent
{
m_storage.read(
&m_piece_data[0]
, m_current_slot
, 0
, int(m_info.piece_size(m_current_slot)));
&m_piece_data[0]
, m_current_slot
, 0
, int(m_info.piece_size(m_current_slot)));
if (m_hash_to_piece.empty())
{
@ -1542,11 +1542,11 @@ namespace libtorrent
}
int piece_index = identify_data(
m_piece_data
, m_current_slot
, pieces
, num_pieces
, m_hash_to_piece);
m_piece_data
, m_current_slot
, pieces
, num_pieces
, m_hash_to_piece);
assert(num_pieces == std::count(pieces.begin(), pieces.end(), true));
assert(piece_index == unassigned || piece_index >= 0);

View File

@ -957,7 +957,7 @@ namespace libtorrent
req.downloaded = m_stat.total_payload_download();
req.uploaded = m_stat.total_payload_upload();
req.left = bytes_left();
if (req.left == -1) req.left = 1000;
if (req.left == -1) req.left = 16*1024;
req.event = m_event;
if (m_event != tracker_request::stopped)