lt sync 3060

This commit is contained in:
Andrew Resch 2008-12-18 02:13:08 +00:00
parent fcc975006a
commit 3f46136362
5 changed files with 43 additions and 13 deletions

View File

@ -65,7 +65,13 @@ namespace libtorrent
proxy_settings const& get_proxy_settings() { return m_proxy_settings; } proxy_settings const& get_proxy_settings() { return m_proxy_settings; }
#ifdef TORRENT_DEBUG #ifdef TORRENT_DEBUG
~udp_socket() { m_magic = 0; } ~udp_socket()
{
TORRENT_ASSERT(m_magic == 0x1337);
TORRENT_ASSERT(m_outstanding == 0);
TORRENT_ASSERT(!m_callback);
m_magic = 0;
}
#endif #endif
private: private:

View File

@ -36,6 +36,6 @@ POSSIBILITY OF SUCH DAMAGE.
#define LIBTORRENT_VERSION_MAJOR 0 #define LIBTORRENT_VERSION_MAJOR 0
#define LIBTORRENT_VERSION_MINOR 14 #define LIBTORRENT_VERSION_MINOR 14
#define LIBTORRENT_VERSION "0.14.1.0" #define LIBTORRENT_VERSION "0.14.2.0"
#endif #endif

View File

@ -1942,6 +1942,8 @@ namespace libtorrent
// is finished // is finished
int piece_manager::check_files(int& current_slot, int& have_piece, std::string& error) int piece_manager::check_files(int& current_slot, int& have_piece, std::string& error)
{ {
if (m_state == state_none) return check_no_fastresume(error);
TORRENT_ASSERT(int(m_piece_to_slot.size()) == m_files.num_pieces()); TORRENT_ASSERT(int(m_piece_to_slot.size()) == m_files.num_pieces());
current_slot = m_current_slot; current_slot = m_current_slot;

View File

@ -497,20 +497,23 @@ namespace libtorrent
} }
} }
// shuffle each tier if (!m_urls.empty())
std::vector<announce_entry>::iterator start = m_urls.begin();
std::vector<announce_entry>::iterator stop;
int current_tier = m_urls.front().tier;
for (stop = m_urls.begin(); stop != m_urls.end(); ++stop)
{ {
if (stop->tier != current_tier) // shuffle each tier
std::vector<announce_entry>::iterator start = m_urls.begin();
std::vector<announce_entry>::iterator stop;
int current_tier = m_urls.front().tier;
for (stop = m_urls.begin(); stop != m_urls.end(); ++stop)
{ {
std::random_shuffle(start, stop); if (stop->tier != current_tier)
start = stop; {
current_tier = stop->tier; std::random_shuffle(start, stop);
start = stop;
current_tier = stop->tier;
}
} }
std::random_shuffle(start, stop);
} }
std::random_shuffle(start, stop);
} }

View File

@ -45,6 +45,7 @@ udp_socket::udp_socket(asio::io_service& ios, udp_socket::callback_t const& c
void udp_socket::send(udp::endpoint const& ep, char const* p, int len, error_code& ec) void udp_socket::send(udp::endpoint const& ep, char const* p, int len, error_code& ec)
{ {
CHECK_MAGIC; CHECK_MAGIC;
TORRENT_ASSERT(m_ipv4_sock.is_open());
if (m_tunnel_packets) if (m_tunnel_packets)
{ {
// send udp packets through SOCKS5 server // send udp packets through SOCKS5 server
@ -72,8 +73,8 @@ void udp_socket::on_read(udp::socket* s, error_code const& e, std::size_t bytes_
{ {
// "this" may be destructed in the callback // "this" may be destructed in the callback
// that's why we need to unlock // that's why we need to unlock
l.unlock();
callback_t tmp = m_callback; callback_t tmp = m_callback;
l.unlock();
m_callback.clear(); m_callback.clear();
} }
return; return;
@ -84,6 +85,7 @@ void udp_socket::on_read(udp::socket* s, error_code const& e, std::size_t bytes_
if (e) if (e)
{ {
l.unlock();
#ifndef BOOST_NO_EXCEPTIONS #ifndef BOOST_NO_EXCEPTIONS
try { try {
#endif #endif
@ -94,6 +96,7 @@ void udp_socket::on_read(udp::socket* s, error_code const& e, std::size_t bytes_
#ifndef BOOST_NO_EXCEPTIONS #ifndef BOOST_NO_EXCEPTIONS
} catch(std::exception&) {} } catch(std::exception&) {}
#endif #endif
l.lock();
// don't stop listening on recoverable errors // don't stop listening on recoverable errors
if (e != asio::error::host_unreachable if (e != asio::error::host_unreachable
@ -122,9 +125,16 @@ void udp_socket::on_read(udp::socket* s, error_code const& e, std::size_t bytes_
#endif #endif
if (m_tunnel_packets && m_v4_ep == m_proxy_addr) if (m_tunnel_packets && m_v4_ep == m_proxy_addr)
{
l.unlock();
unwrap(e, m_v4_buf, bytes_transferred); unwrap(e, m_v4_buf, bytes_transferred);
}
else else
{
l.unlock();
m_callback(e, m_v4_ep, m_v4_buf, bytes_transferred); m_callback(e, m_v4_ep, m_v4_buf, bytes_transferred);
}
l.lock();
#ifndef BOOST_NO_EXCEPTIONS #ifndef BOOST_NO_EXCEPTIONS
} catch(std::exception&) {} } catch(std::exception&) {}
@ -139,13 +149,20 @@ void udp_socket::on_read(udp::socket* s, error_code const& e, std::size_t bytes_
#endif #endif
if (m_tunnel_packets && m_v6_ep == m_proxy_addr) if (m_tunnel_packets && m_v6_ep == m_proxy_addr)
{
l.unlock();
unwrap(e, m_v6_buf, bytes_transferred); unwrap(e, m_v6_buf, bytes_transferred);
}
else else
{
l.unlock();
m_callback(e, m_v6_ep, m_v6_buf, bytes_transferred); m_callback(e, m_v6_ep, m_v6_buf, bytes_transferred);
}
#ifndef BOOST_NO_EXCEPTIONS #ifndef BOOST_NO_EXCEPTIONS
} catch(std::exception&) {} } catch(std::exception&) {}
#endif #endif
l.lock();
s->async_receive_from(asio::buffer(m_v6_buf, sizeof(m_v6_buf)) s->async_receive_from(asio::buffer(m_v6_buf, sizeof(m_v6_buf))
, m_v6_ep, boost::bind(&udp_socket::on_read, this, s, _1, _2)); , m_v6_ep, boost::bind(&udp_socket::on_read, this, s, _1, _2));
} }
@ -215,6 +232,7 @@ void udp_socket::unwrap(error_code const& e, char const* buf, int size)
void udp_socket::close() void udp_socket::close()
{ {
mutex_t::scoped_lock l(m_mutex);
TORRENT_ASSERT(m_magic == 0x1337); TORRENT_ASSERT(m_magic == 0x1337);
error_code ec; error_code ec;
@ -232,6 +250,7 @@ void udp_socket::close()
// "this" may be destructed in the callback // "this" may be destructed in the callback
callback_t tmp = m_callback; callback_t tmp = m_callback;
m_callback.clear(); m_callback.clear();
l.unlock();
} }
} }