From 1bc22888a83c27926f77398139fe661d1a23aa94 Mon Sep 17 00:00:00 2001 From: Arvid Norberg Date: Fri, 10 Jun 2005 23:12:50 +0000 Subject: [PATCH] *** empty log message *** --- include/libtorrent/piece_picker.hpp | 1 - include/libtorrent/torrent.hpp | 6 ++++++ src/http_tracker_connection.cpp | 4 ++-- src/peer_connection.cpp | 15 ++++++++++++++- src/torrent.cpp | 21 ++++++++++++++++----- 5 files changed, 38 insertions(+), 9 deletions(-) diff --git a/include/libtorrent/piece_picker.hpp b/include/libtorrent/piece_picker.hpp index c35882231..14b80c756 100755 --- a/include/libtorrent/piece_picker.hpp +++ b/include/libtorrent/piece_picker.hpp @@ -168,7 +168,6 @@ namespace libtorrent // piece-block, or if it's queued for downloading by some client // or if it already has been successfully downlloaded bool is_downloading(piece_block block) const; - bool is_finished(piece_block block) const; // marks this piece-block as queued for downloading diff --git a/include/libtorrent/torrent.hpp b/include/libtorrent/torrent.hpp index 514ecb2b3..da2589202 100755 --- a/include/libtorrent/torrent.hpp +++ b/include/libtorrent/torrent.hpp @@ -285,6 +285,12 @@ namespace libtorrent // all seeds and let the tracker know we're finished. void completed(); + // this is called when the torrent has finished. i.e. + // all the pieces we have not filtered have been downloaded. + // If no pieces are filtered, this is called first and then + // completed() is called immediately after it. + void finished(); + bool verify_piece(int piece_index); // this is called from the peer_connection diff --git a/src/http_tracker_connection.cpp b/src/http_tracker_connection.cpp index 9c886fc50..2402d0235 100755 --- a/src/http_tracker_connection.cpp +++ b/src/http_tracker_connection.cpp @@ -640,10 +640,10 @@ namespace libtorrent int incomplete = -1; try { complete = e["complete"].integer(); } - catch(type_error& e) {} + catch(type_error&) {} try { incomplete = e["incomplete"].integer(); } - catch(type_error& e) {} + catch(type_error&) {} requester().tracker_response(m_req, peer_list, interval, complete , incomplete); diff --git a/src/peer_connection.cpp b/src/peer_connection.cpp index aebffbef4..dc50563d8 100755 --- a/src/peer_connection.cpp +++ b/src/peer_connection.cpp @@ -992,7 +992,9 @@ namespace libtorrent m_torrent->filesystem().write(&m_recv_buffer[9], p.piece, p.start, p.length); bool was_seed = m_torrent->is_seed(); - + bool was_finished = picker.num_filtered() + m_torrent->num_pieces() + == m_torrent->torrent_file().num_pieces(); + picker.mark_as_finished(block_finished, m_socket->sender()); m_torrent->get_policy().block_finished(*this, block_finished); @@ -1004,6 +1006,17 @@ namespace libtorrent if (verified) { m_torrent->announce_piece(p.piece); + assert(m_torrent->valid_metadata()); + if (!was_finished + && picker.num_filtered() + m_torrent->num_pieces() + == m_torrent->torrent_file().num_pieces()) + { + // torrent finished + // i.e. all the pieces we're interested in have + // been downloaded. Release the files (they will open + // in read only mode if needed) + m_torrent->finished(); + } } else { diff --git a/src/torrent.cpp b/src/torrent.cpp index 0c5484ac2..3e7205b9e 100755 --- a/src/torrent.cpp +++ b/src/torrent.cpp @@ -739,7 +739,8 @@ namespace libtorrent } } - void torrent::completed() + // called when torrent is finished (all interested pieces downloaded) + void torrent::finished() { if (alerts().should_post(alert::info)) { @@ -748,11 +749,9 @@ namespace libtorrent , "torrent has finished downloading")); } - // disconnect all seeds for (peer_iterator i = m_connections.begin(); - i != m_connections.end(); - ++i) + i != m_connections.end(); ++i) { assert(i->second->associated_torrent() == this); if (i->second->is_seed()) @@ -760,7 +759,19 @@ namespace libtorrent } m_storage->release_files(); - + } + + // called when torrent is complete (all pieces downloaded) + void torrent::completed() + { +/* + if (alerts().should_post(alert::info)) + { + alerts().post_alert(torrent_complete_alert( + get_handle() + , "torrent is complete")); + } +*/ // make the next tracker request // be a completed-event m_event = tracker_request::completed;