fixed corruption of the connection queue when a peer_connection fails immediately in its connect() function

This commit is contained in:
Arvid Norberg 2009-04-26 02:46:10 +00:00
parent 73262b126a
commit 6c972e03a4
2 changed files with 19 additions and 10 deletions

View File

@ -62,6 +62,8 @@ release 0.14.3
* fixed bug where an asio exception could be thrown when resolving
peer countries
* fixed crash when shutting down while checking a torrent
* fixed potential crash in connection_queue when a peer_connection
fail to open its socket
release 0.14.2

View File

@ -1,4 +1,3 @@
/*
Copyright (c) 2007, Arvid Norberg
@ -177,6 +176,9 @@ namespace libtorrent
std::list<entry>::iterator i = std::find_if(m_queue.begin()
, m_queue.end(), boost::bind(&entry::connecting, _1) == false);
std::list<entry> to_connect;
while (i != m_queue.end())
{
TORRENT_ASSERT(i->connecting == false);
@ -193,15 +195,7 @@ namespace libtorrent
INVARIANT_CHECK;
entry& ent = *i;
++i;
#ifndef BOOST_NO_EXCEPTIONS
try {
#endif
ent.on_connect(ent.ticket);
#ifndef BOOST_NO_EXCEPTIONS
} catch (std::exception&) {}
#endif
to_connect.push_back(*i);
#ifdef TORRENT_CONNECTION_LOGGING
m_log << log_time() << " " << free_slots() << std::endl;
@ -211,6 +205,19 @@ namespace libtorrent
&& m_half_open_limit > 0) break;
i = std::find_if(i, m_queue.end(), boost::bind(&entry::connecting, _1) == false);
}
while (!to_connect.empty())
{
entry& ent = to_connect.front();
#ifndef BOOST_NO_EXCEPTIONS
try {
#endif
ent.on_connect(ent.ticket);
#ifndef BOOST_NO_EXCEPTIONS
} catch (std::exception&) {}
#endif
to_connect.pop_front();
}
}
#ifdef TORRENT_DEBUG