fix warnings and invalid defines in disk_io_thread.cpp

This commit is contained in:
arvidn 2015-08-18 07:55:50 -04:00
parent f6b86dc4b5
commit 8d8c049d9e
13 changed files with 131 additions and 132 deletions

View File

@ -126,7 +126,7 @@ namespace libtorrent
std::multimap<std::string, std::string> const& headers() const { return m_header; }
std::vector<std::pair<boost::int64_t, boost::int64_t> > const& chunks() const { return m_chunked_ranges; }
private:
boost::int64_t m_recv_pos;
std::string m_method;

View File

@ -220,7 +220,7 @@ private:
// the last time we refreshed our own bucket
// refreshed every 15 minutes
mutable time_point m_last_self_refresh;
// this is a set of all the endpoints that have
// been identified as router nodes. They will
// be used in searches, but they will never
@ -235,7 +235,6 @@ private:
// constant called k in paper
int m_bucket_size;
};
} } // namespace libtorrent::dht

View File

@ -105,6 +105,29 @@ namespace libtorrent
typedef boost::function<void(int, address, int, error_code const&)> portmap_callback_t;
typedef boost::function<void(char const*)> log_callback_t;
struct parse_state
{
parse_state(): in_service(false) {}
bool in_service;
std::list<std::string> tag_stack;
std::string control_url;
std::string service_type;
std::string model;
std::string url_base;
bool top_tags(const char* str1, const char* str2)
{
std::list<std::string>::reverse_iterator i = tag_stack.rbegin();
if (i == tag_stack.rend()) return false;
if (!string_equal_no_case(i->c_str(), str2)) return false;
++i;
if (i == tag_stack.rend()) return false;
if (!string_equal_no_case(i->c_str(), str1)) return false;
return true;
}
};
TORRENT_EXTRA_EXPORT void find_control_url(int type, char const* string, parse_state& state);
// TODO: support using the windows API for UPnP operations as well
class TORRENT_EXTRA_EXPORT upnp : public boost::enable_shared_from_this<upnp>
{

View File

@ -1139,7 +1139,7 @@ namespace libtorrent
return;
}
#if TORRENT_USE_ASSERT
#if TORRENT_USE_ASSERTS
// TODO: it should clear the hash state even when there's an error, right?
if (j->action == disk_io_job::hash && !j->error.ec)
{
@ -1326,7 +1326,7 @@ namespace libtorrent
}
int block = j->d.io.offset / block_size;
#if TORRENT_USE_ASSERT
#if TORRENT_USE_ASSERTS
pe->piece_log.push_back(piece_log_t(j->action, block));
#endif
// as soon we insert the blocks they may be evicted
@ -1480,7 +1480,7 @@ namespace libtorrent
cached_piece_entry* pe = m_disk_cache.find_piece(j);
if (pe && pe->hashing_done)
{
#if TORRENT_USE_ASSERT
#if TORRENT_USE_ASSERTS
print_piece_log(pe->piece_log);
#endif
TORRENT_ASSERT(pe->blocks[j->d.io.offset / 16 / 1024].buf != j->buffer.disk_block);
@ -1494,7 +1494,7 @@ namespace libtorrent
if (pe)
{
#if TORRENT_USE_ASSERT
#if TORRENT_USE_ASSERTS
pe->piece_log.push_back(piece_log_t(j->action, j->d.io.offset / 0x4000));
#endif
@ -1667,7 +1667,7 @@ namespace libtorrent
j->callback = handler;
j->flags = flags;
#if TORRENT_USE_ASSERT
#if TORRENT_USE_ASSERTS
mutex::scoped_lock l3_(m_cache_mutex);
cached_piece_entry* pe = m_disk_cache.find_piece(j);
if (pe)
@ -1682,7 +1682,7 @@ namespace libtorrent
l3_.unlock();
#endif
#if TORRENT_USE_ASSERT && defined TORRENT_EXPENSIVE_INVARIANT_CHECKS
#if TORRENT_USE_ASSERTS && defined TORRENT_EXPENSIVE_INVARIANT_CHECKS
mutex::scoped_lock l2_(m_cache_mutex);
std::pair<block_cache::iterator, block_cache::iterator> range = m_disk_cache.all_pieces();
for (block_cache::iterator i = range.first; i != range.second; ++i)

View File

@ -610,10 +610,10 @@ time_duration node::connection_timeout()
// if there are no more peers, remove the entry altogether
if (t.peers.empty())
{
table_t::iterator i = m_map.find(key);
if (i != m_map.end())
table_t::iterator it = m_map.find(key);
if (it != m_map.end())
{
m_map.erase(i);
m_map.erase(it);
m_counters.inc_stats_counter(counters::dht_torrents, -1);
}
}
@ -633,8 +633,8 @@ void node::status(std::vector<dht_routing_bucket>& table
, end(m_running_requests.end()); i != end; ++i)
{
requests.push_back(dht_lookup());
dht_lookup& l = requests.back();
(*i)->status(l);
dht_lookup& lookup = requests.back();
(*i)->status(lookup);
}
}
@ -652,8 +652,8 @@ void node::status(session_status& s)
, end(m_running_requests.end()); i != end; ++i)
{
s.active_requests.push_back(dht_lookup());
dht_lookup& l = s.active_requests.back();
(*i)->status(l);
dht_lookup& lookup = s.active_requests.back();
(*i)->status(lookup);
}
}
#endif
@ -677,12 +677,12 @@ void node::lookup_peers(sha1_hash const& info_hash, entry& reply
bloom_filter<256> downloaders;
bloom_filter<256> seeds;
for (std::set<peer_entry>::const_iterator i = v.peers.begin()
, end(v.peers.end()); i != end; ++i)
for (std::set<peer_entry>::const_iterator peer_it = v.peers.begin()
, end(v.peers.end()); peer_it != end; ++peer_it)
{
sha1_hash iphash;
hash_address(i->addr.address(), iphash);
if (i->seed) seeds.set(iphash);
hash_address(peer_it->addr.address(), iphash);
if (peer_it->seed) seeds.set(iphash);
else downloaders.set(iphash);
}
@ -834,6 +834,8 @@ void incoming_error(entry& e, char const* msg, int error_code)
struct immutable_item_comparator
{
immutable_item_comparator(node_id const& our_id) : m_our_id(our_id) {}
immutable_item_comparator(immutable_item_comparator const& c)
: m_our_id(c.m_our_id) {}
bool operator() (std::pair<node_id, dht_immutable_item> const& lhs
, std::pair<node_id, dht_immutable_item> const& rhs) const
@ -851,6 +853,7 @@ struct immutable_item_comparator
}
private:
// explicitly disallow assignment, to silence msvc warning
immutable_item_comparator& operator=(immutable_item_comparator const&);
@ -1336,30 +1339,30 @@ void node::incoming_request(msg const& m, entry& e)
// , to_hex(target.to_string()).c_str());
reply["token"] = generate_token(m.addr, msg_keys[1].string_ptr());
nodes_t n;
// always return nodes as well as peers
m_table.find_node(target, n, 0);
write_nodes_entry(reply, n);
dht_immutable_table_t::iterator i = m_immutable_table.end();
dht_immutable_table_t::iterator imutable_it = m_immutable_table.end();
// if the get has a sequence number it must be for a mutable item
// so don't bother searching the immutable table
if (!msg_keys[0])
i = m_immutable_table.find(target);
imutable_it = m_immutable_table.find(target);
if (i != m_immutable_table.end())
if (imutable_it != m_immutable_table.end())
{
dht_immutable_item const& f = i->second;
dht_immutable_item const& f = imutable_it->second;
reply["v"] = bdecode(f.value, f.value + f.size);
}
else
{
dht_mutable_table_t::iterator i = m_mutable_table.find(target);
if (i != m_mutable_table.end())
dht_mutable_table_t::iterator mutable_it = m_mutable_table.find(target);
if (mutable_it != m_mutable_table.end())
{
dht_mutable_item const& f = i->second;
dht_mutable_item const& f = mutable_it->second;
reply["seq"] = f.seq;
if (!msg_keys[0] || boost::uint64_t(msg_keys[0].int_value()) < f.seq)
{

View File

@ -144,7 +144,7 @@ boost::tuple<int, int, int> routing_table::size() const
{
nodes += i->live_nodes.size();
for (bucket_t::const_iterator k = i->live_nodes.begin()
, end(i->live_nodes.end()); k != end; ++k)
, end2(i->live_nodes.end()); k != end2; ++k)
{
if (k->confirmed()) ++confirmed;
}
@ -255,7 +255,7 @@ void routing_table::print_state(std::ostream& os) const
id_shift = bucket_index + 1;
for (bucket_t::const_iterator j = i->live_nodes.begin()
, end(i->live_nodes.end()); j != end; ++j)
, end2(i->live_nodes.end()); j != end2; ++j)
{
int bucket_size_limit = bucket_limit(bucket_index);
boost::uint32_t top_mask = bucket_size_limit - 1;
@ -344,9 +344,9 @@ void routing_table::print_state(std::ostream& os) const
id_shift = bucket_index;
else
id_shift = bucket_index + 1;
for (bucket_t::const_iterator j = i->live_nodes.begin()
, end(i->live_nodes.end()); j != end; ++j)
, end2(i->live_nodes.end()); j != end2; ++j)
{
node_id id = j->id;
id <<= id_shift;
@ -358,10 +358,10 @@ void routing_table::print_state(std::ostream& os) const
cursor += snprintf(&buf[cursor], buf.size() - cursor
, "%2d mask: %2x: [", bucket_index, (top_mask >> mask_shift));
for (int i = 0; i < bucket_size_limit; ++i)
for (int j = 0; j < bucket_size_limit; ++j)
{
cursor += snprintf(&buf[cursor], buf.size() - cursor
, (sub_buckets[i] ? "X" : " "));
, (sub_buckets[j] ? "X" : " "));
}
cursor += snprintf(&buf[cursor], buf.size() - cursor
, "]\n");
@ -387,7 +387,7 @@ node_entry const* routing_table::next_refresh()
, end(m_buckets.rend()); i != end; ++i, --idx)
{
for (bucket_t::iterator j = i->live_nodes.begin()
, end(i->live_nodes.end()); j != end; ++j)
, end2(i->live_nodes.end()); j != end2; ++j)
{
// this shouldn't happen
TORRENT_ASSERT(m_id != j->id);
@ -776,21 +776,24 @@ routing_table::add_node_status_t routing_table::add_node_impl(node_entry e)
// in case bucket_size_limit is not an even power of 2
mask = (0xff << mask_shift) & 0xff;
node_id id = e.id;
// the last bucket is special, since it hasn't been split yet, it
// includes that top bit as well
if (bucket_index + 1 == m_buckets.size())
id <<= bucket_index;
else
id <<= bucket_index + 1;
// pick out all nodes that have the same prefix as the new node
std::vector<bucket_t::iterator> nodes;
bool force_replace = false;
for (j = b.begin(); j != b.end(); ++j)
{
if (!matching_prefix(*j, mask, id[0] & mask, bucket_index)) continue;
nodes.push_back(j);
node_id id = e.id;
// the last bucket is special, since it hasn't been split yet, it
// includes that top bit as well
if (bucket_index + 1 == m_buckets.size())
id <<= bucket_index;
else
id <<= bucket_index + 1;
for (j = b.begin(); j != b.end(); ++j)
{
if (!matching_prefix(*j, mask, id[0] & mask, bucket_index)) continue;
nodes.push_back(j);
}
}
if (!nodes.empty())
@ -866,8 +869,8 @@ routing_table::add_node_status_t routing_table::add_node_impl(node_entry e)
m_ips.insert(e.addr().to_v4().to_bytes());
#ifndef TORRENT_DISABLE_LOGGING
char hex_id[41];
to_hex(reinterpret_cast<char const*>(&e.id[0]), sha1_hash::size, hex_id);
m_log->log(dht_logger::routing_table, "replaving node with higher RTT: %s %s"
to_hex(e.id.data(), sha1_hash::size, hex_id);
m_log->log(dht_logger::routing_table, "replacing node with higher RTT: %s %s"
, hex_id, print_address(e.addr()).c_str());
#endif
return node_added;
@ -999,13 +1002,13 @@ void routing_table::for_each_node(
if (fun1)
{
for (bucket_t::const_iterator j = i->live_nodes.begin()
, end(i->live_nodes.end()); j != end; ++j)
, end2(i->live_nodes.end()); j != end2; ++j)
fun1(userdata, *j);
}
if (fun2)
{
for (bucket_t::const_iterator j = i->replacements.begin()
, end(i->replacements.end()); j != end; ++j)
, end2(i->replacements.end()); j != end2; ++j)
fun2(userdata, *j);
}
}

View File

@ -107,7 +107,7 @@ namespace libtorrent
if (n < m_header_size) return;
using namespace libtorrent::detail;
char* ptr = (char*)header.get();
char* ptr = reinterpret_cast<char*>(header.get());
// we have a header. Parse it
int num_pieces_ = read_uint32(ptr);
int piece_size_ = read_uint32(ptr);
@ -365,7 +365,7 @@ namespace libtorrent
// part file, remove it
std::string p = combine_path(m_path, m_name);
remove(p, ec);
if (ec == boost::system::errc::no_such_file_or_directory)
ec.clear();
return;
@ -378,7 +378,7 @@ namespace libtorrent
using namespace libtorrent::detail;
char* ptr = (char*)header.get();
char* ptr = reinterpret_cast<char*>(header.get());
write_uint32(m_max_pieces, ptr);
write_uint32(m_piece_size, ptr);
@ -391,7 +391,7 @@ namespace libtorrent
slot = i->second;
write_uint32(slot, ptr);
}
memset(ptr, 0, m_header_size - (ptr - (char*)header.get()));
memset(ptr, 0, m_header_size - (ptr - reinterpret_cast<char*>(header.get())));
#ifdef TORRENT_USE_VALGRIND
VALGRIND_CHECK_MEM_IS_DEFINED(header.get(), m_header_size);

View File

@ -124,13 +124,11 @@ namespace libtorrent {
// is blended in at.
void counters::blend_stats_counter(int c, boost::int64_t value, int ratio)
{
TORRENT_ASSERT(c >= 0);
TORRENT_ASSERT(c >= num_stats_counters);
TORRENT_ASSERT(c < num_counters);
TORRENT_ASSERT(ratio >= 0);
TORRENT_ASSERT(ratio <= 100);
TORRENT_ASSERT(num_stats_counters);
#if BOOST_ATOMIC_LLONG_LOCK_FREE == 2
boost::int64_t current = m_stats_counter[c].load(boost::memory_order_relaxed);
boost::int64_t new_value = (current * (100-ratio) + value * ratio) / 100;
@ -160,7 +158,7 @@ namespace libtorrent {
// if this assert fires, someone is trying to decrement a counter
// which is not allowed. Counters are monotonically increasing
TORRENT_ASSERT(value >= m_stats_counter[c] || c >= num_stats_counters);
m_stats_counter[c] = value;
#endif
}

View File

@ -74,7 +74,7 @@ namespace libtorrent
{
TORRENT_ASSERT(l.locked());
// wow, this is quite a hack
pthread_cond_wait(&m_cond, (::pthread_mutex_t*)&l.mutex());
pthread_cond_wait(&m_cond, reinterpret_cast<::pthread_mutex_t*>(&l.mutex()));
}
void condition_variable::wait_for(mutex::scoped_lock& l, time_duration rel_time)
@ -87,9 +87,9 @@ namespace libtorrent
boost::uint64_t microseconds = tv.tv_usec + total_microseconds(rel_time) % 1000000;
ts.tv_nsec = (microseconds % 1000000) * 1000;
ts.tv_sec = tv.tv_sec + total_seconds(rel_time) + microseconds / 1000000;
// wow, this is quite a hack
pthread_cond_timedwait(&m_cond, (::pthread_mutex_t*)&l.mutex(), &ts);
pthread_cond_timedwait(&m_cond, reinterpret_cast<::pthread_mutex_t*>(&l.mutex()), &ts);
}
void condition_variable::notify_all()

View File

@ -180,21 +180,21 @@ int upnp::add_mapping(upnp::protocol_type p, int external_port, int local_port)
log(msg, l);
if (m_disabled) return -1;
std::vector<global_mapping_t>::iterator i = std::find_if(
std::vector<global_mapping_t>::iterator mapping_it = std::find_if(
m_mappings.begin(), m_mappings.end()
, boost::bind(&global_mapping_t::protocol, _1) == int(none));
if (i == m_mappings.end())
if (mapping_it == m_mappings.end())
{
m_mappings.push_back(global_mapping_t());
i = m_mappings.end() - 1;
mapping_it = m_mappings.end() - 1;
}
i->protocol = p;
i->external_port = external_port;
i->local_port = local_port;
mapping_it->protocol = p;
mapping_it->external_port = external_port;
mapping_it->local_port = local_port;
int mapping_index = i - m_mappings.begin();
int mapping_index = mapping_it - m_mappings.begin();
for (std::set<rootdevice>::iterator i = m_devices.begin()
, end(m_devices.end()); i != end; ++i)
@ -479,7 +479,6 @@ void upnp::on_reply(udp::endpoint const& from, char* buffer
{
std::string protocol;
std::string auth;
error_code ec;
// we don't have this device in our list. Add it
boost::tie(protocol, auth, d.hostname, d.port, d.path)
= parse_url_components(d.url, ec);
@ -515,10 +514,12 @@ void upnp::on_reply(udp::endpoint const& from, char* buffer
return;
}
char msg[500];
snprintf(msg, sizeof(msg), "found rootdevice: %s (%d)"
, d.url.c_str(), int(m_devices.size()));
log(msg, l);
{
char msg[500];
snprintf(msg, sizeof(msg), "found rootdevice: %s (%d)"
, d.url.c_str(), int(m_devices.size()));
log(msg, l);
}
if (m_devices.size() >= 50)
{
@ -832,27 +833,6 @@ namespace
}
}
struct parse_state
{
parse_state(): in_service(false) {}
bool in_service;
std::list<std::string> tag_stack;
std::string control_url;
std::string service_type;
std::string model;
std::string url_base;
bool top_tags(const char* str1, const char* str2)
{
std::list<std::string>::reverse_iterator i = tag_stack.rbegin();
if (i == tag_stack.rend()) return false;
if (!string_equal_no_case(i->c_str(), str2)) return false;
++i;
if (i == tag_stack.rend()) return false;
if (!string_equal_no_case(i->c_str(), str1)) return false;
return true;
}
};
TORRENT_EXTRA_EXPORT void find_control_url(int type, char const* string, parse_state& state)
{
if (type == xml_start_tag)
@ -948,7 +928,8 @@ void upnp::on_upnp_xml(error_code const& e
}
parse_state s;
xml_parse((char*)p.get_body().begin, (char*)p.get_body().end
xml_parse(const_cast<char*>(p.get_body().begin),
const_cast<char*>(p.get_body().end)
, boost::bind(&find_control_url, _1, _2, boost::ref(s)));
if (s.control_url.empty())
{
@ -987,12 +968,14 @@ void upnp::on_upnp_xml(error_code const& e
+ to_string(d.port).elems + s.control_url;
}
char msg[500];
snprintf(msg, sizeof(msg), "found control URL: %s namespace %s "
"urlbase: %s in response from %s"
, d.control_url.c_str(), d.service_namespace
, s.url_base.c_str(), d.url.c_str());
log(msg, l);
{
char msg[500];
snprintf(msg, sizeof(msg), "found control URL: %s namespace %s "
"urlbase: %s in response from %s"
, d.control_url.c_str(), d.service_namespace
, s.url_base.c_str(), d.url.c_str());
log(msg, l);
}
boost::tie(protocol, auth, d.hostname, d.port, d.path)
= parse_url_components(d.control_url, ec);
@ -1235,13 +1218,15 @@ void upnp::on_upnp_get_ip_address_response(error_code const& e
// </s:Body>
// </s:Envelope>
char msg[500];
snprintf(msg, sizeof(msg), "get external IP address response: %s"
, std::string(p.get_body().begin, p.get_body().end).c_str());
log(msg, l);
{
char msg[500];
snprintf(msg, sizeof(msg), "get external IP address response: %s"
, std::string(p.get_body().begin, p.get_body().end).c_str());
log(msg, l);
}
ip_address_parse_state s;
xml_parse((char*)p.get_body().begin, (char*)p.get_body().end
xml_parse(const_cast<char*>(p.get_body().begin), const_cast<char*>(p.get_body().end)
, boost::bind(&find_ip_address, _1, _2, boost::ref(s)));
if (s.error_code != -1)
{
@ -1252,6 +1237,7 @@ void upnp::on_upnp_get_ip_address_response(error_code const& e
}
if (!s.ip_address.empty()) {
char msg[500];
snprintf(msg, sizeof(msg), "got router external IP address %s", s.ip_address.c_str());
log(msg, l);
d.external_ip = address::from_string(s.ip_address.c_str(), ignore_error);
@ -1333,7 +1319,8 @@ void upnp::on_upnp_map_response(error_code const& e
// since those might contain valid UPnP error codes
error_code_parse_state s;
xml_parse((char*)p.get_body().begin, (char*)p.get_body().end
xml_parse(const_cast<char*>(p.get_body().begin)
, const_cast<char*>(p.get_body().end)
, boost::bind(&find_error_code, _1, _2, boost::ref(s)));
if (s.error_code != -1)
@ -1474,7 +1461,8 @@ void upnp::on_upnp_unmap_response(error_code const& e
error_code_parse_state s;
if (p.header_finished())
{
xml_parse((char*)p.get_body().begin, (char*)p.get_body().end
xml_parse(const_cast<char*>(p.get_body().begin)
, const_cast<char*>(p.get_body().end)
, boost::bind(&find_error_code, _1, _2, boost::ref(s)));
}
@ -1551,7 +1539,7 @@ void upnp::close()
TORRENT_ASSERT(d.magic == 1337);
if (d.control_url.empty()) continue;
for (std::vector<mapping_t>::iterator j = d.mapping.begin()
, end(d.mapping.end()); j != end; ++j)
, end2(d.mapping.end()); j != end2; ++j)
{
if (j->protocol == none) continue;
if (j->action == mapping_t::action_add)

View File

@ -326,7 +326,7 @@ namespace libtorrent { namespace
peers4_t::value_type v(adr.address().to_v4().to_bytes(), adr.port());
peers4_t::iterator j = std::lower_bound(m_peers.begin(), m_peers.end(), v);
if (j != m_peers.end() && *j == v) m_peers.erase(j);
}
}
}
p = pex_msg.dict_find_string("added");
@ -358,7 +358,7 @@ namespace libtorrent { namespace
if (j != m_peers.end() && *j == v) continue;
m_peers.insert(j, v);
m_torrent.add_peer(adr, peer_info::pex, flags);
}
}
}
#if TORRENT_USE_IPV6
@ -673,7 +673,7 @@ namespace libtorrent
bool was_introduced_by(peer_plugin const* pp, tcp::endpoint const& ep)
{
ut_pex_peer_plugin* p = (ut_pex_peer_plugin*)pp;
ut_pex_peer_plugin const* p = static_cast<ut_pex_peer_plugin const*>(pp);
#if TORRENT_USE_IPV6
if (ep.address().is_v4())
{
@ -687,7 +687,7 @@ namespace libtorrent
else
{
ut_pex_peer_plugin::peers6_t::value_type v(ep.address().to_v6().to_bytes(), ep.port());
ut_pex_peer_plugin::peers6_t::iterator i
ut_pex_peer_plugin::peers6_t::const_iterator i
= std::lower_bound(p->m_peers6.begin(), p->m_peers6.end(), v);
return i != p->m_peers6.end() && *i == v;
}

View File

@ -37,6 +37,8 @@ POSSIBILITY OF SUCH DAMAGE.
namespace libtorrent
{
// TODO: 3 make this take a const buffer instead (and pass in string length
// to callback function). Then remove all associated const_casts.
TORRENT_EXTRA_EXPORT void xml_parse(char* p, char* end
, boost::function<void(int,char const*,char const*)> callback)
{
@ -61,7 +63,7 @@ namespace libtorrent
}
if (p == end) break;
// skip '<'
++p;
if (p != end && p+8 < end && string_begins_no_case("![CDATA[", p))
@ -79,7 +81,7 @@ namespace libtorrent
callback(token, start, val_start);
break;
}
token = xml_string;
char tmp = p[-2];
p[-2] = 0;

View File

@ -235,23 +235,6 @@ char upnp_xml2[] =
using namespace libtorrent;
namespace libtorrent {
struct parse_state
{
parse_state(): in_service(false){}
bool in_service;
std::list<std::string> tag_stack;
std::string control_url;
std::string service_type;
std::string model;
std::string url_base;
};
TORRENT_EXTRA_EXPORT void find_control_url(int type\
, char const* string, parse_state& state);
}
void parser_callback(std::string& out, int token, char const* s, char const* val)
{
switch (token)