added asserts to make sure tracker_connections are shut down correctly (#451)

This commit is contained in:
Arvid Norberg 2008-12-25 02:05:23 +00:00
parent ed5cbcca8a
commit de911676ed
2 changed files with 13 additions and 5 deletions

View File

@ -218,6 +218,7 @@ namespace libtorrent
: m_ses(ses)
, m_proxy(ps)
, m_abort(false) {}
~tracker_manager();
void queue_request(
io_service& ios
@ -227,7 +228,7 @@ namespace libtorrent
, address bind_infc
, boost::weak_ptr<request_callback> c
= boost::weak_ptr<request_callback>());
void abort_all_requests();
void abort_all_requests(bool all = false);
void remove_request(tracker_connection const*);
bool empty() const;

View File

@ -180,6 +180,12 @@ namespace libtorrent
m_man.remove_request(this);
}
tracker_manager::~tracker_manager()
{
TORRENT_ASSERT(m_abort);
abort_all_requests(true);
}
void tracker_manager::sent_bytes(int bytes)
{
aux::session_impl::mutex_t::scoped_lock l(m_ses.m_mutex);
@ -213,6 +219,8 @@ namespace libtorrent
{
mutex_t::scoped_lock l(m_mutex);
TORRENT_ASSERT(req.num_want >= 0);
TORRENT_ASSERT(!m_abort);
if (m_abort) return;
if (req.event == tracker_request::stopped)
req.num_want = 0;
@ -255,11 +263,10 @@ namespace libtorrent
con->start();
}
void tracker_manager::abort_all_requests()
void tracker_manager::abort_all_requests(bool all)
{
// removes all connections from m_connections
// except those with a requester == 0 (since those are
// 'event=stopped'-requests)
// except 'event=stopped'-requests
mutex_t::scoped_lock l(m_mutex);
m_abort = true;
@ -274,7 +281,7 @@ namespace libtorrent
continue;
}
tracker_request const& req = c->tracker_req();
if (req.event == tracker_request::stopped)
if (req.event == tracker_request::stopped && !all)
{
keep_connections.push_back(c);
m_connections.pop_back();