making tracker_manager::remove_request type specific

This commit is contained in:
Alden Torres 2016-12-11 10:56:44 -05:00 committed by Arvid Norberg
parent 3a92908f39
commit 21fb0e8c20
4 changed files with 13 additions and 20 deletions

View File

@ -286,7 +286,6 @@ namespace libtorrent
#endif #endif
}; };
// TODO: 2 this class probably doesn't need to have virtual functions.
struct TORRENT_EXTRA_EXPORT tracker_connection struct TORRENT_EXTRA_EXPORT tracker_connection
: timeout_handler : timeout_handler
{ {
@ -303,7 +302,7 @@ namespace libtorrent
void fail(error_code const& ec, int code = -1, char const* msg = "" void fail(error_code const& ec, int code = -1, char const* msg = ""
, int interval = 0, int min_interval = 0); , int interval = 0, int min_interval = 0);
virtual void start() = 0; virtual void start() = 0;
virtual void close(); virtual void close() = 0;
address const& bind_interface() const { return m_req.bind_ip; } address const& bind_interface() const { return m_req.bind_ip; }
void sent_bytes(int bytes); void sent_bytes(int bytes);
void received_bytes(int bytes); void received_bytes(int bytes);
@ -359,7 +358,8 @@ namespace libtorrent
= std::weak_ptr<request_callback>()); = std::weak_ptr<request_callback>());
void abort_all_requests(bool all = false); void abort_all_requests(bool all = false);
void remove_request(tracker_connection const*); void remove_request(http_tracker_connection const* c);
void remove_request(udp_tracker_connection const* c);
bool empty() const; bool empty() const;
int num_requests() const; int num_requests() const;

View File

@ -253,7 +253,8 @@ namespace libtorrent
m_tracker_connection->close(); m_tracker_connection->close();
m_tracker_connection.reset(); m_tracker_connection.reset();
} }
tracker_connection::close(); cancel();
m_man.remove_request(this);
} }
// endpoints is an in-out parameter // endpoints is an in-out parameter

View File

@ -196,12 +196,6 @@ namespace libtorrent
m_man.received_bytes(bytes); m_man.received_bytes(bytes);
} }
void tracker_connection::close()
{
cancel();
m_man.remove_request(this);
}
tracker_manager::tracker_manager(send_fun_t const& send_fun tracker_manager::tracker_manager(send_fun_t const& send_fun
, send_fun_hostname_t const& send_fun_hostname , send_fun_hostname_t const& send_fun_hostname
, counters& stats_counters , counters& stats_counters
@ -238,7 +232,7 @@ namespace libtorrent
m_stats_counters.inc_stats_counter(counters::recv_tracker_bytes, bytes); m_stats_counters.inc_stats_counter(counters::recv_tracker_bytes, bytes);
} }
void tracker_manager::remove_request(tracker_connection const* c) void tracker_manager::remove_request(http_tracker_connection const* c)
{ {
TORRENT_ASSERT(is_single_thread()); TORRENT_ASSERT(is_single_thread());
http_conns_t::iterator i = std::find_if(m_http_conns.begin(), m_http_conns.end() http_conns_t::iterator i = std::find_if(m_http_conns.begin(), m_http_conns.end()
@ -248,14 +242,12 @@ namespace libtorrent
m_http_conns.erase(i); m_http_conns.erase(i);
return; return;
} }
}
udp_conns_t::iterator j = std::find_if(m_udp_conns.begin(), m_udp_conns.end() void tracker_manager::remove_request(udp_tracker_connection const* c)
, [c] (udp_conns_t::value_type const& uc) { return uc.second.get() == c; }); {
if (j != m_udp_conns.end()) TORRENT_ASSERT(is_single_thread());
{ m_udp_conns.erase(c->transaction_id());
m_udp_conns.erase(j);
return;
}
} }
void tracker_manager::update_transaction_id( void tracker_manager::update_transaction_id(

View File

@ -329,8 +329,8 @@ namespace libtorrent
void udp_tracker_connection::close() void udp_tracker_connection::close()
{ {
error_code ec; cancel();
tracker_connection::close(); m_man.remove_request(this);
} }
bool udp_tracker_connection::on_receive_hostname(char const* hostname bool udp_tracker_connection::on_receive_hostname(char const* hostname