diff --git a/src/bt_peer_connection.cpp b/src/bt_peer_connection.cpp index 075c10b47..a86a8617c 100644 --- a/src/bt_peer_connection.cpp +++ b/src/bt_peer_connection.cpp @@ -2142,7 +2142,15 @@ namespace libtorrent return; } - int num_pieces = t->torrent_file().num_pieces(); + const int num_pieces = t->torrent_file().num_pieces(); + TORRENT_ASSERT(num_pieces > 0); + if (num_pieces <= 0) + { +#ifndef TORRENT_DISABLE_LOGGING + peer_log(peer_log_alert::info, "BITFIELD", "not sending bitfield, num_pieces == 0"); +#endif + return; + } int lazy_pieces[50]; int num_lazy_pieces = 0; diff --git a/src/disk_io_thread.cpp b/src/disk_io_thread.cpp index 03263ec40..d2af37fb6 100644 --- a/src/disk_io_thread.cpp +++ b/src/disk_io_thread.cpp @@ -2359,9 +2359,6 @@ namespace libtorrent int block_size = m_disk_cache.block_size(); int blocks_in_piece = (piece_size + block_size - 1) / block_size; - file::iovec_t iov; - int ret = 0; - // keep track of which blocks we have locked by incrementing // their refcounts. This is used to decrement only these blocks // later. @@ -2374,8 +2371,6 @@ namespace libtorrent TORRENT_PIECE_ASSERT(ph->offset % block_size == 0, pe); for (int i = ph->offset / block_size; i < blocks_in_piece; ++i) { - iov.iov_len = (std::min)(block_size, piece_size - ph->offset); - // is the block not in the cache? if (pe->blocks[i].buf == NULL) continue; @@ -2388,9 +2383,11 @@ namespace libtorrent l.unlock(); + int ret = 0; int next_locked_block = 0; for (int i = ph->offset / block_size; i < blocks_in_piece; ++i) { + file::iovec_t iov; iov.iov_len = (std::min)(block_size, piece_size - ph->offset); if (next_locked_block < num_locked_blocks diff --git a/src/performance_counters.cpp b/src/performance_counters.cpp index e3bb7d9c8..2164390e2 100644 --- a/src/performance_counters.cpp +++ b/src/performance_counters.cpp @@ -76,7 +76,7 @@ namespace libtorrent { , boost::memory_order_relaxed); #else mutex::scoped_lock l(m_mutex); - mutex::scoped_lock l(c.m_mutex); + mutex::scoped_lock l2(c.m_mutex); memcpy(m_stats_counter, c.m_stats_counter, sizeof(m_stats_counter)); #endif return *this; diff --git a/src/session_impl.cpp b/src/session_impl.cpp index aff2874c9..41aea259f 100644 --- a/src/session_impl.cpp +++ b/src/session_impl.cpp @@ -1192,11 +1192,14 @@ namespace aux { { #ifdef TORRENT_DEBUG // make it obvious that the return value is undefined - ret.upload_limit = random(); - ret.download_limit = random(); + ret.upload_limit = 0xf0f0f0f; + ret.download_limit = 0xf0f0f0f; ret.label.resize(20); url_random(&ret.label[0], &ret.label[0] + 20); ret.ignore_unchoke_slots = false; + ret.connection_limit_factor = 0xf0f0f0f; + ret.upload_priority = 0xf0f0f0f; + ret.download_priority = 0xf0f0f0f; #endif return ret; } @@ -2392,7 +2395,7 @@ retry: #ifndef TORRENT_DISABLE_LOGGING session_log(" <== INCOMING CONNECTION FAILED, could " "not retrieve remote endpoint: %s" - , print_endpoint(endp).c_str(), ec.message().c_str()); + , ec.message().c_str()); #endif return; } diff --git a/src/utp_stream.cpp b/src/utp_stream.cpp index b26b8d1b8..fc48fbc68 100644 --- a/src/utp_stream.cpp +++ b/src/utp_stream.cpp @@ -3084,13 +3084,13 @@ bool utp_socket_impl::incoming_packet(boost::uint8_t const* buf, int size if (sample && acked_bytes && prev_bytes_in_flight) { + // only use the minimum from the last 3 delay measurements + delay = *std::min_element(m_delay_sample_hist, m_delay_sample_hist + num_delay_hist); + // it's impossible for delay to be more than the RTT, so make // sure to clamp it as a sanity check if (delay > min_rtt) delay = min_rtt; - // only use the minimum from the last 3 delay measurements - delay = *std::min_element(m_delay_sample_hist, m_delay_sample_hist + num_delay_hist); - do_ledbat(acked_bytes, delay, prev_bytes_in_flight); m_send_delay = delay; }