diff --git a/include/libtorrent/disk_io_thread.hpp b/include/libtorrent/disk_io_thread.hpp index 98e8623b6..8da1a5d2e 100644 --- a/include/libtorrent/disk_io_thread.hpp +++ b/include/libtorrent/disk_io_thread.hpp @@ -84,7 +84,7 @@ namespace libtorrent action_t action; char* buffer; - size_type buffer_size; + int buffer_size; boost::intrusive_ptr storage; // arguments used for read and write int piece, offset; diff --git a/include/libtorrent/storage.hpp b/include/libtorrent/storage.hpp index 26f0202ac..de1a79932 100755 --- a/include/libtorrent/storage.hpp +++ b/include/libtorrent/storage.hpp @@ -123,10 +123,10 @@ namespace libtorrent virtual bool initialize(bool allocate_files) = 0; // negative return value indicates an error - virtual size_type read(char* buf, int slot, int offset, int size) = 0; + virtual int read(char* buf, int slot, int offset, int size) = 0; // negative return value indicates an error - virtual size_type write(const char* buf, int slot, int offset, int size) = 0; + virtual int write(const char* buf, int slot, int offset, int size) = 0; // non-zero return value indicates an error virtual bool move_storage(fs::path save_path) = 0; @@ -283,13 +283,13 @@ namespace libtorrent bool allocate_slots(int num_slots, bool abort_on_disk = false); - size_type read_impl( + int read_impl( char* buf , int piece_index , int offset , int size); - size_type write_impl( + int write_impl( const char* buf , int piece_index , int offset diff --git a/include/libtorrent/time.hpp b/include/libtorrent/time.hpp index ec1c0bce9..983e9fa4d 100644 --- a/include/libtorrent/time.hpp +++ b/include/libtorrent/time.hpp @@ -293,13 +293,13 @@ namespace libtorrent inline int total_seconds(time_duration td) { - return aux::performance_counter_to_microseconds(td.diff) - / 1000000; + return int(aux::performance_counter_to_microseconds(td.diff) + / 1000000); } inline int total_milliseconds(time_duration td) { - return aux::performance_counter_to_microseconds(td.diff) - / 1000; + return int(aux::performance_counter_to_microseconds(td.diff) + / 1000); } inline boost::int64_t total_microseconds(time_duration td) { diff --git a/src/alert.cpp b/src/alert.cpp index cb89147da..be6f718ee 100755 --- a/src/alert.cpp +++ b/src/alert.cpp @@ -95,7 +95,7 @@ namespace libtorrent { nsec -= 1000000000; xt.sec += 1; } - xt.nsec = nsec; + xt.nsec = boost::xtime::xtime_nsec_t(nsec); if (!m_condition.timed_wait(lock, xt)) return 0; TORRENT_ASSERT(!m_alerts.empty()); if (m_alerts.empty()) return 0; diff --git a/src/bt_peer_connection.cpp b/src/bt_peer_connection.cpp index 74499cc3c..589c8cbe4 100755 --- a/src/bt_peer_connection.cpp +++ b/src/bt_peer_connection.cpp @@ -1240,6 +1240,7 @@ namespace libtorrent } catch (std::exception& exc) { + (void)exc; #ifdef TORRENT_VERBOSE_LOGGING (*m_logger) << "invalid extended handshake: " << exc.what() << "\n"; #endif diff --git a/src/http_tracker_connection.cpp b/src/http_tracker_connection.cpp index 547c6a7dd..3adad2ca1 100755 --- a/src/http_tracker_connection.cpp +++ b/src/http_tracker_connection.cpp @@ -341,8 +341,8 @@ namespace libtorrent fail(-1, "missing 'complete' or 'incomplete' entries in scrape response"); return; } - cb->tracker_scrape_response(tracker_req(), complete->integer() - , incomplete->integer(), downloaded->integer()); + cb->tracker_scrape_response(tracker_req(), int(complete->integer()) + , int(incomplete->integer()), int(downloaded->integer())); return; } @@ -426,11 +426,11 @@ namespace libtorrent entry const* complete_ent = e.find_key("complete"); if (complete_ent && complete_ent->type() == entry::int_t) - complete = complete_ent->integer(); + complete = int(complete_ent->integer()); entry const* incomplete_ent = e.find_key("incomplete"); if (incomplete_ent && incomplete_ent->type() == entry::int_t) - incomplete = incomplete_ent->integer(); + incomplete = int(incomplete_ent->integer()); cb->tracker_response(tracker_req(), peer_list, interval->integer(), complete , incomplete, external_ip); diff --git a/src/mapped_storage.cpp b/src/mapped_storage.cpp index d0368dbd4..834bdce5c 100644 --- a/src/mapped_storage.cpp +++ b/src/mapped_storage.cpp @@ -256,7 +256,7 @@ namespace libtorrent bool initialize(bool allocate_files) { return false; } - size_type read(char* buf, int slot, int offset, int size) + int read(char* buf, int slot, int offset, int size) { TORRENT_ASSERT(buf != 0); TORRENT_ASSERT(slot >= 0 && slot < m_info->num_pieces()); @@ -378,7 +378,7 @@ namespace libtorrent return result; } - size_type write(const char* buf, int slot, int offset, int size) + int write(const char* buf, int slot, int offset, int size) { TORRENT_ASSERT(buf != 0); TORRENT_ASSERT(slot >= 0 && slot < m_info->num_pieces()); diff --git a/src/metadata_transfer.cpp b/src/metadata_transfer.cpp index 632a22b59..303942231 100644 --- a/src/metadata_transfer.cpp +++ b/src/metadata_transfer.cpp @@ -284,7 +284,7 @@ namespace libtorrent { namespace entry const& messages = h["m"]; if (entry const* index = messages.find_key("LT_metadata")) { - m_message_index = index->integer(); + m_message_index = int(index->integer()); return true; } else diff --git a/src/peer_connection.cpp b/src/peer_connection.cpp index 4e7520fc0..a35dbf85a 100755 --- a/src/peer_connection.cpp +++ b/src/peer_connection.cpp @@ -309,7 +309,7 @@ namespace libtorrent t->get_policy().peer_is_interesting(*this); } // may throw an asio error if socket has disconnected - catch (std::exception& e) {} + catch (std::exception&) {} TORRENT_ASSERT(is_interesting() == interested); } @@ -1207,7 +1207,7 @@ namespace libtorrent "s: " << r.start << " | " "l: " << r.length << " | " "i: " << m_peer_interested << " | " - "t: " << (int)t->torrent_file().piece_size(r.piece) << " | " + "t: " << t->torrent_file().piece_size(r.piece) << " | " "n: " << t->torrent_file().num_pieces() << " ]\n"; (*m_logger) << time_now_string() @@ -1233,7 +1233,7 @@ namespace libtorrent "s: " << r.start << " | " "l: " << r.length << " | " "i: " << m_peer_interested << " | " - "t: " << (int)t->torrent_file().piece_size(r.piece) << " | " + "t: " << t->torrent_file().piece_size(r.piece) << " | " "n: " << t->torrent_file().num_pieces() << " ]\n"; (*m_logger) << time_now_string() @@ -1294,7 +1294,7 @@ namespace libtorrent "s: " << r.start << " | " "l: " << r.length << " | " "i: " << m_peer_interested << " | " - "t: " << (int)t->torrent_file().piece_size(r.piece) << " | " + "t: " << t->torrent_file().piece_size(r.piece) << " | " "n: " << t->torrent_file().num_pieces() << " | " "h: " << t->have_piece(r.piece) << " | " "block_limit: " << t->block_size() << " ]\n"; @@ -1873,7 +1873,7 @@ namespace libtorrent int block_offset = block.block_index * t->block_size(); int block_size - = (std::min)((int)t->torrent_file().piece_size(block.piece_index)-block_offset, + = (std::min)(t->torrent_file().piece_size(block.piece_index)-block_offset, t->block_size()); TORRENT_ASSERT(block_size > 0); TORRENT_ASSERT(block_size <= t->block_size()); @@ -1985,7 +1985,7 @@ namespace libtorrent piece_block block = m_request_queue.front(); int block_offset = block.block_index * t->block_size(); - int block_size = (std::min)((int)t->torrent_file().piece_size( + int block_size = (std::min)(t->torrent_file().piece_size( block.piece_index) - block_offset, t->block_size()); TORRENT_ASSERT(block_size > 0); TORRENT_ASSERT(block_size <= t->block_size()); @@ -2031,7 +2031,7 @@ namespace libtorrent #endif block_offset = block.block_index * t->block_size(); - block_size = (std::min)((int)t->torrent_file().piece_size( + block_size = (std::min)(t->torrent_file().piece_size( block.piece_index) - block_offset, t->block_size()); TORRENT_ASSERT(block_size > 0); TORRENT_ASSERT(block_size <= t->block_size()); diff --git a/src/policy.cpp b/src/policy.cpp index b15412fab..b7a70f804 100755 --- a/src/policy.cpp +++ b/src/policy.cpp @@ -559,7 +559,9 @@ namespace libtorrent if (m_torrent->has_picker()) p = &m_torrent->picker(); +#ifndef TORRENT_DISABLE_DHT bool pinged = false; +#endif ptime now = time_now(); // remove old disconnected peers from the list diff --git a/src/storage.cpp b/src/storage.cpp index 0907c8fd1..5827f2d3d 100755 --- a/src/storage.cpp +++ b/src/storage.cpp @@ -365,8 +365,8 @@ namespace libtorrent bool delete_files(); bool initialize(bool allocate_files); bool move_storage(fs::path save_path); - size_type read(char* buf, int slot, int offset, int size); - size_type write(const char* buf, int slot, int offset, int size); + int read(char* buf, int slot, int offset, int size); + int write(const char* buf, int slot, int offset, int size); bool move_slot(int src_slot, int dst_slot); bool swap_slots(int slot1, int slot2); bool swap_slots3(int slot1, int slot2, int slot3); @@ -377,7 +377,7 @@ namespace libtorrent std::string const& error() const { return m_error; } void clear_error() { m_error.clear(); } - size_type read_impl(char* buf, int slot, int offset, int size, bool fill_zero); + int read_impl(char* buf, int slot, int offset, int size, bool fill_zero); ~storage() { m_files.release(this); } @@ -756,8 +756,8 @@ namespace libtorrent { int piece_size = m_info->piece_size(dst_slot); m_scratch_buffer.resize(piece_size); - size_type ret1 = read_impl(&m_scratch_buffer[0], src_slot, 0, piece_size, true); - size_type ret2 = write(&m_scratch_buffer[0], dst_slot, 0, piece_size); + int ret1 = read_impl(&m_scratch_buffer[0], src_slot, 0, piece_size, true); + int ret2 = write(&m_scratch_buffer[0], dst_slot, 0, piece_size); return ret1 != piece_size || ret2 != piece_size; } @@ -768,10 +768,10 @@ namespace libtorrent int piece1_size = m_info->piece_size(slot2); int piece2_size = m_info->piece_size(slot1); m_scratch_buffer.resize(piece_size * 2); - size_type ret1 = read_impl(&m_scratch_buffer[0], slot1, 0, piece1_size, true); - size_type ret2 = read_impl(&m_scratch_buffer[piece_size], slot2, 0, piece2_size, true); - size_type ret3 = write(&m_scratch_buffer[0], slot2, 0, piece1_size); - size_type ret4 = write(&m_scratch_buffer[piece_size], slot1, 0, piece2_size); + int ret1 = read_impl(&m_scratch_buffer[0], slot1, 0, piece1_size, true); + int ret2 = read_impl(&m_scratch_buffer[piece_size], slot2, 0, piece2_size, true); + int ret3 = write(&m_scratch_buffer[0], slot2, 0, piece1_size); + int ret4 = write(&m_scratch_buffer[piece_size], slot1, 0, piece2_size); return ret1 != piece1_size || ret2 != piece2_size || ret3 != piece1_size || ret4 != piece2_size; } @@ -784,18 +784,18 @@ namespace libtorrent int piece2_size = m_info->piece_size(slot3); int piece3_size = m_info->piece_size(slot1); m_scratch_buffer.resize(piece_size * 2); - size_type ret1 = read_impl(&m_scratch_buffer[0], slot1, 0, piece1_size, true); - size_type ret2 = read_impl(&m_scratch_buffer[piece_size], slot2, 0, piece2_size, true); - size_type ret3 = write(&m_scratch_buffer[0], slot2, 0, piece1_size); - size_type ret4 = read_impl(&m_scratch_buffer[0], slot3, 0, piece3_size, true); - size_type ret5 = write(&m_scratch_buffer[piece_size], slot3, 0, piece2_size); - size_type ret6 = write(&m_scratch_buffer[0], slot1, 0, piece3_size); + int ret1 = read_impl(&m_scratch_buffer[0], slot1, 0, piece1_size, true); + int ret2 = read_impl(&m_scratch_buffer[piece_size], slot2, 0, piece2_size, true); + int ret3 = write(&m_scratch_buffer[0], slot2, 0, piece1_size); + int ret4 = read_impl(&m_scratch_buffer[0], slot3, 0, piece3_size, true); + int ret5 = write(&m_scratch_buffer[piece_size], slot3, 0, piece2_size); + int ret6 = write(&m_scratch_buffer[0], slot1, 0, piece3_size); return ret1 != piece1_size || ret2 != piece2_size || ret3 != piece1_size || ret4 != piece3_size || ret5 != piece2_size || ret6 != piece3_size; } - size_type storage::read( + int storage::read( char* buf , int slot , int offset @@ -804,7 +804,7 @@ namespace libtorrent return read_impl(buf, slot, offset, size, false); } - size_type storage::read_impl( + int storage::read_impl( char* buf , int slot , int offset @@ -904,7 +904,7 @@ namespace libtorrent == file_iter->path); #endif - size_type actual_read = in->read(buf + buf_pos, read_bytes); + int actual_read = int(in->read(buf + buf_pos, read_bytes)); if (read_bytes != actual_read) { @@ -956,7 +956,7 @@ namespace libtorrent } // throws file_error if it fails to write - size_type storage::write( + int storage::write( const char* buf , int slot , int offset @@ -1317,7 +1317,7 @@ namespace libtorrent m_free_slots.push_back(slot_index); } - size_type piece_manager::read_impl( + int piece_manager::read_impl( char* buf , int piece_index , int offset @@ -1330,7 +1330,7 @@ namespace libtorrent return m_storage->read(buf, slot, offset, size); } - size_type piece_manager::write_impl( + int piece_manager::write_impl( const char* buf , int piece_index , int offset diff --git a/src/torrent.cpp b/src/torrent.cpp index 97f1a8d4a..2784dd4ac 100755 --- a/src/torrent.cpp +++ b/src/torrent.cpp @@ -102,7 +102,7 @@ namespace // if pieces are too small, adjust the block size if (i.piece_length() < default_block_size) { - return static_cast(i.piece_length()); + return i.piece_length(); } // otherwise, go with the default @@ -343,7 +343,7 @@ namespace libtorrent peer_request torrent::to_req(piece_block const& p) { int block_offset = p.block_index * m_block_size; - int block_size = (std::min)((int)torrent_file().piece_size( + int block_size = (std::min)(torrent_file().piece_size( p.piece_index) - block_offset, m_block_size); TORRENT_ASSERT(block_size > 0); TORRENT_ASSERT(block_size <= m_block_size); @@ -410,8 +410,8 @@ namespace libtorrent m_storage = m_owning_storage.get(); m_block_size = calculate_block_size(*m_torrent_file, m_default_block_size); m_picker.reset(new piece_picker( - static_cast(m_torrent_file->piece_length() / m_block_size) - , static_cast((m_torrent_file->total_size()+m_block_size-1)/m_block_size))); + m_torrent_file->piece_length() / m_block_size + , int((m_torrent_file->total_size()+m_block_size-1)/m_block_size))); std::vector const& url_seeds = m_torrent_file->url_seeds(); std::copy(url_seeds.begin(), url_seeds.end(), std::inserter(m_web_seeds @@ -1014,8 +1014,7 @@ namespace libtorrent const std::vector& dl_queue = m_picker->get_download_queue(); - const int blocks_per_piece = static_cast( - piece_size / m_block_size); + const int blocks_per_piece = piece_size / m_block_size; for (std::vector::const_iterator i = dl_queue.begin(); i != dl_queue.end(); ++i) @@ -1971,7 +1970,7 @@ namespace libtorrent m_host_resolver.async_resolve(q, bind(&torrent::on_name_lookup, shared_from_this(), _1, _2, url, a)); } - catch (std::exception& exc) + catch (std::exception&) { TORRENT_ASSERT(false); }; @@ -2260,7 +2259,7 @@ namespace libtorrent pi.finished = (int)i->finished; pi.writing = (int)i->writing; pi.requested = (int)i->requested; - int piece_size = torrent_file().piece_size(i->index); + int piece_size = int(torrent_file().piece_size(i->index)); for (int j = 0; j < pi.blocks_in_piece; ++j) { block_info& bi = pi.blocks[j]; @@ -3484,7 +3483,7 @@ namespace libtorrent st.progress = m_progress; else if (st.total_wanted == 0) st.progress = 1.f; else st.progress = st.total_wanted_done - / static_cast(st.total_wanted); + / static_cast(st.total_wanted); st.pieces = &m_have_pieces; st.num_pieces = m_num_pieces; diff --git a/src/torrent_handle.cpp b/src/torrent_handle.cpp index c8dab2d4d..fe4accd0c 100755 --- a/src/torrent_handle.cpp +++ b/src/torrent_handle.cpp @@ -433,7 +433,7 @@ namespace libtorrent if (m_ses == 0) return false; session_impl::mutex_t::scoped_lock l1(m_ses->m_mutex); boost::shared_ptr t = m_ses->find_torrent(m_info_hash).lock(); - return t; + return t != 0; } entry torrent_handle::write_resume_data() const diff --git a/src/torrent_info.cpp b/src/torrent_info.cpp index a184973f6..0dfce1d1b 100755 --- a/src/torrent_info.cpp +++ b/src/torrent_info.cpp @@ -361,7 +361,7 @@ namespace libtorrent error = "invalid or missing 'piece length' entry in torrent file"; return false; } - m_piece_length = (int)piece_length->integer(); + m_piece_length = int(piece_length->integer()); if (m_piece_length <= 0) { error = "invalid torrent. piece length <= 0"; @@ -563,7 +563,7 @@ namespace libtorrent ++iter; int port = 6881; if (iter->type() != entry::int_t) continue; - if (l.end() != iter) port = iter->integer(); + if (l.end() != iter) port = int(iter->integer()); m_nodes.push_back(std::make_pair(hostname, port)); } } @@ -895,7 +895,7 @@ namespace libtorrent - (num_pieces() - 1) * piece_length()); TORRENT_ASSERT(size > 0); TORRENT_ASSERT(size <= piece_length()); - return size; + return int(size); } else return piece_length(); @@ -951,12 +951,13 @@ namespace libtorrent } std::vector torrent_info::map_block(int piece, size_type offset - , int size, bool storage) const + , int size_, bool storage) const { TORRENT_ASSERT(num_files() > 0); std::vector ret; size_type start = piece * (size_type)m_piece_length + offset; + size_type size = size_; TORRENT_ASSERT(start + size <= m_total_size); // find the file iterator and file offset @@ -995,8 +996,8 @@ namespace libtorrent size_type offset = file_offset + file_at(file_index, storage).offset; peer_request ret; - ret.piece = offset / piece_length(); - ret.start = offset - ret.piece * piece_length(); + ret.piece = int(offset / piece_length()); + ret.start = int(offset - ret.piece * piece_length()); ret.length = size; return ret; } diff --git a/src/upnp.cpp b/src/upnp.cpp index 2b3af450d..53817ef94 100644 --- a/src/upnp.cpp +++ b/src/upnp.cpp @@ -208,6 +208,7 @@ void upnp::resend_request(asio::error_code const& e) } catch (std::exception& e) { + (void)e; #ifdef TORRENT_UPNP_LOGGING m_log << time_now_string() << " *** Connection failed to: " << d.url @@ -434,6 +435,7 @@ void upnp::on_reply(udp::endpoint const& from, char* buffer } catch (std::exception& e) { + (void)e; #ifdef TORRENT_UPNP_LOGGING m_log << time_now_string() << " *** Connection failed to: " << d.url diff --git a/src/ut_pex.cpp b/src/ut_pex.cpp index adf09a6fe..0bc9e8d93 100644 --- a/src/ut_pex.cpp +++ b/src/ut_pex.cpp @@ -205,7 +205,7 @@ namespace libtorrent { namespace entry const* index = messages->find_key(extension_name); if (!index || index->type() != entry::int_t) return false; - m_message_index = index->integer(); + m_message_index = int(index->integer()); return true; } diff --git a/test/test_primitives.cpp b/test/test_primitives.cpp index b2e4c3af7..c58af9445 100644 --- a/test/test_primitives.cpp +++ b/test/test_primitives.cpp @@ -6,10 +6,11 @@ #include "libtorrent/entry.hpp" #include "libtorrent/torrent_info.hpp" #include "libtorrent/escape_string.hpp" +#include "libtorrent/broadcast_socket.hpp" +#ifndef TORRENT_DISABLE_DHT #include "libtorrent/kademlia/node_id.hpp" #include "libtorrent/kademlia/routing_table.hpp" -#include "libtorrent/broadcast_socket.hpp" - +#endif #include #include #include @@ -64,6 +65,7 @@ void parser_callback(std::string& out, int token, char const* s, char const* val } } +#ifndef TORRENT_DISABLE_DHT void add_and_replace(libtorrent::dht::node_id& dst, libtorrent::dht::node_id const& add) { bool carry = false; @@ -74,6 +76,7 @@ void add_and_replace(libtorrent::dht::node_id& dst, libtorrent::dht::node_id con carry = sum > 255; } } +#endif int test_main() { @@ -318,6 +321,7 @@ int test_main() std::cerr << ti3.name() << std::endl; TEST_CHECK(ti3.name() == "test2/test3/test4"); +#ifndef TORRENT_DISABLE_DHT // test kademlia functions using namespace libtorrent::dht; @@ -417,6 +421,7 @@ int test_main() } TEST_CHECK(hits > int(temp.size()) / 2); +#endif