From 7b9ada7a95ce545d89e51e760d86a9a1ddb703b7 Mon Sep 17 00:00:00 2001 From: arvidn Date: Fri, 5 May 2017 08:54:02 -0400 Subject: [PATCH] make connection_tester generate_block take a span --- examples/connection_tester.cpp | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/examples/connection_tester.cpp b/examples/connection_tester.cpp index 5aae65083..3262c9d60 100644 --- a/examples/connection_tester.cpp +++ b/examples/connection_tester.cpp @@ -63,14 +63,11 @@ using namespace lt::detail; // for write_* and read_* using namespace std::placeholders; -// TODO: this should take a span -void generate_block(std::uint32_t* buffer, piece_index_t const piece, int start, int length) +void generate_block(span buffer, piece_index_t const piece + , int const offset) { - std::uint32_t fill = (static_cast(piece) << 8) | ((start / 0x4000) & 0xff); - for (int i = 0; i < length / 4; ++i) - { - buffer[i] = fill; - } + std::uint32_t const fill = (static_cast(piece) << 8) | ((offset / 0x4000) & 0xff); + for (auto& w : buffer) w = fill; } // in order to circumvent the restricton of only @@ -694,7 +691,8 @@ struct peer_conn void write_piece(piece_index_t const piece, int start, int length) { - generate_block(write_buffer, piece, start, length); + generate_block({write_buffer, static_cast(length / 4)} + , piece, start); if (corrupt) { @@ -781,8 +779,8 @@ void hasher_thread(lt::create_torrent* t, piece_index_t const start_piece hasher ph; for (int j = 0; j < piece_size; j += 0x4000) { - generate_block(piece, i, j, 0x4000); - ph.update((char*)piece, 0x4000); + generate_block(piece, i, j); + ph.update(reinterpret_cast(piece), 0x4000); } t->set_hash(i, ph.final()); int const range = static_cast(end_piece) - static_cast(start_piece); @@ -866,7 +864,7 @@ void generate_data(char const* path, torrent_info const& ti) { for (int j = 0; j < ti.piece_size(i); j += 0x4000) { - generate_block(piece, i, j, 0x4000); + generate_block(piece, i, j); int const left_in_piece = ti.piece_size(i) - j; iovec_t const b = { reinterpret_cast(piece) , size_t(std::min(left_in_piece, 0x4000))};