consts, minor refactor, typos and test (#1142)

This commit is contained in:
Alden Torres 2016-09-23 16:49:39 -04:00 committed by Arvid Norberg
parent 24b271b7c1
commit 158ae3a4ba
5 changed files with 29 additions and 21 deletions

View File

@ -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;

View File

@ -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

View File

@ -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

View File

@ -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<piece_picker::downloading_piece>::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<peer_connection*>::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<std::int64_t>& fp, int flags)
void torrent::file_progress(std::vector<std::int64_t>& fp, int const flags)
{
TORRENT_ASSERT(is_single_thread());
if (!valid_metadata())
@ -11108,12 +11107,11 @@ namespace libtorrent
}
else
{
std::vector<announce_entry>::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;
}
}

View File

@ -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);
}