diff --git a/docs/manual.html b/docs/manual.html index 9a84eb5cb..fdac39e18 100755 --- a/docs/manual.html +++ b/docs/manual.html @@ -413,9 +413,9 @@ public:

This class will need some explanation. First of all, to get a list of all files in the torrent, you can use begin_files(), end_files(), rbegin_files() and rend_files(). These will give you standard vector -iterators with the type file.

+iterators with the type file_entry.

-struct file
+struct file_entry
 {
         std::string path;
         std::string filename;
@@ -548,7 +548,7 @@ struct torrent_status
 
         int num_peers;
 
-        std::vector<bool> pieces;
+        const std::vector<bool>* pieces;
         std::size_t total_done;
 };
 
@@ -592,8 +592,9 @@ uploaded to all peers, accumulated, this session only.

total_payload_download and total_payload_upload counts the amount of bytes send and received this session, but only the actual oayload data (i.e the interesting data), these counters ignore any protocol overhead.

-

pieces is the bitmask that representw which pieces we have (set to true) and -the pieces we don't have.

+

pieces is the bitmask that represents which pieces we have (set to true) and +the pieces we don't have. It's a pointer and may be set to 0 if the torrent isn't +downloading or seeding.

download_rate and upload_rate are the total rates for all peers for this torrent. These will usually have better precision than summing the rates from all peers. The rates are given as the number of bytes per second.

diff --git a/docs/manual.rst b/docs/manual.rst index d4bdc0573..cc096fe1e 100755 --- a/docs/manual.rst +++ b/docs/manual.rst @@ -395,11 +395,11 @@ The ``torrent_info`` has the following synopsis:: This class will need some explanation. First of all, to get a list of all files in the torrent, you can use ``begin_files()``, ``end_files()``, ``rbegin_files()`` and ``rend_files()``. These will give you standard vector -iterators with the type ``file``. +iterators with the type ``file_entry``. :: - struct file + struct file_entry { std::string path; std::string filename; diff --git a/include/libtorrent/file.hpp b/include/libtorrent/file.hpp new file mode 100755 index 000000000..79f552d4d --- /dev/null +++ b/include/libtorrent/file.hpp @@ -0,0 +1,99 @@ +/* + +Copyright (c) 2003, Arvid Norberg +All rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions +are met: + + * Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in + the documentation and/or other materials provided with the distribution. + * Neither the name of the author nor the names of its + contributors may be used to endorse or promote products derived + from this software without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE +LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN +CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) +ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +POSSIBILITY OF SUCH DAMAGE. + +*/ + +#ifndef TORRENT_FILE_HPP_INCLUDED +#define TORRENT_FILE_HPP_INCLUDED + +#include + +#include +#include + +namespace libtorrent +{ + + struct file_error: std::runtime_error + { + file_error(std::string const& msg): std::runtime_error(msg) {} + }; + + class file: public boost::noncopyable + { + public: + +#ifdef _MSC_VER + typedef _int64 size_type; +#else + typedef long long int size_type; +#endif + + class open_mode + { + friend file; + public: + + open_mode operator|(open_mode m) + { return open_mode(m.m_mask | m_mask); } + + private: + + open_mode(int val): m_mask(val) {} + int m_mask; + }; + + static open_mode in; + static open_mode out; + + file(); + file(boost::filesystem::path const& p, open_mode m); + ~file(); + + void open(boost::filesystem::path const& p, open_mode m); + void close(); + + size_type write(const char*, size_type num_bytes); + size_type read(char*, size_type num_bytes); + + void seek(size_type pos); + size_type tell(); + + private: + + struct impl; + const std::auto_ptr m_impl; + + }; + +} + +#endif // TORRENT_FILE_HPP_INCLUDED + diff --git a/include/libtorrent/socket.hpp b/include/libtorrent/socket.hpp index b2aff6059..824056465 100755 --- a/include/libtorrent/socket.hpp +++ b/include/libtorrent/socket.hpp @@ -242,5 +242,5 @@ namespace libtorrent } -#endif // TORRENT_SOCKET_WIN_INCLUDED +#endif // TORRENT_SOCKET_HPP_INCLUDED diff --git a/include/libtorrent/torrent_info.hpp b/include/libtorrent/torrent_info.hpp index 934d85dd4..49d521f7a 100755 --- a/include/libtorrent/torrent_info.hpp +++ b/include/libtorrent/torrent_info.hpp @@ -54,7 +54,7 @@ POSSIBILITY OF SUCH DAMAGE. namespace libtorrent { - struct file + struct file_entry { std::string path; std::string filename; @@ -96,8 +96,8 @@ namespace libtorrent } } - typedef std::vector::const_iterator file_iterator; - typedef std::vector::const_reverse_iterator reverse_file_iterator; + typedef std::vector::const_iterator file_iterator; + typedef std::vector::const_reverse_iterator reverse_file_iterator; // list the files in the torrent file file_iterator begin_files() const { return m_files.begin(); } @@ -106,7 +106,7 @@ namespace libtorrent reverse_file_iterator rend_files() const { return m_files.rend(); } std::size_t num_files() const { return m_files.size(); } - const file& file_at(int index) const { assert(index >= 0 && index < (int)m_files.size()); return m_files[index]; } + const file_entry& file_at(int index) const { assert(index >= 0 && index < (int)m_files.size()); return m_files[index]; } const std::vector& trackers() const { return m_urls; } @@ -161,7 +161,7 @@ namespace libtorrent std::vector m_piece_hash; // the list of files that this torrent consists of - std::vector m_files; + std::vector m_files; // the sum of all filesizes entry::integer_type m_total_size; diff --git a/src/peer_connection.cpp b/src/peer_connection.cpp index 930538f3b..f359256c5 100755 --- a/src/peer_connection.cpp +++ b/src/peer_connection.cpp @@ -1477,7 +1477,7 @@ namespace libtorrent assert(r.length > 0 && r.start >= 0); #ifndef NDEBUG - assert(m_torrent->verify_piece(r.piece) && "internal error"); +// assert(m_torrent->verify_piece(r.piece) && "internal error"); #endif const int send_buffer_offset = m_send_buffer.size(); const int packet_size = 4 + 5 + 4 + r.length; diff --git a/src/storage.cpp b/src/storage.cpp index f8ce41f30..5ab81c7db 100755 --- a/src/storage.cpp +++ b/src/storage.cpp @@ -50,6 +50,7 @@ POSSIBILITY OF SUCH DAMAGE. #include "libtorrent/hasher.hpp" #include "libtorrent/session.hpp" #include "libtorrent/peer_id.hpp" +#include "libtorrent/file.hpp" #if defined(_MSC_VER) #define for if (false) {} else for @@ -185,7 +186,7 @@ namespace libtorrent { // find the file iterator and file offset size_type file_offset = start; - std::vector::const_iterator file_iter; + std::vector::const_iterator file_iter; for (file_iter = m_pimpl->info.begin_files();;) { @@ -261,7 +262,7 @@ namespace libtorrent { // find the file iterator and file offset size_type file_offset = start; - std::vector::const_iterator file_iter; + std::vector::const_iterator file_iter; for (file_iter = m_pimpl->info.begin_files();;) { diff --git a/src/torrent_info.cpp b/src/torrent_info.cpp index bd4220a7e..cb41fd84c 100755 --- a/src/torrent_info.cpp +++ b/src/torrent_info.cpp @@ -50,7 +50,7 @@ using namespace libtorrent; namespace { - void extract_single_file(const entry::dictionary_type& dict, file& target) + void extract_single_file(const entry::dictionary_type& dict, file_entry& target) { entry::dictionary_type::const_iterator i = dict.find("length"); if (i == dict.end()) throw invalid_torrent_file(); @@ -69,11 +69,11 @@ namespace target.filename = list.back().string(); } - void extract_files(const entry::list_type& list, std::vector& target, const std::string& root_directory) + void extract_files(const entry::list_type& list, std::vector& target, const std::string& root_directory) { for (entry::list_type::const_iterator i = list.begin(); i != list.end(); ++i) { - target.push_back(file()); + target.push_back(file_entry()); target.back().path = root_directory; extract_single_file(i->dict(), target.back()); } @@ -161,7 +161,7 @@ namespace libtorrent i = info.dict().find("length"); if (i == info.dict().end()) throw invalid_torrent_file(); - m_files.push_back(file()); + m_files.push_back(file_entry()); m_files.back().filename = m_name; m_files.back().size = i->second.integer(); } @@ -186,7 +186,7 @@ namespace libtorrent // calculate total size of all pieces m_total_size = 0; - for (std::vector::iterator i = m_files.begin(); i != m_files.end(); ++i) + for (std::vector::iterator i = m_files.begin(); i != m_files.end(); ++i) m_total_size += i->size; // extract sha-1 hashes for all pieces @@ -206,7 +206,7 @@ namespace libtorrent void torrent_info::convert_file_names() { - for (std::vector::iterator i = m_files.begin(); i != m_files.end(); ++i) + for (std::vector::iterator i = m_files.begin(); i != m_files.end(); ++i) { // replace all dots in directory names with underscores std::string& path = i->path;