|
|
@ -1106,7 +1106,6 @@ namespace libtorrent |
|
|
|
|
|
|
|
|
|
|
|
TORRENT_ASSERT(piece >= 0 && piece < m_torrent_file->num_pieces()); |
|
|
|
TORRENT_ASSERT(piece >= 0 && piece < m_torrent_file->num_pieces()); |
|
|
|
int piece_size = size; |
|
|
|
int piece_size = size; |
|
|
|
int blocks_in_piece = (piece_size + block_size() - 1) / block_size(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// avoid crash trying to access the picker when there is none
|
|
|
|
// avoid crash trying to access the picker when there is none
|
|
|
|
if (!has_picker()) return; |
|
|
|
if (!has_picker()) return; |
|
|
@ -1119,13 +1118,8 @@ namespace libtorrent |
|
|
|
p.piece = piece; |
|
|
|
p.piece = piece; |
|
|
|
p.start = 0; |
|
|
|
p.start = 0; |
|
|
|
picker().inc_refcount(piece, 0); |
|
|
|
picker().inc_refcount(piece, 0); |
|
|
|
for (int i = 0; i < blocks_in_piece; ++i, p.start += block_size()) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
if (picker().is_finished(piece_block(piece, i)) |
|
|
|
|
|
|
|
&& (flags & torrent::overwrite_existing) == 0) |
|
|
|
|
|
|
|
continue; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
p.length = (std::min)(piece_size - p.start, int(block_size())); |
|
|
|
p.length = piece_size; |
|
|
|
char* buffer = m_ses.allocate_disk_buffer("add piece"); |
|
|
|
char* buffer = m_ses.allocate_disk_buffer("add piece"); |
|
|
|
// out of memory
|
|
|
|
// out of memory
|
|
|
|
if (buffer == 0) |
|
|
|
if (buffer == 0) |
|
|
@ -1137,10 +1131,10 @@ namespace libtorrent |
|
|
|
std::memcpy(buffer, data + p.start, p.length); |
|
|
|
std::memcpy(buffer, data + p.start, p.length); |
|
|
|
filesystem().async_write(p, holder, boost::bind(&torrent::on_disk_write_complete |
|
|
|
filesystem().async_write(p, holder, boost::bind(&torrent::on_disk_write_complete |
|
|
|
, shared_from_this(), _1, _2, p)); |
|
|
|
, shared_from_this(), _1, _2, p)); |
|
|
|
piece_block block(piece, i); |
|
|
|
piece_block block(piece, 0); |
|
|
|
picker().mark_as_downloading(block, 0, piece_picker::fast); |
|
|
|
picker().mark_as_downloading(block, 0, piece_picker::fast); |
|
|
|
picker().mark_as_writing(block, 0); |
|
|
|
picker().mark_as_writing(block, 0); |
|
|
|
} |
|
|
|
|
|
|
|
async_verify_piece(piece, boost::bind(&torrent::piece_finished |
|
|
|
async_verify_piece(piece, boost::bind(&torrent::piece_finished |
|
|
|
, shared_from_this(), piece, _1, p.length)); |
|
|
|
, shared_from_this(), piece, _1, p.length)); |
|
|
|
picker().dec_refcount(piece, 0); |
|
|
|
picker().dec_refcount(piece, 0); |
|
|
@ -1149,6 +1143,8 @@ namespace libtorrent |
|
|
|
void torrent::on_disk_write_complete(int ret, disk_io_job const& j |
|
|
|
void torrent::on_disk_write_complete(int ret, disk_io_job const& j |
|
|
|
, peer_request p) |
|
|
|
, peer_request p) |
|
|
|
{ |
|
|
|
{ |
|
|
|
|
|
|
|
//printf("on_disk_write_complete: size %d\n", j.buffer_size);
|
|
|
|
|
|
|
|
|
|
|
|
TORRENT_ASSERT(m_ses.is_network_thread()); |
|
|
|
TORRENT_ASSERT(m_ses.is_network_thread()); |
|
|
|
|
|
|
|
|
|
|
|
INVARIANT_CHECK; |
|
|
|
INVARIANT_CHECK; |
|
|
|