From 811c073c1bc6d8919a5947c55d81e6e27adda323 Mon Sep 17 00:00:00 2001 From: Arvid Norberg Date: Wed, 10 Dec 2003 00:24:16 +0000 Subject: [PATCH] fixed storage bug --- examples/client_test.cpp | 21 ++++++++++++++++++--- src/storage.cpp | 26 +++++++++++++++++--------- 2 files changed, 35 insertions(+), 12 deletions(-) diff --git a/examples/client_test.cpp b/examples/client_test.cpp index f23d33fe5..2fcbbb6b3 100755 --- a/examples/client_test.cpp +++ b/examples/client_test.cpp @@ -54,7 +54,7 @@ POSSIBILITY OF SUCH DAMAGE. bool sleep_and_input(char* c) { - Sleep(1000); + Sleep(200); if (kbhit()) { *c = getch(); @@ -112,7 +112,7 @@ bool sleep_and_input(char* c) fd_set set; FD_ZERO(&set); FD_SET(0, &set); - timeval tv = {1, 0}; + timeval tv = {0, 200000}; if (select(1, &set, 0, 0, &tv) > 0) { *c = getc(stdin); @@ -294,10 +294,24 @@ int main(int argc, char* argv[]) << static_cast((i->flags & peer_info::choked)?"C":"_") << static_cast((i->flags & peer_info::remote_interested)?"i":"_") << static_cast((i->flags & peer_info::remote_choked)?"c":"_") << "\n"; + + if (i->downloading_piece_index >= 0) + { + out << i->downloading_piece_index << ";" + << i->downloading_block_index << ": "; + float progress = i->downloading_progress / static_cast(i->downloading_total); + for (int j = 0; j < 20; ++j) + { + if (progress * 20 > j) out << "#"; + else out << "-"; + } + } + + out << "\n"; } out << "___________________________________\n"; - +/* i->get_download_queue(queue); for (std::vector::iterator i = queue.begin(); i != queue.end(); @@ -316,6 +330,7 @@ int main(int argc, char* argv[]) } out << "___________________________________\n"; +*/ } clear(); diff --git a/src/storage.cpp b/src/storage.cpp index 81ccc1cbd..967bd64d1 100755 --- a/src/storage.cpp +++ b/src/storage.cpp @@ -1288,6 +1288,7 @@ namespace { { static std::ofstream log("log.txt"); log << s; + log.flush(); } } @@ -1825,15 +1826,7 @@ namespace libtorrent { m_info.piece_size( m_info.num_pieces() - 1); - // treat the last slot as unallocated space. - // this means that when we get to the last - // slot we are either allocating space for - // the last piece, or the last piece has already - // been allocated - if (current_piece == m_info.num_pieces() - 1) - m_unallocated_slots.push_back(current_piece); - else - m_free_slots.push_back(current_piece); + m_free_slots.push_back(current_piece); } // done with piece, move on to next @@ -1869,6 +1862,8 @@ namespace libtorrent { boost::recursive_mutex::scoped_lock lock(m_mutex); // ---------------------------------------------------------------------- + check_invariant(); + assert(piece_index >= 0 && piece_index < m_piece_to_slot.size()); assert(m_piece_to_slot.size() == m_slot_to_piece.size()); @@ -1895,6 +1890,7 @@ namespace libtorrent { if (iter == m_free_slots.end()) { + assert(m_slot_to_piece[piece_index] != -2); iter = m_free_slots.end() - 1; // special case to make sure we don't use the last slot @@ -1978,6 +1974,8 @@ namespace libtorrent { boost::recursive_mutex::scoped_lock lock(m_mutex); // ---------------------------------------------------------------------- + check_invariant(); + namespace fs = boost::filesystem; std::cout << "allocating pieces...\n"; @@ -2043,6 +2041,16 @@ namespace libtorrent { { if (m_piece_to_slot[i] != i && m_piece_to_slot[i] >= 0) assert(m_slot_to_piece[i] == -1); + + if (m_slot_to_piece[i] == -2) + { + assert( + std::find( + m_free_slots.begin() + , m_free_slots.end() + , i) != m_free_slots.end() + ); + } } }