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, // this is true if we have all pieces. If it's false,
// it means we either don't have any pieces, or, if // 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 // the state of how many pieces we have
bool m_have_all:1; bool m_have_all:1;

View File

@ -247,9 +247,10 @@ namespace libtorrent
if (bdecode_node pieces = rd.dict_find_string("pieces")) if (bdecode_node pieces = rd.dict_find_string("pieces"))
{ {
char const* pieces_str = pieces.string_ptr(); char const* pieces_str = pieces.string_ptr();
ret.have_pieces.resize(pieces.string_length()); int const pieces_len = pieces.string_length();
ret.verified_pieces.resize(pieces.string_length()); ret.have_pieces.resize(pieces_len);
for (int i = 0, end(pieces.string_length()); i < end; ++i) 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. // being in seed mode and missing a piece is not compatible.
// Leave seed mode if that happens // Leave seed mode if that happens

View File

@ -1498,7 +1498,7 @@ namespace aux {
#ifndef TORRENT_DISABLE_LOGGING #ifndef TORRENT_DISABLE_LOGGING
if (should_log()) 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); , print_endpoint(bind_ep).c_str(), device.c_str(), flags);
} }
#endif #endif

View File

@ -6717,7 +6717,7 @@ namespace libtorrent
// unless it's zeroed out here (block_info has a construct that's // unless it's zeroed out here (block_info has a construct that's
// supposed to initialize it) // supposed to initialize it)
if (!blk.empty()) 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; int counter = 0;
for (std::vector<piece_picker::downloading_piece>::const_iterator i 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()); TORRENT_ASSERT(is_single_thread());
INVARIANT_CHECK; INVARIANT_CHECK;
@ -7210,10 +7210,9 @@ namespace libtorrent
// find one of the connecting peers and disconnect it // find one of the connecting peers and disconnect it
// find any peer that's connecting (i.e. a half-open TCP connection) // find any peer that's connecting (i.e. a half-open TCP connection)
// that's also not disconnecting // 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 // the longest
std::vector<peer_connection*>::iterator i = std::max_element(begin(), end() auto i = std::max_element(begin(), end(), &connecting_time_compare);
, &connecting_time_compare);
if (i == end() || !(*i)->is_connecting() || (*i)->is_disconnecting()) if (i == end() || !(*i)->is_connecting() || (*i)->is_disconnecting())
{ {
@ -10681,7 +10680,7 @@ namespace libtorrent
} }
#endif #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()); TORRENT_ASSERT(is_single_thread());
if (!valid_metadata()) if (!valid_metadata())
@ -11108,12 +11107,11 @@ namespace libtorrent
} }
else else
{ {
std::vector<announce_entry>::const_iterator i; for (auto const& t : m_trackers)
for (i = m_trackers.begin(); i != m_trackers.end(); ++i)
{ {
if (i->updating) continue; if (t.updating) continue;
if (!i->verified) continue; if (!t.verified) continue;
st->current_tracker = i->url; st->current_tracker = t.url;
break; break;
} }
} }

View File

@ -393,3 +393,12 @@ TORRENT_TEST(coalesce_buffer)
TEST_CHECK(std::strcmp(test_buf2, "foobar") == 0); TEST_CHECK(std::strcmp(test_buf2, "foobar") == 0);
f.close(); 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);
}