handle short reads when exporting a file (#990)

handle short reads when exporting a file. Pieces in the part file are not guaranteed to be fully written so short reads need to be handled rather than asserting.
This commit is contained in:
Steven Siloti 2016-08-07 13:04:29 -07:00 committed by Arvid Norberg
parent 354a866636
commit bc369683df
1 changed files with 7 additions and 7 deletions

View File

@ -329,14 +329,14 @@ namespace libtorrent
// don't hold the lock during disk I/O // don't hold the lock during disk I/O
l.unlock(); l.unlock();
file::iovec_t const v = { buf.get(), size_t(block_to_copy) }; file::iovec_t v = { buf.get(), size_t(block_to_copy) };
int ret = m_file.readv(slot_offset + piece_offset, &v, 1, ec); v.iov_len = m_file.readv(slot_offset + piece_offset, &v, 1, ec);
TORRENT_ASSERT(ec || ret == block_to_copy); TORRENT_ASSERT(!ec);
if (ec || ret != block_to_copy) return; if (ec || v.iov_len == 0) return;
ret = f.writev(file_offset, &v, 1, ec); boost::int64_t ret = f.writev(file_offset, &v, 1, ec);
TORRENT_ASSERT(ec || ret == block_to_copy); TORRENT_ASSERT(ec || ret == v.iov_len);
if (ec || ret != block_to_copy) return; if (ec || ret != v.iov_len) return;
// we're done with the disk I/O, grab the lock again to update // we're done with the disk I/O, grab the lock again to update
// the slot map // the slot map