various fixes for potential shutdown freezes

This commit is contained in:
Arvid Norberg 2008-12-07 20:25:04 +00:00
parent eda4032a93
commit 3b7e484d6a
4 changed files with 16 additions and 3 deletions

View File

@ -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<queued_packet> m_queue;
};

View File

@ -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)

View File

@ -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();
}

View File

@ -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))
{