diff options
Diffstat (limited to 'libtorrent/src/kademlia/dht_tracker.cpp')
-rw-r--r-- | libtorrent/src/kademlia/dht_tracker.cpp | 15 |
1 files changed, 12 insertions, 3 deletions
diff --git a/libtorrent/src/kademlia/dht_tracker.cpp b/libtorrent/src/kademlia/dht_tracker.cpp index fe6a516ba..56bc765de 100644 --- a/libtorrent/src/kademlia/dht_tracker.cpp +++ b/libtorrent/src/kademlia/dht_tracker.cpp @@ -158,6 +158,7 @@ namespace libtorrent { namespace dht , m_refresh_timer(ios) , m_settings(settings) , m_refresh_bucket(160) + , m_abort(false) , m_host_resolver(ios) , m_refs(0) { @@ -220,6 +221,8 @@ namespace libtorrent { namespace dht void dht_tracker::stop() { + mutex_t::scoped_lock l(m_mutex); + m_abort = true; m_timer.cancel(); m_connection_timer.cancel(); m_refresh_timer.cancel(); @@ -237,7 +240,9 @@ namespace libtorrent { namespace dht void dht_tracker::connection_timeout(asio::error_code const& e) try { - if (e) return; + mutex_t::scoped_lock l(m_mutex); + if (e || m_abort) return; + if (!m_socket.is_open()) return; time_duration d = m_dht.connection_timeout(); m_connection_timer.expires_from_now(d); @@ -255,7 +260,9 @@ namespace libtorrent { namespace dht void dht_tracker::refresh_timeout(asio::error_code const& e) try { - if (e) return; + mutex_t::scoped_lock l(m_mutex); + if (e || m_abort) return; + if (!m_socket.is_open()) return; time_duration d = m_dht.refresh_timeout(); m_refresh_timer.expires_from_now(d); @@ -281,7 +288,9 @@ namespace libtorrent { namespace dht void dht_tracker::tick(asio::error_code const& e) try { - if (e) return; + mutex_t::scoped_lock l(m_mutex); + if (e || m_abort) return; + if (!m_socket.is_open()) return; m_timer.expires_from_now(minutes(tick_period)); m_timer.async_wait(m_strand.wrap(bind(&dht_tracker::tick, self(), _1))); |