diff --git a/include/libtorrent/stat.hpp b/include/libtorrent/stat.hpp index 6acc4da81..e8a6adc77 100755 --- a/include/libtorrent/stat.hpp +++ b/include/libtorrent/stat.hpp @@ -35,6 +35,8 @@ POSSIBILITY OF SUCH DAMAGE. #include #include +#include +#include namespace libtorrent { @@ -44,6 +46,9 @@ namespace libtorrent enum { history = 10 }; public: + typedef boost::int64_t size_type; + + stat() : m_downloaded_payload(0) , m_uploaded_payload(0) @@ -77,14 +82,19 @@ namespace libtorrent void received_bytes(int bytes_payload, int bytes_protocol) { + assert(bytes_payload>=0); + assert(bytes_protocol>=0); m_downloaded_payload += bytes_payload; m_total_download_payload += bytes_payload; m_downloaded_protocol += bytes_protocol; m_total_download_protocol += bytes_protocol; } + void sent_bytes(int bytes_payload, int bytes_protocol) { + assert(bytes_payload>=0); + assert(bytes_protocol>=0); m_uploaded_payload += bytes_payload; m_total_upload_payload += bytes_payload; @@ -102,11 +112,11 @@ namespace libtorrent float down_peak() const { return m_peak_downloaded_per_second; } float up_peak() const { return m_peak_uploaded_per_second; } - unsigned int total_payload_upload() const { return m_total_upload_payload; } - unsigned int total_payload_download() const { return m_total_download_payload; } + size_type total_payload_upload() const { return m_total_upload_payload; } + size_type total_payload_download() const { return m_total_download_payload; } - unsigned int total_protocol_upload() const { return m_total_upload_protocol; } - unsigned int total_protocol_download() const { return m_total_download_protocol; } + size_type total_protocol_upload() const { return m_total_upload_protocol; } + size_type total_protocol_download() const { return m_total_download_protocol; } private: @@ -130,13 +140,13 @@ namespace libtorrent // total download/upload counters // only counting payload data - unsigned int m_total_download_payload; - unsigned int m_total_upload_payload; + size_type m_total_download_payload; + size_type m_total_upload_payload; // total download/upload counters // only counting protocol chatter - unsigned int m_total_download_protocol; - unsigned int m_total_upload_protocol; + size_type m_total_download_protocol; + size_type m_total_upload_protocol; // peak mean download/upload rates unsigned int m_peak_downloaded_per_second; diff --git a/include/libtorrent/torrent.hpp b/include/libtorrent/torrent.hpp index bdf809b7f..cfce7c3ad 100755 --- a/include/libtorrent/torrent.hpp +++ b/include/libtorrent/torrent.hpp @@ -42,6 +42,7 @@ POSSIBILITY OF SUCH DAMAGE. #include #include #include +#include #include "libtorrent/torrent_handle.hpp" #include "libtorrent/entry.hpp" @@ -106,7 +107,7 @@ namespace libtorrent { public: - typedef entry::integer_type size_type; + typedef boost::int64_t size_type; torrent( detail::session_impl& ses diff --git a/include/libtorrent/torrent_handle.hpp b/include/libtorrent/torrent_handle.hpp index 51b618dc1..698b6ab60 100755 --- a/include/libtorrent/torrent_handle.hpp +++ b/include/libtorrent/torrent_handle.hpp @@ -35,6 +35,7 @@ POSSIBILITY OF SUCH DAMAGE. #include #include +#include #include "libtorrent/peer_id.hpp" #include "libtorrent/peer_info.hpp" @@ -63,7 +64,7 @@ namespace libtorrent struct torrent_status { - typedef entry::integer_type size_type; + typedef boost::int64_t size_type; torrent_status() : state(queued_for_checking) diff --git a/include/libtorrent/torrent_info.hpp b/include/libtorrent/torrent_info.hpp index 49d521f7a..189802943 100755 --- a/include/libtorrent/torrent_info.hpp +++ b/include/libtorrent/torrent_info.hpp @@ -36,6 +36,7 @@ POSSIBILITY OF SUCH DAMAGE. #include #include +#include #include "libtorrent/entry.hpp" #include "libtorrent/socket.hpp" @@ -58,7 +59,7 @@ namespace libtorrent { std::string path; std::string filename; - entry::integer_type size; + boost::int64_t size; }; struct announce_entry @@ -81,6 +82,8 @@ namespace libtorrent { public: + typedef boost::int64_t size_type; + torrent_info(const entry& torrent_file) : m_creation_date(boost::gregorian::date(1970 , boost::gregorian::Jan @@ -115,8 +118,8 @@ namespace libtorrent // the begining) and return the new index to the tracker. int prioritize_tracker(int index); - entry::integer_type total_size() const { return m_total_size; } - entry::integer_type piece_length() const { return m_piece_length; } + size_type total_size() const { return m_total_size; } + size_type piece_length() const { return m_piece_length; } int num_pieces() const { return (int)m_piece_hash.size(); } const sha1_hash& info_hash() const { return m_info_hash; } const std::string& name() const { return m_name; } @@ -124,11 +127,11 @@ namespace libtorrent void convert_file_names(); - entry::integer_type piece_size(unsigned int index) const + size_type piece_size(unsigned int index) const { if (index == num_pieces()-1) { - entry::integer_type s = total_size() % m_piece_length; + size_type s = total_size() % m_piece_length; return (s == 0)?m_piece_length:s; } else @@ -155,7 +158,7 @@ namespace libtorrent std::vector m_urls; // the length of one piece - entry::integer_type m_piece_length; + size_type m_piece_length; // the sha-1 hashes of each piece std::vector m_piece_hash; @@ -164,7 +167,7 @@ namespace libtorrent std::vector m_files; // the sum of all filesizes - entry::integer_type m_total_size; + size_type m_total_size; // the hash that identifies this torrent sha1_hash m_info_hash; diff --git a/src/storage.cpp b/src/storage.cpp index be42cdd5a..5537c9489 100755 --- a/src/storage.cpp +++ b/src/storage.cpp @@ -363,7 +363,7 @@ namespace libtorrent { class piece_manager::impl { public: - typedef entry::integer_type size_type; + typedef boost::int64_t size_type; impl( const torrent_info& info @@ -629,9 +629,9 @@ namespace libtorrent { std::size_t bytes_to_read = piece_size; std::size_t bytes_current_read = 0; std::size_t seek_into_next = 0; - entry::integer_type filesize = 0; - entry::integer_type start_of_read = 0; - entry::integer_type start_of_file = 0; + size_type filesize = 0; + size_type start_of_read = 0; + size_type start_of_file = 0; { boost::mutex::scoped_lock lock(mutex); @@ -724,8 +724,8 @@ namespace libtorrent { { if (bytes_current_read != file_iter->size) { - entry::integer_type pos; - entry::integer_type file_end = start_of_file + file_iter->size; + size_type pos; + size_type file_end = start_of_file + file_iter->size; for (pos = start_of_read; pos < file_end; pos += piece_size) @@ -804,7 +804,7 @@ namespace libtorrent { { m_slot_to_piece[current_slot] = -2; - entry::integer_type last_pos = + size_type last_pos = m_info.total_size() - m_info.piece_size( m_info.num_pieces() - 1); diff --git a/src/torrent_info.cpp b/src/torrent_info.cpp index cb41fd84c..3a9b711cf 100755 --- a/src/torrent_info.cpp +++ b/src/torrent_info.cpp @@ -192,7 +192,7 @@ namespace libtorrent // extract sha-1 hashes for all pieces // we want this division to round upwards, that's why we have the // extra addition - entry::integer_type num_pieces = (m_total_size + m_piece_length - 1) / m_piece_length; + size_type num_pieces = (m_total_size + m_piece_length - 1) / m_piece_length; i = info.dict().find("pieces"); if (i == info.dict().end()) throw invalid_torrent_file();