@@ -631,8 +631,7 @@ namespace libtorrent {
631
631
TORRENT_UNUSED (locked);
632
632
633
633
flushing[num_flushing++] = i + block_base_index;
634
- iov[iov_len].iov_base = pe->blocks [i].buf ;
635
- iov[iov_len].iov_len = aux::numeric_cast<std::size_t >(std::min (block_size, size_left));
634
+ iov[iov_len] = { pe->blocks [i].buf , aux::numeric_cast<std::size_t >(std::min (block_size, size_left)) };
636
635
++iov_len;
637
636
pe->blocks [i].pending = true ;
638
637
@@ -1302,9 +1301,10 @@ namespace libtorrent {
1302
1301
1303
1302
// if this is the last piece, adjust the size of the
1304
1303
// last buffer to match up
1305
- iov[iov_len - 1 ].iov_len = aux::numeric_cast<std::size_t >(std::min (int (piece_size - adjusted_offset)
1306
- - (iov_len - 1 ) * block_size, block_size));
1307
- TORRENT_ASSERT (iov[iov_len - 1 ].iov_len > 0 );
1304
+ iov[iov_len - 1 ] = iov[iov_len - 1 ].first (aux::numeric_cast<std::size_t >(
1305
+ std::min (int (piece_size - adjusted_offset)
1306
+ - (iov_len - 1 ) * block_size, block_size)));
1307
+ TORRENT_ASSERT (iov[iov_len - 1 ].size () > 0 );
1308
1308
1309
1309
// at this point, all the buffers are allocated and iov is initialized
1310
1310
// and the blocks have their refcounters incremented, so no other thread
@@ -2162,8 +2162,7 @@ namespace libtorrent {
2162
2162
std::uint32_t const file_flags = file_flags_for_job (j
2163
2163
, m_settings.get_bool (settings_pack::coalesce_reads));
2164
2164
2165
- iovec_t iov;
2166
- iov.iov_base = m_disk_cache.allocate_buffer (" hashing" );
2165
+ iovec_t iov = { m_disk_cache.allocate_buffer (" hashing" ), 0x4000 };
2167
2166
hasher h;
2168
2167
int ret = 0 ;
2169
2168
int offset = 0 ;
@@ -2174,10 +2173,11 @@ namespace libtorrent {
2174
2173
2175
2174
time_point const start_time = clock_type::now ();
2176
2175
2177
- iov. iov_len = aux::numeric_cast<std::size_t >(std::min (block_size, piece_size - offset));
2176
+ iov = iov. first ( aux::numeric_cast<std::size_t >(std::min (block_size, piece_size - offset) ));
2178
2177
ret = j->storage ->readv (iov, j->piece
2179
2178
, offset, file_flags, j->error );
2180
2179
if (ret < 0 ) break ;
2180
+ iov = iov.first (std::size_t (ret));
2181
2181
2182
2182
if (!j->error .ec )
2183
2183
{
@@ -2191,10 +2191,10 @@ namespace libtorrent {
2191
2191
}
2192
2192
2193
2193
offset += block_size;
2194
- h.update (static_cast < char const *>( iov. iov_base ), int (iov. iov_len ) );
2194
+ h.update (iov);
2195
2195
}
2196
2196
2197
- m_disk_cache.free_buffer (static_cast < char *>( iov.iov_base ));
2197
+ m_disk_cache.free_buffer (iov.data ( ));
2198
2198
2199
2199
sha1_hash piece_hash = h.final ();
2200
2200
std::memcpy (j->d .piece_hash , piece_hash.data (), 20 );
@@ -2326,23 +2326,22 @@ namespace libtorrent {
2326
2326
int next_locked_block = 0 ;
2327
2327
for (int i = offset / block_size; i < blocks_in_piece; ++i)
2328
2328
{
2329
- iovec_t iov;
2330
- iov.iov_len = aux::numeric_cast<std::size_t >(std::min (block_size, piece_size - offset));
2331
-
2332
2329
if (next_locked_block < num_locked_blocks
2333
2330
&& locked_blocks[next_locked_block] == i)
2334
2331
{
2332
+ int const len = std::min (block_size, piece_size - offset);
2335
2333
++next_locked_block;
2336
2334
TORRENT_PIECE_ASSERT (pe->blocks [i].buf , pe);
2337
2335
TORRENT_PIECE_ASSERT (offset == i * block_size, pe);
2338
- offset += int (iov. iov_len ) ;
2339
- ph->h .update ({pe->blocks [i].buf , iov. iov_len });
2336
+ offset += len ;
2337
+ ph->h .update ({pe->blocks [i].buf , aux::numeric_cast<std:: size_t >(len) });
2340
2338
}
2341
2339
else
2342
2340
{
2343
- iov.iov_base = m_disk_cache.allocate_buffer (" hashing" );
2341
+ iovec_t const iov = { m_disk_cache.allocate_buffer (" hashing" )
2342
+ , aux::numeric_cast<std::size_t >(std::min (block_size, piece_size - offset))};
2344
2343
2345
- if (iov.iov_base == nullptr )
2344
+ if (iov.data () == nullptr )
2346
2345
{
2347
2346
l.lock ();
2348
2347
@@ -2374,19 +2373,19 @@ namespace libtorrent {
2374
2373
{
2375
2374
ret = status_t ::fatal_disk_error;
2376
2375
TORRENT_ASSERT (j->error .ec && j->error .operation != 0 );
2377
- m_disk_cache.free_buffer (static_cast < char *>( iov.iov_base ));
2376
+ m_disk_cache.free_buffer (iov.data ( ));
2378
2377
break ;
2379
2378
}
2380
2379
2381
2380
// treat a short read as an error. The hash will be invalid, the
2382
2381
// block cannot be cached and the main thread should skip the rest
2383
2382
// of this file
2384
- if (read_ret != int (iov.iov_len ))
2383
+ if (read_ret != int (iov.size () ))
2385
2384
{
2386
2385
ret = status_t ::fatal_disk_error;
2387
2386
j->error .ec = boost::asio::error::eof;
2388
2387
j->error .operation = storage_error::read ;
2389
- m_disk_cache.free_buffer (static_cast < char *>( iov.iov_base ));
2388
+ m_disk_cache.free_buffer (iov.data ( ));
2390
2389
break ;
2391
2390
}
2392
2391
@@ -2403,8 +2402,8 @@ namespace libtorrent {
2403
2402
}
2404
2403
2405
2404
TORRENT_PIECE_ASSERT (offset == i * block_size, pe);
2406
- offset += int (iov.iov_len );
2407
- ph->h .update ({ static_cast < char const *>( iov. iov_base ), iov. iov_len } );
2405
+ offset += int (iov.size () );
2406
+ ph->h .update (iov);
2408
2407
2409
2408
l.lock ();
2410
2409
m_disk_cache.insert_blocks (pe, i, iov, j);
0 commit comments