From 158ae3a4baf866d67b497f7d83857a2a577eab2d Mon Sep 17 00:00:00 2001 From: Alden Torres Date: Fri, 23 Sep 2016 16:49:39 -0400 Subject: [PATCH] consts, minor refactor, typos and test (#1142) --- include/libtorrent/torrent.hpp | 2 +- src/read_resume_data.cpp | 7 ++++--- src/session_impl.cpp | 2 +- src/torrent.cpp | 30 ++++++++++++++---------------- test/test_file.cpp | 9 +++++++++ 5 files changed, 29 insertions(+), 21 deletions(-) diff --git a/include/libtorrent/torrent.hpp b/include/libtorrent/torrent.hpp index 9abd600b9..e5b424088 100644 --- a/include/libtorrent/torrent.hpp +++ b/include/libtorrent/torrent.hpp @@ -228,7 +228,7 @@ namespace libtorrent // this is true if we have all pieces. If it's false, // it means we either don't have any pieces, or, if - // there is a piece_picker object present, it contans + // there is a piece_picker object present, it contains // the state of how many pieces we have bool m_have_all:1; diff --git a/src/read_resume_data.cpp b/src/read_resume_data.cpp index c0d28681e..dc23d707f 100644 --- a/src/read_resume_data.cpp +++ b/src/read_resume_data.cpp @@ -247,9 +247,10 @@ namespace libtorrent if (bdecode_node pieces = rd.dict_find_string("pieces")) { char const* pieces_str = pieces.string_ptr(); - ret.have_pieces.resize(pieces.string_length()); - ret.verified_pieces.resize(pieces.string_length()); - for (int i = 0, end(pieces.string_length()); i < end; ++i) + int const pieces_len = pieces.string_length(); + ret.have_pieces.resize(pieces_len); + ret.verified_pieces.resize(pieces_len); + for (int i = 0; i < pieces_len; ++i) { // being in seed mode and missing a piece is not compatible. // Leave seed mode if that happens diff --git a/src/session_impl.cpp b/src/session_impl.cpp index 20cbd39c3..6210abaf3 100644 --- a/src/session_impl.cpp +++ b/src/session_impl.cpp @@ -1498,7 +1498,7 @@ namespace aux { #ifndef TORRENT_DISABLE_LOGGING if (should_log()) { - session_log("attempting to to open listen socket to: %s on device: %s flags: %x" + session_log("attempting to open listen socket to: %s on device: %s flags: %x" , print_endpoint(bind_ep).c_str(), device.c_str(), flags); } #endif diff --git a/src/torrent.cpp b/src/torrent.cpp index 3dd3474bb..0f88b55bb 100644 --- a/src/torrent.cpp +++ b/src/torrent.cpp @@ -2276,11 +2276,11 @@ namespace libtorrent for (int i = 0; i < num_pieces; ++i) { if (m_add_torrent_params->have_pieces[i] == false) continue; - need_picker(); - m_picker->we_have(i); - inc_stats_counter(counters::num_piece_passed); - update_gauge(); - we_have(i); + need_picker(); + m_picker->we_have(i); + inc_stats_counter(counters::num_piece_passed); + update_gauge(); + we_have(i); } if (m_seed_mode) @@ -6717,7 +6717,7 @@ namespace libtorrent // unless it's zeroed out here (block_info has a construct that's // supposed to initialize it) if (!blk.empty()) - memset(&blk[0], 0, sizeof(blk[0]) * blk.size()); + std::memset(&blk[0], 0, sizeof(blk[0]) * blk.size()); int counter = 0; for (std::vector::const_iterator i @@ -6787,7 +6787,7 @@ namespace libtorrent } - bool torrent::connect_to_peer(torrent_peer* peerinfo, bool ignore_limit) + bool torrent::connect_to_peer(torrent_peer* peerinfo, bool const ignore_limit) { TORRENT_ASSERT(is_single_thread()); INVARIANT_CHECK; @@ -7210,10 +7210,9 @@ namespace libtorrent // find one of the connecting peers and disconnect it // find any peer that's connecting (i.e. a half-open TCP connection) // that's also not disconnecting - // disconnect the peer that's been wating to establish a connection + // disconnect the peer that's been waiting to establish a connection // the longest - std::vector::iterator i = std::max_element(begin(), end() - , &connecting_time_compare); + auto i = std::max_element(begin(), end(), &connecting_time_compare); if (i == end() || !(*i)->is_connecting() || (*i)->is_disconnecting()) { @@ -10681,7 +10680,7 @@ namespace libtorrent } #endif - void torrent::file_progress(std::vector& fp, int flags) + void torrent::file_progress(std::vector& fp, int const flags) { TORRENT_ASSERT(is_single_thread()); if (!valid_metadata()) @@ -11108,12 +11107,11 @@ namespace libtorrent } else { - std::vector::const_iterator i; - for (i = m_trackers.begin(); i != m_trackers.end(); ++i) + for (auto const& t : m_trackers) { - if (i->updating) continue; - if (!i->verified) continue; - st->current_tracker = i->url; + if (t.updating) continue; + if (!t.verified) continue; + st->current_tracker = t.url; break; } } diff --git a/test/test_file.cpp b/test/test_file.cpp index b5a1b5a28..48a4a87c9 100644 --- a/test/test_file.cpp +++ b/test/test_file.cpp @@ -393,3 +393,12 @@ TORRENT_TEST(coalesce_buffer) TEST_CHECK(std::strcmp(test_buf2, "foobar") == 0); f.close(); } + +TORRENT_TEST(stat_file) +{ + file_status st; + error_code ec; + stat_file("no_such_file_or_directory.file", &st, ec); + TEST_CHECK(ec); + TEST_EQUAL(ec, boost::system::errc::no_such_file_or_directory); +}