fixed tracker timeout handling

This commit is contained in:
Arvid Norberg 2010-11-18 01:06:33 +00:00
parent 12d19f15e0
commit 40ed231366
5 changed files with 37 additions and 18 deletions

View File

@ -94,7 +94,7 @@ namespace libtorrent
void on_response(error_code const& ec, http_parser const& parser
, char const* data, int size);
virtual void on_timeout() {}
virtual void on_timeout(error_code const& ec) {}
void parse(int status_code, lazy_entry const& e);
bool extract_peer_info(lazy_entry const& e, peer_entry& ret);

View File

@ -170,7 +170,7 @@ namespace libtorrent
void cancel();
bool cancelled() const { return m_abort; }
virtual void on_timeout() = 0;
virtual void on_timeout(error_code const& ec) = 0;
virtual ~timeout_handler() {}
private:

View File

@ -110,7 +110,7 @@ namespace libtorrent
void send_udp_announce();
void send_udp_scrape();
virtual void on_timeout();
virtual void on_timeout(error_code const& ec);
tracker_manager& m_man;

View File

@ -72,10 +72,19 @@ namespace libtorrent
m_read_timeout = read_timeout;
m_start_time = m_read_time = time_now_hires();
TORRENT_ASSERT(completion_timeout > 0 || read_timeout > 0);
if (m_abort) return;
int timeout = (std::min)(
m_read_timeout, (std::min)(m_completion_timeout, m_read_timeout));
int timeout = 0;
if (m_read_timeout > 0) timeout = m_read_timeout;
if (m_completion_timeout > 0)
{
timeout = timeout == 0
? m_completion_timeout
: (std::min)(m_completion_timeout, timeout);
}
error_code ec;
m_timeout.expires_at(m_read_time + seconds(timeout), ec);
m_timeout.async_wait(boost::bind(
@ -97,26 +106,30 @@ namespace libtorrent
void timeout_handler::timeout_callback(error_code const& error)
{
if (error) return;
if (m_completion_timeout == 0) return;
if (m_abort) return;
ptime now = time_now_hires();
time_duration receive_timeout = now - m_read_time;
time_duration completion_timeout = now - m_start_time;
if (m_read_timeout
<= total_seconds(receive_timeout)
|| m_completion_timeout
<= total_seconds(completion_timeout))
if ((m_read_timeout
&& m_read_timeout <= total_seconds(receive_timeout))
|| (m_completion_timeout
&& m_completion_timeout <= total_seconds(completion_timeout))
|| error)
{
on_timeout();
on_timeout(error);
return;
}
if (m_abort) return;
int timeout = (std::min)(
m_read_timeout, (std::min)(m_completion_timeout, m_read_timeout));
int timeout = 0;
if (m_read_timeout > 0) timeout = m_read_timeout;
if (m_completion_timeout > 0)
{
timeout = timeout == 0
? m_completion_timeout - total_seconds(m_read_time - m_start_time)
: (std::min)(m_completion_timeout - total_seconds(m_read_time - m_start_time), timeout);
}
error_code ec;
m_timeout.expires_at(m_read_time + seconds(timeout), ec);
m_timeout.async_wait(

View File

@ -239,8 +239,14 @@ namespace libtorrent
send_udp_connect();
}
void udp_tracker_connection::on_timeout()
void udp_tracker_connection::on_timeout(error_code const& ec)
{
if (ec)
{
fail(ec);
return;
}
#if defined TORRENT_VERBOSE_LOGGING || defined TORRENT_LOGGING || defined TORRENT_ERROR_LOGGING
boost::shared_ptr<request_callback> cb = requester();
char msg[200];