a bunch of fixes to make test_web_seeds a lot faster, and fail slightly fewer tests

This commit is contained in:
Arvid Norberg
2013-08-19 03:54:45 +00:00
parent 61be6b6ec8
commit 1afc0c6740
12 changed files with 172 additions and 102 deletions

View File

@@ -104,7 +104,7 @@ namespace libtorrent
&connection_queue::on_try_connect, this));
}
void connection_queue::done(int ticket)
bool connection_queue::done(int ticket)
{
mutex_t::scoped_lock l(m_mutex);
@@ -115,7 +115,8 @@ namespace libtorrent
if (i == m_queue.end())
{
// this might not be here in case on_timeout calls remove
return;
TORRENT_ASSERT(false);
return false;
}
if (i->connecting) --m_num_connecting;
m_queue.erase(i);
@@ -124,6 +125,7 @@ namespace libtorrent
|| m_half_open_limit == 0)
m_timer.get_io_service().post(boost::bind(
&connection_queue::on_try_connect, this));
return true;
}
void connection_queue::close()

View File

@@ -83,10 +83,10 @@ namespace libtorrent
if (i == m_queued_for_close.end())
{
l.unlock();
// none of the files are ready to be closet yet
// none of the files are ready to be closed yet
// because they're still in use by other threads
// hold off for a while
sleep(1000);
sleep(100);
}
else
{

View File

@@ -1727,8 +1727,6 @@ namespace libtorrent
peer_log("<== DONT_HAVE [ piece: %d ]", index);
#endif
if (is_disconnecting()) return;
// if we got an invalid message, abort
if (index >= int(m_have_piece.size()) || index < 0)
{
@@ -3419,7 +3417,8 @@ namespace libtorrent
if (m_connection_ticket != -1)
{
m_ses.m_half_open.done(m_connection_ticket);
if (m_ses.m_half_open.done(m_connection_ticket))
m_connection_ticket = -1;
}
// a connection attempt using uTP just failed
@@ -3585,8 +3584,8 @@ namespace libtorrent
}
if (m_connection_ticket >= 0)
{
m_ses.m_half_open.done(m_connection_ticket);
m_connection_ticket = -1;
if (m_ses.m_half_open.done(m_connection_ticket))
m_connection_ticket = -1;
}
torrent_handle handle;
@@ -4109,8 +4108,11 @@ namespace libtorrent
if (!t || m_disconnecting)
{
m_ses.m_half_open.done(m_connection_ticket);
if (m_connection_ticket >= -1) m_connection_ticket = -1;
if (m_connection_ticket != -1)
{
if (m_ses.m_half_open.done(m_connection_ticket))
m_connection_ticket = -1;
}
TORRENT_ASSERT(t || !m_connecting);
if (m_connecting && t)
{
@@ -5554,7 +5556,11 @@ namespace libtorrent
t->dec_num_connecting();
m_connecting = false;
}
m_ses.m_half_open.done(m_connection_ticket);
if (m_connection_ticket != -1)
{
if (m_ses.m_half_open.done(m_connection_ticket))
m_connection_ticket = -1;
}
if (m_disconnecting) return;
m_last_receive = time_now();

View File

@@ -2462,7 +2462,14 @@ namespace libtorrent
if (info.state == block_info::state_finished) return;
TORRENT_ASSERT(info.num_peers == 0);
info.peer = peer;
// peers may have been disconnected in between mark_as_writing
// and mark_as_finished. When a peer disconnects, its m_peer_info
// pointer is set to NULL. If so, preserve the previous peer
// pointer, instead of forgetting who we downloaded this block from
if (info.state != block_info::state_writing || peer != 0)
info.peer = peer;
TORRENT_ASSERT(info.state == block_info::state_writing
|| peer == 0);
TORRENT_ASSERT(i->writing >= 0);

View File

@@ -6518,6 +6518,8 @@ namespace libtorrent
m_files_checked = true;
start_announcing();
maybe_connect_web_seeds();
}
alert_manager& torrent::alerts() const
@@ -7794,24 +7796,7 @@ namespace libtorrent
// ---- WEB SEEDS ----
// if we have everything we want we don't need to connect to any web-seed
if (!is_finished() && !m_web_seeds.empty() && m_files_checked
&& int(m_connections.size()) < m_max_connections
&& m_ses.num_connections() < m_ses.settings().connections_limit)
{
// keep trying web-seeds if there are any
// first find out which web seeds we are connected to
for (std::list<web_seed_entry>::iterator i = m_web_seeds.begin();
i != m_web_seeds.end();)
{
std::list<web_seed_entry>::iterator w = i++;
if (w->peer_info.connection) continue;
if (w->retry > time_now()) continue;
if (w->resolving) continue;
connect_to_url_seed(w);
}
}
maybe_connect_web_seeds();
m_swarm_last_seen_complete = m_last_seen_complete;
for (peer_iterator i = m_connections.begin();
@@ -7854,6 +7839,28 @@ namespace libtorrent
state_updated();
}
void torrent::maybe_connect_web_seeds()
{
// if we have everything we want we don't need to connect to any web-seed
if (!is_finished() && !m_web_seeds.empty() && m_files_checked
&& int(m_connections.size()) < m_max_connections
&& m_ses.num_connections() < m_ses.settings().connections_limit)
{
// keep trying web-seeds if there are any
// first find out which web seeds we are connected to
for (std::list<web_seed_entry>::iterator i = m_web_seeds.begin();
i != m_web_seeds.end();)
{
std::list<web_seed_entry>::iterator w = i++;
if (w->peer_info.connection) continue;
if (w->retry > time_now()) continue;
if (w->resolving) continue;
connect_to_url_seed(w);
}
}
}
void torrent::recalc_share_mode()
{
TORRENT_ASSERT(share_mode());
@@ -8329,6 +8336,7 @@ namespace libtorrent
for (std::list<web_seed_entry>::const_iterator i = m_web_seeds.begin()
, end(m_web_seeds.end()); i != end; ++i)
{
if (i->peer_info.banned) continue;
if (i->type != type) continue;
ret.insert(i->url);
}

View File

@@ -615,8 +615,8 @@ void udp_socket::close()
if (m_connection_ticket >= 0)
{
m_cc.done(m_connection_ticket);
m_connection_ticket = -1;
if (m_cc.done(m_connection_ticket))
m_connection_ticket = -1;
// we just called done, which means on_timeout
// won't be called. Decrement the outstanding
@@ -624,6 +624,8 @@ void udp_socket::close()
#if defined TORRENT_DEBUG || TORRENT_RELEASE_ASSERTS
TORRENT_ASSERT(m_outstanding_timeout > 0);
--m_outstanding_timeout;
print_backtrace(timeout_stack, sizeof(timeout_stack));
#endif
TORRENT_ASSERT(m_outstanding_ops > 0);
--m_outstanding_ops;
@@ -815,6 +817,7 @@ void udp_socket::on_timeout()
#if defined TORRENT_DEBUG || TORRENT_RELEASE_ASSERTS
TORRENT_ASSERT(m_outstanding_timeout > 0);
--m_outstanding_timeout;
print_backtrace(timeout_stack, sizeof(timeout_stack));
#endif
TORRENT_ASSERT(m_outstanding_ops > 0);
--m_outstanding_ops;
@@ -832,6 +835,7 @@ void udp_socket::on_timeout()
error_code ec;
m_socks5_sock.close(ec);
TORRENT_ASSERT(m_cc.done(m_connection_ticket) == false);
m_connection_ticket = -1;
}
@@ -857,6 +861,7 @@ void udp_socket::on_connect(int ticket)
#if defined TORRENT_DEBUG || TORRENT_RELEASE_ASSERTS
TORRENT_ASSERT(m_outstanding_timeout > 0);
--m_outstanding_timeout;
print_backtrace(timeout_stack, sizeof(timeout_stack));
#endif
TORRENT_ASSERT(m_outstanding_ops > 0);
--m_outstanding_ops;
@@ -904,14 +909,18 @@ void udp_socket::on_connected(error_code const& e)
+ m_outstanding_resolve
+ m_outstanding_connect_queue
+ m_outstanding_socks);
if (m_abort) return;
CHECK_MAGIC;
if (e == asio::error::operation_aborted) return;
TORRENT_ASSERT(is_single_thread());
m_cc.done(m_connection_ticket);
m_connection_ticket = -1;
if (m_connection_ticket >= 0)
{
if (m_cc.done(m_connection_ticket))
m_connection_ticket = -1;
}
if (m_abort) return;
if (e == asio::error::operation_aborted) return;
// we just called done, which means on_timeout
// won't be called. Decrement the outstanding
@@ -919,6 +928,7 @@ void udp_socket::on_connected(error_code const& e)
#if defined TORRENT_DEBUG || TORRENT_RELEASE_ASSERTS
TORRENT_ASSERT(m_outstanding_timeout > 0);
--m_outstanding_timeout;
print_backtrace(timeout_stack, sizeof(timeout_stack));
#endif
TORRENT_ASSERT(m_outstanding_ops > 0);
--m_outstanding_ops;