From 3b7e484d6a0239d0e52ebd865d728e5916a3ade2 Mon Sep 17 00:00:00 2001 From: Arvid Norberg Date: Sun, 7 Dec 2008 20:25:04 +0000 Subject: [PATCH] various fixes for potential shutdown freezes --- include/libtorrent/udp_socket.hpp | 1 + src/natpmp.cpp | 13 ++++++++++--- src/udp_socket.cpp | 3 +++ src/upnp.cpp | 2 ++ 4 files changed, 16 insertions(+), 3 deletions(-) diff --git a/include/libtorrent/udp_socket.hpp b/include/libtorrent/udp_socket.hpp index 5000af04d..83f187831 100644 --- a/include/libtorrent/udp_socket.hpp +++ b/include/libtorrent/udp_socket.hpp @@ -134,6 +134,7 @@ namespace libtorrent int m_queue_size_limit; int m_rate_limit; int m_quota; + bool m_abort; ptime m_last_tick; std::list m_queue; }; diff --git a/src/natpmp.cpp b/src/natpmp.cpp index be6db3edb..4f642599e 100644 --- a/src/natpmp.cpp +++ b/src/natpmp.cpp @@ -299,9 +299,16 @@ void natpmp::send_map_request(int i) m_socket.send_to(asio::buffer(buf, 12), m_nat_endpoint, 0, ec); m.map_sent = true; // linear back-off instead of exponential - ++m_retry_count; - m_send_timer.expires_from_now(milliseconds(250 * m_retry_count), ec); - m_send_timer.async_wait(bind(&natpmp::resend_request, self(), i, _1)); + if (m_abort) + { + try_next_mapping(i); + } + else + { + ++m_retry_count; + m_send_timer.expires_from_now(milliseconds(250 * m_retry_count), ec); + m_send_timer.async_wait(bind(&natpmp::resend_request, self(), i, _1)); + } } void natpmp::resend_request(int i, error_code const& e) diff --git a/src/udp_socket.cpp b/src/udp_socket.cpp index 37b784294..5580fc3cd 100644 --- a/src/udp_socket.cpp +++ b/src/udp_socket.cpp @@ -539,6 +539,7 @@ rate_limited_udp_socket::rate_limited_udp_socket(io_service& ios , m_queue_size_limit(200) , m_rate_limit(4000) , m_quota(4000) + , m_abort(false) , m_last_tick(time_now()) { error_code ec; @@ -569,6 +570,7 @@ bool rate_limited_udp_socket::send(udp::endpoint const& ep, char const* p, int l void rate_limited_udp_socket::on_tick(error_code const& e) { if (e) return; + if (m_abort) return; error_code ec; ptime now = time_now(); m_timer.expires_at(now + seconds(1), ec); @@ -593,6 +595,7 @@ void rate_limited_udp_socket::on_tick(error_code const& e) void rate_limited_udp_socket::close() { error_code ec; + m_abort = true; m_timer.cancel(ec); udp_socket::close(); } diff --git a/src/upnp.cpp b/src/upnp.cpp index 27ab71493..f4de70d85 100644 --- a/src/upnp.cpp +++ b/src/upnp.cpp @@ -246,6 +246,8 @@ void upnp::resend_request(error_code const& e) mutex_t::scoped_lock l(m_mutex); + if (m_closing) return; + if (m_retry_count < 12 && (m_devices.empty() || m_retry_count < 4)) {