From c3695d9fbb9ac0a768ab440da4c0a1994c5baadd Mon Sep 17 00:00:00 2001 From: Arvid Norberg Date: Sun, 27 Nov 2011 00:01:13 +0000 Subject: [PATCH] add have_piece function to torrent_handle --- bindings/python/src/torrent_handle.cpp | 1 + docs/manual.rst | 10 ++++++++++ include/libtorrent/torrent_handle.hpp | 1 + src/torrent_handle.cpp | 7 +++++++ 4 files changed, 19 insertions(+) diff --git a/bindings/python/src/torrent_handle.cpp b/bindings/python/src/torrent_handle.cpp index 1b3d38e4d..d37a757d1 100644 --- a/bindings/python/src/torrent_handle.cpp +++ b/bindings/python/src/torrent_handle.cpp @@ -332,6 +332,7 @@ void bind_torrent_handle() #endif .def("add_piece", add_piece) .def("read_piece", _(&torrent_handle::read_piece)) + .def("have_piece", _(&torrent_handle::have_piece)) .def("set_piece_deadline", _(&torrent_handle::set_piece_deadline) , (arg("index"), arg("deadline"), arg("flags") = 0)) .def("reset_piece_deadline", _(&torrent_handle::reset_piece_deadline), (arg("index"))) diff --git a/docs/manual.rst b/docs/manual.rst index ed777fcd9..c1a8b3fd8 100644 --- a/docs/manual.rst +++ b/docs/manual.rst @@ -2363,6 +2363,7 @@ Its declaration looks like this:: enum flags_t { overwrite_existing = 1 }; void add_piece(int piece, char const* data, int flags = 0) const; void read_piece(int piece) const; + bool have_piece(int piece) const; sha1_hash info_hash() const; @@ -2629,6 +2630,15 @@ read_piece_alert_. In order to receive this alert, you must enable Note that if you read multiple pieces, the read operations are not guaranteed to finish in the same order as you initiated them. +have_piece() +------------ + + :: + + bool have_piece(int piece) const; + +Returns true if this piece has been completely downloaded, and false otherwise. + force_reannounce() force_dht_announce() --------------------------------------- diff --git a/include/libtorrent/torrent_handle.hpp b/include/libtorrent/torrent_handle.hpp index 59920c720..272a71b9d 100644 --- a/include/libtorrent/torrent_handle.hpp +++ b/include/libtorrent/torrent_handle.hpp @@ -161,6 +161,7 @@ namespace libtorrent enum flags_t { overwrite_existing = 1 }; void add_piece(int piece, char const* data, int flags = 0) const; void read_piece(int piece) const; + bool have_piece(int piece) const; void get_full_peer_list(std::vector& v) const; void get_peer_info(std::vector& v) const; diff --git a/src/torrent_handle.cpp b/src/torrent_handle.cpp index ffc1f2d7a..725a7cf5c 100644 --- a/src/torrent_handle.cpp +++ b/src/torrent_handle.cpp @@ -724,6 +724,13 @@ namespace libtorrent TORRENT_ASYNC_CALL1(read_piece, piece); } + bool torrent_handle::have_piece(int piece) const + { + INVARIANT_CHECK; + TORRENT_SYNC_CALL_RET1(bool, false, have_piece, piece); + return r; + } + storage_interface* torrent_handle::get_storage_impl() const { INVARIANT_CHECK;