diff --git a/src/disk_io_thread.cpp b/src/disk_io_thread.cpp index 2e80ad046..2382b6509 100644 --- a/src/disk_io_thread.cpp +++ b/src/disk_io_thread.cpp @@ -1271,7 +1271,7 @@ namespace libtorrent int block = j.offset / m_block_size; int block_offset = j.offset & (m_block_size-1); int size = j.buffer_size; - int min_blocks_to_read = block_offset > 0 ? 2 : 1; + int min_blocks_to_read = block_offset > 0 && (size > m_block_size - block_offset) ? 2 : 1; TORRENT_ASSERT(size <= m_block_size); int start_block = block; // if we have to read more than one block, and @@ -1280,6 +1280,12 @@ namespace libtorrent if (p.blocks[start_block].buf != 0 && min_blocks_to_read > 1) ++start_block; +#ifdef TORRENT_DEBUG + int piece_size = j.storage->info()->piece_size(j.piece); + int blocks_in_piece = (piece_size + m_block_size - 1) / m_block_size; + TORRENT_ASSERT(start_block < blocks_in_piece); +#endif + return p.blocks[start_block].buf != 0; } @@ -1293,11 +1299,16 @@ namespace libtorrent int block_offset = j.offset & (m_block_size-1); int buffer_offset = 0; int size = j.buffer_size; - int min_blocks_to_read = block_offset > 0 ? 2 : 1; + int min_blocks_to_read = block_offset > 0 && (size > m_block_size - block_offset) ? 2 : 1; TORRENT_ASSERT(size <= m_block_size); int start_block = block; if (p.blocks[start_block].buf != 0 && min_blocks_to_read > 1) ++start_block; + + int piece_size = j.storage->info()->piece_size(j.piece); + int blocks_in_piece = (piece_size + m_block_size - 1) / m_block_size; + TORRENT_ASSERT(start_block < blocks_in_piece); + // if block_offset > 0, we need to read two blocks, and then // copy parts of both, because it's not aligned to the block // boundaries @@ -1307,8 +1318,6 @@ namespace libtorrent // space to force hitting disk without caching anything if (m_settings.explicit_read_cache) return -2; - int piece_size = j.storage->info()->piece_size(j.piece); - int blocks_in_piece = (piece_size + m_block_size - 1) / m_block_size; int end_block = start_block; while (end_block < blocks_in_piece && p.blocks[end_block].buf == 0) ++end_block; diff --git a/src/utp_socket_manager.cpp b/src/utp_socket_manager.cpp index 2f512f66b..8931cb1a9 100644 --- a/src/utp_socket_manager.cpp +++ b/src/utp_socket_manager.cpp @@ -49,6 +49,7 @@ namespace libtorrent , m_last_socket(0) , m_new_connection(-1) , m_sett(sett) + , m_last_route_update(min_time()) , m_sock_buf_size(0) {}