fix some warnings

This commit is contained in:
arvidn 2015-08-16 12:17:23 -04:00
parent 506d515151
commit 9a0092c120
26 changed files with 270 additions and 213 deletions

View File

@ -1832,18 +1832,18 @@ namespace libtorrent {
}
dht_direct_response_alert::dht_direct_response_alert(
aux::stack_allocator& alloc, void* userdata
aux::stack_allocator& alloc, void* userdata_
, udp::endpoint const& addr, bdecode_node const& response)
: userdata(userdata), addr(addr), m_alloc(alloc)
: userdata(userdata_), addr(addr), m_alloc(alloc)
, m_response_idx(alloc.copy_buffer(response.data_section().first, response.data_section().second))
, m_response_size(response.data_section().second)
{}
dht_direct_response_alert::dht_direct_response_alert(
aux::stack_allocator& alloc
, void* userdata
, udp::endpoint const& addr)
: userdata(userdata), addr(addr), m_alloc(alloc)
, void* userdata_
, udp::endpoint const& addr_)
: userdata(userdata_), addr(addr_), m_alloc(alloc)
, m_response_idx(-1), m_response_size(0)
{}

View File

@ -30,6 +30,7 @@ POSSIBILITY OF SUCH DAMAGE.
*/
#include "libtorrent/config.hpp"
#include "libtorrent/storage.hpp"
#include "libtorrent/disk_io_thread.hpp"
#include "libtorrent/disk_buffer_holder.hpp"

View File

@ -30,6 +30,18 @@ POSSIBILITY OF SUCH DAMAGE.
*/
#ifdef __GNUC__
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wunused-macros"
#endif
#ifdef __clang__
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wunused-macros"
#endif
// these defines are just in case the system we're on needs them for 64 bit file
// support
#define _FILE_OFFSET_BITS 64
#define _LARGE_FILES 1
@ -40,6 +52,14 @@ POSSIBILITY OF SUCH DAMAGE.
# define __MINGW_USE_VC2005_COMPAT
#endif
#ifdef __clang__
#pragma clang diagnostic pop
#endif
#ifdef __GNUC__
#pragma GCC diagnostic pop
#endif
#include "libtorrent/config.hpp"
#include "libtorrent/alloca.hpp"
#include "libtorrent/allocator.hpp" // page_size

View File

@ -127,7 +127,8 @@ namespace libtorrent { namespace aux
boost::int64_t file_offset = off - fs.file_offset(file_index);
TORRENT_ASSERT(file_index != fs.num_files());
TORRENT_ASSERT(file_offset <= fs.file_size(file_index));
int add = (std::min)(fs.file_size(file_index) - file_offset, (boost::int64_t)size);
int add = (std::min)(fs.file_size(file_index)
- file_offset, boost::int64_t(size));
m_file_progress[file_index] += add;
TORRENT_ASSERT(m_file_progress[file_index]

View File

@ -138,7 +138,7 @@ void lsd::announce_impl(sha1_hash const& ih, int listen_port, bool broadcast
#endif
char ih_hex[41];
to_hex((char const*)&ih[0], 20, ih_hex);
to_hex(ih.data(), 20, ih_hex);
char msg[200];
#ifndef TORRENT_DISABLE_LOGGING
@ -279,7 +279,7 @@ void lsd::on_announce(udp::endpoint const& from, char* buf
}
sha1_hash ih(0);
from_hex(ih_str.c_str(), 40, (char*)&ih[0]);
from_hex(ih_str.c_str(), 40, ih.data());
if (!ih.is_all_zeros() && port != 0)
{

View File

@ -112,12 +112,14 @@ namespace libtorrent
#ifndef TORRENT_NO_DEPRECATE
torrent_handle add_magnet_uri_deprecated(session& ses, std::string const& uri
, add_torrent_params p, error_code& ec)
{
parse_magnet_uri(uri, p, ec);
if (ec) return torrent_handle();
return ses.add_torrent(p, ec);
namespace {
torrent_handle add_magnet_uri_deprecated(session& ses, std::string const& uri
, add_torrent_params p, error_code& ec)
{
parse_magnet_uri(uri, p, ec);
if (ec) return torrent_handle();
return ses.add_torrent(p, ec);
}
}
torrent_handle add_magnet_uri(session& ses, std::string const& uri
@ -147,13 +149,13 @@ namespace libtorrent
if (!display_name.empty()) params.name = unescape_string(display_name.c_str(), ec);
std::string tracker_string = url_has_argument(uri, "tr");
if (!tracker_string.empty()) params.trackers.push_back(unescape_string(tracker_string.c_str(), ec));
std::string btih = url_has_argument(uri, "xt");
if (btih.empty()) return torrent_handle();
if (btih.compare(0, 9, "urn:btih:") != 0) return torrent_handle();
if (btih.size() == 40 + 9) from_hex(&btih[9], 40, (char*)&params.info_hash[0]);
if (btih.size() == 40 + 9) from_hex(&btih[9], 40, params.info_hash.data());
else params.info_hash.assign(base32decode(btih.substr(9)));
return ses.add_torrent(params);
@ -175,9 +177,11 @@ namespace libtorrent
ec.clear();
std::string name;
error_code e;
std::string display_name = url_has_argument(uri, "dn");
if (!display_name.empty()) name = unescape_string(display_name.c_str(), e);
{
error_code e;
std::string display_name = url_has_argument(uri, "dn");
if (!display_name.empty()) name = unescape_string(display_name.c_str(), e);
}
// parse trackers out of the magnet link
std::string::size_type pos = std::string::npos;
@ -234,7 +238,7 @@ namespace libtorrent
if (port != 0)
p.dht_nodes.push_back(std::make_pair(node.substr(0, divider), port));
}
node_pos = uri.find("&dht=", node_pos);
if (node_pos == std::string::npos) break;
node_pos += 5;
@ -243,7 +247,7 @@ namespace libtorrent
#endif
sha1_hash info_hash;
if (btih.size() == 40 + 9) from_hex(&btih[9], 40, (char*)&info_hash[0]);
if (btih.size() == 40 + 9) from_hex(&btih[9], 40, info_hash.data());
else info_hash.assign(base32decode(btih.substr(9)));
p.info_hash = info_hash;

View File

@ -131,7 +131,7 @@ namespace libtorrent { namespace
virtual boost::shared_ptr<peer_plugin> new_connection(
peer_connection_handle const& pc);
buffer::const_interval metadata() const
{
if (!m_metadata)
@ -162,13 +162,13 @@ namespace libtorrent { namespace
std::pair<int, int> req = offset_to_req(std::make_pair(offset, size)
, total_size);
TORRENT_ASSERT(req.first + req.second <= (int)m_have_metadata.size());
TORRENT_ASSERT(req.first + req.second <= int(m_have_metadata.size()));
std::fill(
m_have_metadata.begin() + req.first
, m_have_metadata.begin() + req.first + req.second
, true);
bool have_all = std::count(
m_have_metadata.begin()
, m_have_metadata.end()
@ -335,7 +335,7 @@ namespace libtorrent { namespace
if (m_torrent.valid_metadata())
{
std::pair<int, int> offset
= req_to_offset(req, (int)m_tp.metadata().left());
= req_to_offset(req, int(m_tp.metadata().left()));
char msg[15];
char* ptr = msg;
@ -351,7 +351,7 @@ namespace libtorrent { namespace
detail::write_uint8(m_message_index, ptr);
// means 'data packet'
detail::write_uint8(1, ptr);
detail::write_uint32((int)m_tp.metadata().left(), ptr);
detail::write_uint32(int(m_tp.metadata().left()), ptr);
detail::write_uint32(offset.first, ptr);
m_pc.send_buffer(msg, sizeof(msg));
@ -566,7 +566,7 @@ namespace libtorrent { namespace
int min = *std::min_element(m_requested_metadata.begin() + i
, m_requested_metadata.begin() + i + num_blocks);
min += std::accumulate(m_requested_metadata.begin() + i
, m_requested_metadata.begin() + i + num_blocks, (int)0);
, m_requested_metadata.begin() + i + num_blocks, int(0));
if (min_element > min)
{

View File

@ -296,7 +296,7 @@ namespace libtorrent
TORRENT_UNUSED(ec);
// not implemented
assert(false);
TORRENT_ASSERT(false);
}
void part_file::export_file(file& f, boost::int64_t offset, boost::int64_t size, error_code& ec)

View File

@ -3721,12 +3721,14 @@ namespace libtorrent
// we cannot suggest a piece we don't have!
#if TORRENT_USE_ASSERTS
boost::shared_ptr<torrent> t = m_torrent.lock();
TORRENT_ASSERT(t);
TORRENT_ASSERT(t->has_piece_passed(piece));
{
boost::shared_ptr<torrent> t = m_torrent.lock();
TORRENT_ASSERT(t);
TORRENT_ASSERT(t->has_piece_passed(piece));
TORRENT_ASSERT(piece >= 0 && piece < t->torrent_file().num_pieces());
}
#endif
TORRENT_ASSERT(piece >= 0 && piece < t->torrent_file().num_pieces());
if (m_sent_suggested_pieces.empty())
{
@ -3940,7 +3942,6 @@ namespace libtorrent
m_peer_info->supports_utp = false;
// reconnect immediately using TCP
torrent_peer* pi = peer_info_struct();
boost::shared_ptr<torrent> t = m_torrent.lock();
fast_reconnect(true);
disconnect(e, op_connect, 0);
if (t && pi) t->connect_to_peer(pi, true);
@ -3957,7 +3958,6 @@ namespace libtorrent
&& m_peer_info->supports_holepunch
&& !m_holepunch_mode)
{
boost::shared_ptr<torrent> t = m_torrent.lock();
// see if we can try a holepunch
bt_peer_connection* p = t->find_introducer(remote());
if (p)
@ -6080,14 +6080,13 @@ namespace libtorrent
trancieve_ip_packet(bytes_in_loop, m_remote.address().is_v6());
return;
}
TORRENT_ASSERT(bytes_transferred > 0);
m_recv_buffer.received(bytes_transferred);
int bytes = bytes_transferred;
int sub_transferred = 0;
do {
INVARIANT_CHECK;
// TODO: The stats checks can not be honored when authenticated encryption is in use
// because we may have encrypted data which we cannot authenticate yet
#if 0
@ -6106,7 +6105,7 @@ namespace libtorrent
m_statistics.last_protocol_downloaded() - cur_protocol_dl;
TORRENT_ASSERT(stats_diff == int(sub_transferred));
#endif
if (m_disconnecting) return;
if (m_disconnecting) return;
} while (bytes > 0 && sub_transferred > 0);

View File

@ -217,6 +217,7 @@ bool peer_connection_handle::failed() const
return pc->failed();
}
TORRENT_FORMAT(4,5)
void peer_connection_handle::peer_log(peer_log_alert::direction_t direction
, char const* event, char const* fmt, ...) const
{

View File

@ -214,10 +214,11 @@ namespace libtorrent
downloading_piece ret;
ret.index = piece;
int download_state = piece_pos::piece_downloading;
std::vector<downloading_piece>::iterator i
std::vector<downloading_piece>::iterator downloading_iter
= std::lower_bound(m_downloads[download_state].begin()
, m_downloads[download_state].end(), ret);
TORRENT_ASSERT(i == m_downloads[download_state].end() || i->index != piece);
TORRENT_ASSERT(downloading_iter == m_downloads[download_state].end()
|| downloading_iter->index != piece);
TORRENT_ASSERT(block_index >= 0);
TORRENT_ASSERT(block_index < (std::numeric_limits<boost::uint16_t>::max)());
ret.info_idx = block_index;
@ -246,12 +247,12 @@ namespace libtorrent
VALGRIND_CHECK_VALUE_IS_DEFINED(ret.info_idx);
VALGRIND_CHECK_VALUE_IS_DEFINED(ret.index);
#endif
i = m_downloads[download_state].insert(i, ret);
downloading_iter = m_downloads[download_state].insert(downloading_iter, ret);
#if TORRENT_USE_INVARIANT_CHECKS
check_piece_state();
#endif
return i;
return downloading_iter;
}
void piece_picker::erase_download_piece(std::vector<downloading_piece>::iterator i)
@ -344,11 +345,11 @@ namespace libtorrent
TORRENT_ASSERT(int(dp.info_idx) * m_blocks_per_piece
+ m_blocks_per_piece <= int(m_block_info.size()));
block_info const* info = blocks_for_piece(dp);
for (int k = 0; k < m_blocks_per_piece; ++k)
for (int j = 0; j < m_blocks_per_piece; ++j)
{
if (info[k].peer)
if (info[j].peer)
{
torrent_peer* p = static_cast<torrent_peer*>(info[k].peer);
torrent_peer* p = static_cast<torrent_peer*>(info[j].peer);
TORRENT_ASSERT(p->in_use);
TORRENT_ASSERT(p->connection == NULL
|| static_cast<peer_connection*>(p->connection)->m_in_use);
@ -452,7 +453,7 @@ namespace libtorrent
void piece_picker::check_invariant(torrent const* t) const
{
#ifndef TORRENT_DEBUG_REFCOUNTS
#if TORRENT_OPTIMIZE_MEMORY_USAGE
#ifdef TORRENT_OPTIMIZE_MEMORY_USAGE
TORRENT_ASSERT(sizeof(piece_pos) == 4);
#else
TORRENT_ASSERT(sizeof(piece_pos) == 8);
@ -478,10 +479,10 @@ namespace libtorrent
+ m_blocks_per_piece <= int(m_block_info.size()));
#if TORRENT_USE_ASSERTS
block_info const* info = blocks_for_piece(dp);
for (int k = 0; k < m_blocks_per_piece; ++k)
for (int j = 0; j < m_blocks_per_piece; ++j)
{
if (!info[k].peer) continue;
torrent_peer* p = static_cast<torrent_peer*>(info[k].peer);
if (!info[j].peer) continue;
torrent_peer* p = static_cast<torrent_peer*>(info[j].peer);
TORRENT_ASSERT(p->in_use);
TORRENT_ASSERT(p->connection == NULL
|| static_cast<peer_connection*>(p->connection)->m_in_use);
@ -500,7 +501,7 @@ namespace libtorrent
, end(m_downloads[j].end()); i != end; ++i)
{
TORRENT_ASSERT(m_piece_map[i->index].download_queue() == j);
int num_blocks = blocks_in_piece(i->index);
const int num_blocks = blocks_in_piece(i->index);
int num_requested = 0;
int num_finished = 0;
int num_writing = 0;
@ -593,24 +594,26 @@ namespace libtorrent
return;
#endif
int index = 0;
for (std::vector<piece_pos>::const_iterator i = m_piece_map.begin()
, end(m_piece_map.end()); i != end && (i->have() || i->filtered());
++i, ++index);
TORRENT_ASSERT(m_cursor == index);
index = num_pieces;
if (num_pieces > 0)
{
for (std::vector<piece_pos>::reverse_iterator i = m_piece_map.rend()
- index; index > 0 && (i->have() || i->filtered()); ++i, --index);
TORRENT_ASSERT(index == num_pieces
|| m_piece_map[index].have()
|| m_piece_map[index].filtered());
TORRENT_ASSERT(m_reverse_cursor == index);
}
else
{
TORRENT_ASSERT(m_reverse_cursor == 0);
int index = 0;
for (std::vector<piece_pos>::const_iterator i = m_piece_map.begin()
, end(m_piece_map.end()); i != end && (i->have() || i->filtered());
++i, ++index);
TORRENT_ASSERT(m_cursor == index);
index = num_pieces;
if (num_pieces > 0)
{
for (std::vector<piece_pos>::reverse_iterator i = m_piece_map.rend()
- index; index > 0 && (i->have() || i->filtered()); ++i, --index);
TORRENT_ASSERT(index == num_pieces
|| m_piece_map[index].have()
|| m_piece_map[index].filtered());
TORRENT_ASSERT(m_reverse_cursor == index);
}
else
{
TORRENT_ASSERT(m_reverse_cursor == 0);
}
}
int num_filtered = 0;
@ -2258,7 +2261,7 @@ namespace libtorrent
{
TORRENT_ASSERT(m_piece_map[k].downloading() == false);
TORRENT_ASSERT(m_piece_map[k].priority(this) >= 0);
int num_blocks_in_piece = blocks_in_piece(k);
const int num_blocks_in_piece = blocks_in_piece(k);
for (int j = 0; j < num_blocks_in_piece; ++j)
{
pc.inc_stats_counter(counters::piece_picker_rand_loops);
@ -2361,8 +2364,8 @@ get_out:
bool found = false;
for (std::vector<piece_block>::const_iterator j
= interesting_blocks.begin(), end(interesting_blocks.end());
j != end; ++j)
= interesting_blocks.begin(), end2(interesting_blocks.end());
j != end2; ++j)
{
if (j->piece_index != dp.index) continue;
found = true;
@ -2405,7 +2408,7 @@ get_out:
TORRENT_ASSERT(piece_priority(dp->index) > 0);
// fill in with blocks requested from other peers
// as backups
int num_blocks_in_piece = blocks_in_piece(dp->index);
const int num_blocks_in_piece = blocks_in_piece(dp->index);
TORRENT_ASSERT(dp->requested > 0);
block_info const* binfo = blocks_for_piece(*dp);
for (int j = 0; j < num_blocks_in_piece; ++j)
@ -2449,7 +2452,7 @@ get_out:
&& piece_priority(i->index) != priority_levels - 1)
continue;
int num_blocks_in_piece = blocks_in_piece(i->index);
const int num_blocks_in_piece = blocks_in_piece(i->index);
block_info const* binfo = blocks_for_piece(*i);
for (int j = 0; j < num_blocks_in_piece; ++j)
{
@ -2468,12 +2471,13 @@ get_out:
for (std::vector<downloading_piece>::const_iterator l
= m_downloads[piece_pos::piece_downloading].begin()
, end(m_downloads[piece_pos::piece_downloading].end()); l != end; ++l)
, end2(m_downloads[piece_pos::piece_downloading].end());
l != end2; ++l)
{
block_info const* binfo2 = blocks_for_piece(*l);
fprintf(stderr, "%d : ", l->index);
int num_blocks_in_piece = blocks_in_piece(l->index);
for (int m = 0; m < num_blocks_in_piece; ++m)
const int cnt = blocks_in_piece(l->index);
for (int m = 0; m < cnt; ++m)
fprintf(stderr, "%d", binfo2[m].state);
fprintf(stderr, "\n");
}
@ -2501,7 +2505,7 @@ get_out:
// this assert is not valid for web_seeds
/*
int num_blocks_in_piece = blocks_in_piece(k->index);
const int num_blocks_in_piece = blocks_in_piece(k->index);
block_info const* binfo = blocks_for_piece(*k);
for (int j = 0; j < num_blocks_in_piece; ++j)
{
@ -3433,7 +3437,7 @@ get_out:
}
}
void piece_picker::mark_as_canceled(piece_block block, void* peer)
void piece_picker::mark_as_canceled(const piece_block block, void* peer)
{
#ifdef TORRENT_PICKER_LOG
std::cerr << "[" << this << "] " << "mark_as_cancelled( {"
@ -3477,7 +3481,6 @@ get_out:
if (i->finished + i->writing + i->requested == 0)
{
piece_pos& p = m_piece_map[block.piece_index];
int prev_priority = p.priority(this);
erase_download_piece(i);
int new_priority = p.priority(this);
@ -3625,7 +3628,7 @@ get_out:
d.clear();
int state = m_piece_map[index].download_queue();
int num_blocks = blocks_in_piece(index);
const int num_blocks = blocks_in_piece(index);
d.reserve(num_blocks);
if (state == piece_pos::piece_open)

View File

@ -84,8 +84,8 @@ namespace libtorrent
desired_queue_size = (std::min)(1, desired_queue_size);
int num_requests = desired_queue_size
- (int)c.download_queue().size()
- (int)c.request_queue().size();
- int(c.download_queue().size())
- int(c.request_queue().size());
#ifndef TORRENT_DISABLE_LOGGING
c.peer_log(peer_log_alert::info, "PIECE_PICKER"

View File

@ -75,11 +75,11 @@ namespace libtorrent
if (m_cache.size() > m_max_size)
{
cache_t::iterator oldest = m_cache.begin();
for (cache_t::iterator i = m_cache.begin();
i != m_cache.end(); ++i)
for (cache_t::iterator k = m_cache.begin();
k != m_cache.end(); ++k)
{
if (i->second.last_seen < oldest->second.last_seen)
oldest = i;
if (k->second.last_seen < oldest->second.last_seen)
oldest = k;
}
// remove the oldest entry

View File

@ -36,6 +36,16 @@ POSSIBILITY OF SUCH DAMAGE.
#include "libtorrent/torrent.hpp"
#include "libtorrent/lazy_entry.hpp"
#ifdef __GNUC__
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wunused-macros"
#endif
#ifdef __clang__
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wunused-macros"
#endif
#define TORRENT_ASYNC_CALL(x) \
m_impl->get_io_service().dispatch(boost::bind(&session_impl:: x, m_impl))
@ -75,6 +85,14 @@ POSSIBILITY OF SUCH DAMAGE.
#define TORRENT_SYNC_CALL_RET3(type, x, a1, a2, a3) \
aux::sync_call_ret<type>(*m_impl, boost::function<type(void)>(boost::bind(&session_impl:: x, m_impl, a1, a2, a3)))
#ifdef __clang__
#pragma clang diagnostic pop
#endif
#ifdef __GNUC__
#pragma GCC diagnostic pop
#endif
using libtorrent::aux::session_impl;
namespace libtorrent
@ -863,7 +881,7 @@ namespace libtorrent
| alert::dht_notification); break;
case alert::critical: m = alert::error_notification | alert::storage_notification; break;
case alert::fatal: m = alert::error_notification; break;
default: break;
case alert::none: m = 0; break;
}
settings_pack p;

View File

@ -353,6 +353,10 @@ namespace aux {
session_impl::session_impl(io_service& ios)
:
#ifndef TORRENT_NO_DEPRECATE
m_next_rss_update(min_time())
,
#endif
#ifndef TORRENT_DISABLE_POOL_ALLOCATOR
m_send_buffers(send_buffer_size())
,
@ -403,9 +407,6 @@ namespace aux {
, m_last_second_tick(m_created - milliseconds(900))
, m_last_choke(m_created)
, m_last_auto_manage(m_created)
#ifndef TORRENT_NO_DEPRECATE
, m_next_rss_update(min_time())
#endif
, m_next_port(0)
#ifndef TORRENT_DISABLE_DHT
, m_dht_announce_timer(m_io_service)
@ -1666,8 +1667,10 @@ namespace aux {
// may end up binding to the same socket as some other random
// application. Don't do it!
#ifndef TORRENT_WINDOWS
error_code err; // ignore errors here
ret.sock->set_option(tcp::acceptor::reuse_address(true), err);
{
error_code err; // ignore errors here
ret.sock->set_option(tcp::acceptor::reuse_address(true), err);
}
#endif
#if TORRENT_USE_IPV6

View File

@ -218,6 +218,10 @@ namespace libtorrent
void socket_type::construct(int type, void* userdata)
{
#ifndef TORRENT_USE_OPENSSL
TORRENT_UNUSED(userdata);
#endif
destruct();
switch (type)
{
@ -260,8 +264,6 @@ namespace libtorrent
new ((ssl_stream<utp_stream>*)m_data) ssl_stream<utp_stream>(m_io_service
, *static_cast<ssl::context*>(userdata));
break;
#else
TORRENT_UNUSED(userdata);
#endif
default: TORRENT_ASSERT(false);
}

View File

@ -198,7 +198,7 @@ namespace libtorrent
// start sub-negotiation
m_buffer.resize(m_user.size() + m_password.size() + 3);
char* p = &m_buffer[0];
p = &m_buffer[0];
write_uint8(1, p);
write_uint8(m_user.size(), p);
write_string(m_user, p);

View File

@ -149,7 +149,8 @@ namespace libtorrent
size += bufs->iov_len;
if (size >= bytes)
{
reinterpret_cast<char*&>(bufs->iov_base) += bufs->iov_len - (size - bytes);
bufs->iov_base = reinterpret_cast<char*>(bufs->iov_base)
+ bufs->iov_len - (size - bytes);
bufs->iov_len = size - bytes;
return;
}

View File

@ -2041,7 +2041,7 @@ namespace libtorrent
std::vector<boost::shared_ptr<torrent> > ts = m_ses.find_collection(*i);
for (std::vector<boost::shared_ptr<torrent> >::iterator k = ts.begin()
, end(ts.end()); k != end; ++k)
, end2(ts.end()); k != end2; ++k)
{
// Only attempt to reuse files from torrents that are seeding.
// TODO: this could be optimized by looking up which files are
@ -2674,7 +2674,7 @@ namespace libtorrent
m_ses.disk_thread().async_hash(m_storage.get(), m_checking_piece++
, disk_io_job::sequential_access | disk_io_job::volatile_read
, boost::bind(&torrent::on_piece_hashed
, shared_from_this(), _1), (void*)1);
, shared_from_this(), _1), reinterpret_cast<void*>(1));
if (m_checking_piece >= m_torrent_file->num_pieces()) break;
}
#ifndef TORRENT_DISABLE_LOGGING
@ -2822,7 +2822,7 @@ namespace libtorrent
m_ses.disk_thread().async_hash(m_storage.get(), m_checking_piece++
, disk_io_job::sequential_access | disk_io_job::volatile_read
, boost::bind(&torrent::on_piece_hashed
, shared_from_this(), _1), (void*)1);
, shared_from_this(), _1), reinterpret_cast<void*>(1));
#ifndef TORRENT_DISABLE_LOGGING
debug_log("on_piece_hashed, m_checking_piece: %d", m_checking_piece);
#endif
@ -4995,11 +4995,12 @@ namespace libtorrent
boost::uint32_t torrent::tracker_key() const
{
uintptr_t self = (uintptr_t)this;
uintptr_t ses = (uintptr_t)&m_ses;
sha1_hash h = hasher((char*)&self, sizeof(self))
.update((char*)&m_storage, sizeof(m_storage))
.update((char*)&ses, sizeof(ses))
uintptr_t self = reinterpret_cast<uintptr_t>(this);
uintptr_t ses = reinterpret_cast<uintptr_t>(&m_ses);
uintptr_t storage = reinterpret_cast<uintptr_t>(m_storage.get());
sha1_hash h = hasher(reinterpret_cast<char const*>(&self), sizeof(self))
.update(reinterpret_cast<char const*>(&storage), sizeof(storage))
.update(reinterpret_cast<char const*>(&ses), sizeof(ses))
.final();
unsigned char const* ptr = &h[0];
return detail::read_uint32(ptr);
@ -5133,7 +5134,7 @@ namespace libtorrent
for (std::vector<void*>::iterator i = downloaders.begin()
, end(downloaders.end()); i != end; ++i, ++block)
{
torrent_peer* p = (torrent_peer*)*i;
torrent_peer* p = static_cast<torrent_peer*>(*i);
if (p == 0 || p->connection == 0) continue;
peer_connection* peer = static_cast<peer_connection*>(p->connection);
peer->make_time_critical(piece_block(piece, block));
@ -5672,10 +5673,10 @@ namespace libtorrent
// the bitmask need to have exactly one bit for every file
// in the torrent
TORRENT_ASSERT((int)bitmask.size() == m_torrent_file->num_files());
TORRENT_ASSERT(int(bitmask.size()) == m_torrent_file->num_files());
if (int(bitmask.size()) != m_torrent_file->num_files()) return;
boost::int64_t position = 0;
if (m_torrent_file->num_pieces())
@ -5684,13 +5685,13 @@ namespace libtorrent
// mark all pieces as filtered, then clear the bits for files
// that should be downloaded
std::vector<bool> piece_filter(m_torrent_file->num_pieces(), true);
for (int i = 0; i < (int)bitmask.size(); ++i)
for (int i = 0; i < int(bitmask.size()); ++i)
{
boost::int64_t start = position;
position += m_torrent_file->files().file_size(i);
// is the file selected for download?
if (!bitmask[i])
{
{
// mark all pieces of the file as downloadable
int start_piece = int(start / piece_length);
int last_piece = int(position / piece_length);
@ -7339,9 +7340,9 @@ namespace libtorrent
{
partial_piece_info pi;
pi.blocks_in_piece = p.blocks_in_piece(i->index);
pi.finished = (int)i->finished;
pi.writing = (int)i->writing;
pi.requested = (int)i->requested;
pi.finished = int(i->finished);
pi.writing = int(i->writing);
pi.requested = int(i->requested);
TORRENT_ASSERT(counter * blocks_per_piece + pi.blocks_in_piece <= int(blk.size()));
pi.blocks = &blk[counter * blocks_per_piece];
int piece_size = int(torrent_file().piece_size(i->index));
@ -9695,8 +9696,7 @@ namespace libtorrent
, end(m_trackers.end()); i != end; ++i)
{
#ifndef TORRENT_DISABLE_LOGGING
char msg[1000];
snprintf(msg, sizeof(msg), "*** tracker: \"%s\" "
debug_log("*** tracker: \"%s\" "
"[ tiers: %d trackers: %d"
" found: %d i->tier: %d tier: %d"
" working: %d fails: %d limit: %d upd: %d ]"
@ -9704,7 +9704,6 @@ namespace libtorrent
, settings().get_bool(settings_pack::announce_to_all_trackers), found_working
, i->tier, tier, i->is_working(), i->fails, i->fail_limit
, i->updating);
debug_log(msg);
#endif
if (settings().get_bool(settings_pack::announce_to_all_tiers)
&& found_working
@ -9733,12 +9732,10 @@ namespace libtorrent
}
#ifndef TORRENT_DISABLE_LOGGING
char msg[200];
snprintf(msg, sizeof(msg), "*** update tracker timer: next_announce < now %d"
debug_log("*** update tracker timer: next_announce < now %d"
" m_waiting_tracker: %d next_announce_in: %d"
, next_announce <= now, m_waiting_tracker
, int(total_seconds(now - next_announce)));
debug_log(msg);
#endif
if (next_announce <= now) next_announce = now;

View File

@ -58,12 +58,83 @@ POSSIBILITY OF SUCH DAMAGE.
#include "libtorrent/utf8.hpp"
#include "libtorrent/thread.hpp"
#if defined(_MSC_VER) && _MSC_VER < 1300
namespace std
{
using ::srand;
using ::isalnum;
};
#ifdef __GNUC__
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wunused-macros"
#endif
#ifdef __clang__
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wunused-macros"
#endif
#define TORRENT_ASYNC_CALL(x) \
boost::shared_ptr<torrent> t = m_torrent.lock(); \
if (!t) return; \
session_impl& ses = static_cast<session_impl&>(t->session()); \
ses.get_io_service().dispatch(boost::bind(&torrent:: x, t))
#define TORRENT_ASYNC_CALL1(x, a1) \
boost::shared_ptr<torrent> t = m_torrent.lock(); \
if (!t) return; \
session_impl& ses = static_cast<session_impl&>(t->session()); \
ses.get_io_service().dispatch(boost::bind(&torrent:: x, t, a1))
#define TORRENT_ASYNC_CALL2(x, a1, a2) \
boost::shared_ptr<torrent> t = m_torrent.lock(); \
if (!t) return; \
session_impl& ses = static_cast<session_impl&>(t->session()); \
ses.get_io_service().dispatch(boost::bind(&torrent:: x, t, a1, a2))
#define TORRENT_ASYNC_CALL3(x, a1, a2, a3) \
boost::shared_ptr<torrent> t = m_torrent.lock(); \
if (!t) return; \
session_impl& ses = static_cast<session_impl&>(t->session()); \
ses.get_io_service().dispatch(boost::bind(&torrent:: x, t, a1, a2, a3))
#define TORRENT_ASYNC_CALL4(x, a1, a2, a3, a4) \
boost::shared_ptr<torrent> t = m_torrent.lock(); \
if (!t) return; \
session_impl& ses = static_cast<session_impl&>(t->session()); \
ses.get_io_service().dispatch(boost::bind(&torrent:: x, t, a1, a2, a3, a4))
#define TORRENT_SYNC_CALL(x) \
boost::shared_ptr<torrent> t = m_torrent.lock(); \
if (t) aux::sync_call_handle(t, boost::bind(&torrent:: x, t));
#define TORRENT_SYNC_CALL1(x, a1) \
boost::shared_ptr<torrent> t = m_torrent.lock(); \
if (t) aux::sync_call_handle(t, boost::bind(&torrent:: x, t, a1));
#define TORRENT_SYNC_CALL2(x, a1, a2) \
boost::shared_ptr<torrent> t = m_torrent.lock(); \
if (t) aux::sync_call_handle(t, boost::bind(&torrent:: x, t, a1, a2));
#define TORRENT_SYNC_CALL3(x, a1, a2, a3) \
boost::shared_ptr<torrent> t = m_torrent.lock(); \
if (t) aux::sync_call_handle(t, boost::bind(&torrent:: x, t, a1, a2, a3));
#define TORRENT_SYNC_CALL_RET(type, def, x) \
boost::shared_ptr<torrent> t = m_torrent.lock(); \
type r = def; \
if (t) aux::sync_call_ret_handle(t, r, boost::function<type(void)>(boost::bind(&torrent:: x, t)));
#define TORRENT_SYNC_CALL_RET1(type, def, x, a1) \
boost::shared_ptr<torrent> t = m_torrent.lock(); \
type r = def; \
if (t) aux::sync_call_ret_handle(t, r, boost::function<type(void)>(boost::bind(&torrent:: x, t, a1)));
#define TORRENT_SYNC_CALL_RET2(type, def, x, a1, a2) \
boost::shared_ptr<torrent> t = m_torrent.lock(); \
type r = def; \
if (t) aux::sync_call_ret_handle(t, r, boost::function<type(void)>(boost::bind(&torrent:: x, t, a1, a2)));
#ifdef __clang__
#pragma clang diagnostic pop
#endif
#ifdef __GNUC__
#pragma GCC diagnostic pop
#endif
using libtorrent::aux::session_impl;
@ -141,67 +212,6 @@ namespace libtorrent
torrent_status::~torrent_status() {}
#define TORRENT_ASYNC_CALL(x) \
boost::shared_ptr<torrent> t = m_torrent.lock(); \
if (!t) return; \
session_impl& ses = static_cast<session_impl&>(t->session()); \
ses.get_io_service().dispatch(boost::bind(&torrent:: x, t))
#define TORRENT_ASYNC_CALL1(x, a1) \
boost::shared_ptr<torrent> t = m_torrent.lock(); \
if (!t) return; \
session_impl& ses = static_cast<session_impl&>(t->session()); \
ses.get_io_service().dispatch(boost::bind(&torrent:: x, t, a1))
#define TORRENT_ASYNC_CALL2(x, a1, a2) \
boost::shared_ptr<torrent> t = m_torrent.lock(); \
if (!t) return; \
session_impl& ses = static_cast<session_impl&>(t->session()); \
ses.get_io_service().dispatch(boost::bind(&torrent:: x, t, a1, a2))
#define TORRENT_ASYNC_CALL3(x, a1, a2, a3) \
boost::shared_ptr<torrent> t = m_torrent.lock(); \
if (!t) return; \
session_impl& ses = static_cast<session_impl&>(t->session()); \
ses.get_io_service().dispatch(boost::bind(&torrent:: x, t, a1, a2, a3))
#define TORRENT_ASYNC_CALL4(x, a1, a2, a3, a4) \
boost::shared_ptr<torrent> t = m_torrent.lock(); \
if (!t) return; \
session_impl& ses = static_cast<session_impl&>(t->session()); \
ses.get_io_service().dispatch(boost::bind(&torrent:: x, t, a1, a2, a3, a4))
#define TORRENT_SYNC_CALL(x) \
boost::shared_ptr<torrent> t = m_torrent.lock(); \
if (t) aux::sync_call_handle(t, boost::bind(&torrent:: x, t));
#define TORRENT_SYNC_CALL1(x, a1) \
boost::shared_ptr<torrent> t = m_torrent.lock(); \
if (t) aux::sync_call_handle(t, boost::bind(&torrent:: x, t, a1));
#define TORRENT_SYNC_CALL2(x, a1, a2) \
boost::shared_ptr<torrent> t = m_torrent.lock(); \
if (t) aux::sync_call_handle(t, boost::bind(&torrent:: x, t, a1, a2));
#define TORRENT_SYNC_CALL3(x, a1, a2, a3) \
boost::shared_ptr<torrent> t = m_torrent.lock(); \
if (t) aux::sync_call_handle(t, boost::bind(&torrent:: x, t, a1, a2, a3));
#define TORRENT_SYNC_CALL_RET(type, def, x) \
boost::shared_ptr<torrent> t = m_torrent.lock(); \
type r = def; \
if (t) aux::sync_call_ret_handle(t, r, boost::function<type(void)>(boost::bind(&torrent:: x, t)));
#define TORRENT_SYNC_CALL_RET1(type, def, x, a1) \
boost::shared_ptr<torrent> t = m_torrent.lock(); \
type r = def; \
if (t) aux::sync_call_ret_handle(t, r, boost::function<type(void)>(boost::bind(&torrent:: x, t, a1)));
#define TORRENT_SYNC_CALL_RET2(type, def, x, a1, a2) \
boost::shared_ptr<torrent> t = m_torrent.lock(); \
type r = def; \
if (t) aux::sync_call_ret_handle(t, r, boost::function<type(void)>(boost::bind(&torrent:: x, t, a1, a2)));
#ifndef BOOST_NO_EXCEPTIONS
void throw_invalid_handle()
{

View File

@ -656,10 +656,10 @@ void udp_socket::set_buf_size(int s)
if (s == m_buf_size) return;
bool no_mem = false;
void* tmp = realloc(m_buf, s);
char* tmp = static_cast<char*>(realloc(m_buf, s));
if (tmp != 0)
{
m_buf = (char*)tmp;
m_buf = tmp;
m_buf_size = s;
m_new_buf_size = s;
}
@ -1063,7 +1063,7 @@ void udp_socket::handshake2(error_code const& e)
}
// start sub-negotiation
char* p = &m_tmp_buf[0];
p = &m_tmp_buf[0];
write_uint8(1, p);
write_uint8(m_proxy_settings.username.size(), p);
write_string(m_proxy_settings.username, p);

View File

@ -606,7 +606,6 @@ namespace libtorrent
#ifndef TORRENT_DISABLE_LOGGING
if (cb)
{
boost::shared_ptr<request_callback> cb = requester();
cb->debug_log("<== UDP_TRACKER_RESPONSE [ url: %s ]", tracker_req().url.c_str());
}
#endif

View File

@ -67,7 +67,7 @@ namespace upnp_errors
} // upnp_errors namespace
static error_code ec;
static error_code ignore_error;
upnp::upnp(io_service& ios
, address const& listen_interface, std::string const& user_agent
@ -79,7 +79,8 @@ upnp::upnp(io_service& ios
, m_retry_count(0)
, m_io_service(ios)
, m_resolver(ios)
, m_socket(udp::endpoint(address_v4::from_string("239.255.255.250", ec), 1900))
, m_socket(udp::endpoint(address_v4::from_string("239.255.255.250"
, ignore_error), 1900))
, m_broadcast_timer(ios)
, m_refresh_timer(ios)
, m_map_timer(ios)
@ -699,10 +700,10 @@ void upnp::create_port_mapping(http_connection& c, rootdevice& d, int i)
char const* soap_action = "AddPortMapping";
error_code ec;
std::string local_endpoint = print_address(c.socket().local_endpoint(ec).address());
char soap[2048];
error_code ec;
snprintf(soap, sizeof(soap), "<?xml version=\"1.0\"?>\n"
"<s:Envelope xmlns:s=\"http://schemas.xmlsoap.org/soap/envelope/\" "
"s:encodingStyle=\"http://schemas.xmlsoap.org/soap/encoding/\">"
@ -1273,7 +1274,7 @@ void upnp::on_upnp_get_ip_address_response(error_code const& e
if (!s.ip_address.empty()) {
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(), ec);
d.external_ip = address::from_string(s.ip_address.c_str(), ignore_error);
} else {
log("failed to find external IP address in response", l);
}

View File

@ -46,7 +46,7 @@ namespace libtorrent
{
// ==== utf-8 -> wide ===
template<int width>
struct convert_to_wide
struct convert_to_wide
{
static utf8_conv_result_t convert(UTF8 const** src_start
, UTF8 const* src_end
@ -78,8 +78,8 @@ namespace libtorrent
{
// assume Latin-1
wide.clear();
std::copy((boost::uint8_t const*)*src_start
, (boost::uint8_t const*)src_end
std::copy(reinterpret_cast<boost::uint8_t const*>(*src_start)
,reinterpret_cast<boost::uint8_t const*>(src_end)
, std::back_inserter(wide));
return static_cast<utf8_conv_result_t>(ret);
}
@ -107,8 +107,8 @@ namespace libtorrent
{
// assume Latin-1
wide.clear();
std::copy((boost::uint8_t const*)*src_start
, (boost::uint8_t const*)src_end
std::copy(reinterpret_cast<boost::uint8_t const*>(*src_start)
, reinterpret_cast<boost::uint8_t const*>(src_end)
, std::back_inserter(wide));
return static_cast<utf8_conv_result_t>(ret);
}

View File

@ -205,9 +205,9 @@ namespace libtorrent
if (aux::time_now() - seconds(60) > m_last_route_update)
{
m_last_route_update = aux::time_now();
error_code ec;
m_routes = enum_routes(m_sock.get_io_service(), ec);
if (ec) return socket_ep;
error_code err;
m_routes = enum_routes(m_sock.get_io_service(), err);
if (err) return socket_ep;
}
if (m_routes.empty()) return socket_ep;
@ -236,9 +236,9 @@ namespace libtorrent
if (aux::time_now() - seconds(60) > m_last_if_update)
{
m_last_if_update = aux::time_now();
error_code ec;
m_interfaces = enum_net_interfaces(m_sock.get_io_service(), ec);
if (ec) return socket_ep;
error_code err;
m_interfaces = enum_net_interfaces(m_sock.get_io_service(), err);
if (err) return socket_ep;
}
for (std::vector<ip_interface>::iterator i = m_interfaces.begin()
@ -263,7 +263,7 @@ namespace libtorrent
if (size < int(sizeof(utp_header))) return false;
utp_header const* ph = (utp_header*)p;
utp_header const* ph = reinterpret_cast<utp_header const*>(p);
// UTP_LOGV("incoming packet version:%d\n", int(ph->get_version()));

View File

@ -466,6 +466,7 @@ public:
// the send and receive buffers
// maps packet sequence numbers
// TODO 3: if the packet_buffer was a template, we could avoid some pointer casts
packet_buffer m_inbuf;
packet_buffer m_outbuf;
@ -919,7 +920,7 @@ int utp_stream::read_buffer_size() const
void utp_stream::on_close_reason(void* self, boost::uint16_t close_reason)
{
utp_stream* s = (utp_stream*)self;
utp_stream* s = static_cast<utp_stream*>(self);
TORRENT_ASSERT(s->m_impl);
s->m_incoming_close_reason = close_reason;
}
@ -927,7 +928,7 @@ void utp_stream::on_close_reason(void* self, boost::uint16_t close_reason)
void utp_stream::on_read(void* self, size_t bytes_transferred
, error_code const& ec, bool kill)
{
utp_stream* s = (utp_stream*)self;
utp_stream* s = static_cast<utp_stream*>(self);
UTP_LOGV("%8p: calling read handler read:%d ec:%s kill:%d\n", s->m_impl
, int(bytes_transferred), ec.message().c_str(), kill);
@ -950,7 +951,7 @@ void utp_stream::on_read(void* self, size_t bytes_transferred
void utp_stream::on_write(void* self, size_t bytes_transferred
, error_code const& ec, bool kill)
{
utp_stream* s = (utp_stream*)self;
utp_stream* s = static_cast<utp_stream*>(self);
UTP_LOGV("%8p: calling write handler written:%d ec:%s kill:%d\n", s->m_impl
, int(bytes_transferred), ec.message().c_str(), kill);
@ -972,7 +973,7 @@ void utp_stream::on_write(void* self, size_t bytes_transferred
void utp_stream::on_connect(void* self, error_code const& ec, bool kill)
{
utp_stream* s = (utp_stream*)self;
utp_stream* s = static_cast<utp_stream*>(self);
TORRENT_ASSERT(s);
UTP_LOGV("%8p: calling connect handler ec:%s kill:%d\n"
@ -2041,12 +2042,8 @@ bool utp_socket_impl::send_pkt(int flags)
#endif
error_code ec;
#ifdef TORRENT_DEBUG
// simulate 1% packet loss
// if ((random() % 100) > 0)
#endif
m_sm->send_packet(udp::endpoint(m_remote_address, m_port)
, (char const*)h, p->size, ec
, reinterpret_cast<char const*>(h), p->size, ec
, p->mtu_probe ? utp_socket_manager::dont_fragment : 0);
++m_out_packets;
@ -2074,7 +2071,7 @@ bool utp_socket_impl::send_pkt(int flags)
UTP_LOGV("%8p: re-sending\n", this);
#endif
m_sm->send_packet(udp::endpoint(m_remote_address, m_port)
, (char const*)h, p->size, ec, 0);
, reinterpret_cast<char const*>(h), p->size, ec, 0);
}
if (ec == error::would_block || ec == error::try_again)