fix build and some warnings

This commit is contained in:
Arvid Norberg 2015-04-20 00:01:27 +00:00
parent 820fde5066
commit 4fd230dbe5
18 changed files with 176 additions and 91 deletions

View File

@ -103,10 +103,6 @@ namespace libtorrent
namespace detail
{
// this is used in the template, so it must be available to the client
TORRENT_EXPORT char const* integer_to_str(char* buf, int size
, entry::integer_type val);
template <class OutIt>
int write_integer(OutIt& out, entry::integer_type val)
{

View File

@ -363,6 +363,8 @@ POSSIBILITY OF SUCH DAMAGE.
#endif
#define TORRENT_UNUSED(x) (void)(x)
#if defined TORRENT_WINDOWS && !defined TORRENT_MINGW
#include <stdarg.h>

View File

@ -296,6 +296,12 @@ namespace libtorrent
mutable boost::uint8_t m_type_queried:1;
};
namespace detail
{
TORRENT_EXPORT char const* integer_to_str(char* buf, int size
, entry::integer_type val);
}
#if TORRENT_USE_IOSTREAM
// prints the bencoded structure to the ostream as a JSON-style structure.
inline std::ostream& operator<<(std::ostream& os, const entry& e)

View File

@ -392,8 +392,10 @@ namespace libtorrent
stats_counters().inc_stats_counter(counters::num_outgoing_suggest);
}
namespace {
char random_byte()
{ return random() & 0xff; }
}
void bt_peer_connection::get_specific_peer_info(peer_info& p) const
{
@ -715,11 +717,13 @@ namespace libtorrent
}
#endif // #if !defined(TORRENT_DISABLE_ENCRYPTION) && !defined(TORRENT_DISABLE_EXTENSIONS)
namespace {
void regular_c_free(char* buf, void* /* userdata */
, block_cache_reference /* ref */)
{
::free(buf);
}
}
void bt_peer_connection::append_const_send_buffer(char const* buffer, int size
, chained_buffer::free_buffer_fun destructor, void* userdata
@ -2426,6 +2430,8 @@ namespace libtorrent
#endif
}
namespace {
void buffer_reclaim_block(char* /* buffer */, void* userdata
, block_cache_reference ref)
{
@ -2440,6 +2446,8 @@ namespace libtorrent
buf->free_disk_buffer(buffer);
}
} // anonymous namespace
void bt_peer_connection::write_piece(peer_request const& r, disk_buffer_holder& buffer)
{
INVARIANT_CHECK;

View File

@ -54,7 +54,7 @@ namespace libtorrent
#endif
}
static bool sse42_support = supports_sse42();
bool sse42_support = supports_sse42();
} // anonymous namespace

View File

@ -436,6 +436,8 @@ namespace libtorrent
check_buffer_level(l);
}
namespace {
boost::uint64_t physical_ram()
{
boost::uint64_t ret = 0;
@ -483,6 +485,8 @@ namespace libtorrent
return ret;
}
} // anonymous namespace
void disk_buffer_pool::set_settings(aux::session_settings const& sett
, error_code& ec)
{

View File

@ -30,17 +30,24 @@ POSSIBILITY OF SUCH DAMAGE.
*/
#include <algorithm>
#include "libtorrent/config.hpp"
#include "aux_/disable_warnings_push.hpp"
#if TORRENT_USE_IOSTREAM
#include <iostream>
#endif
#include <algorithm>
#include <boost/bind.hpp>
#include "aux_/disable_warnings_pop.hpp"
#include "libtorrent/entry.hpp"
#include "libtorrent/config.hpp"
#ifndef TORRENT_NO_DEPRECATE
#include "libtorrent/lazy_entry.hpp"
#endif
#include "libtorrent/bdecode.hpp"
#include "libtorrent/entry.hpp"
#include "libtorrent/hex.hpp"
#if defined(_MSC_VER)
@ -61,7 +68,8 @@ namespace libtorrent
{
namespace detail
{
TORRENT_EXPORT char const* integer_to_str(char* buf, int size, entry::integer_type val)
TORRENT_EXPORT char const* integer_to_str(char* buf, int size
, entry::integer_type val)
{
int sign = 0;
if (val < 0)

View File

@ -475,6 +475,8 @@ namespace libtorrent
*out = '\0';
}
// TODO: 3 move the hex coding to its own .cpp file corresponding
// to the functions exported by hex.hpp
TORRENT_EXTRA_EXPORT int hex_to_int(char in)
{
if (in >= '0' && in <= '9') return int(in) - '0';

View File

@ -123,6 +123,18 @@ namespace libtorrent
if (str2.size() != len) return false;
return memcmp(str2.c_str(), str, len) == 0;
}
bool compare_file_entry_size(internal_file_entry const& fe1
, internal_file_entry const& fe2)
{
return fe1.size < fe2.size;
}
bool compare_file_offset(internal_file_entry const& lhs
, internal_file_entry const& rhs)
{
return lhs.offset < rhs.offset;
}
}
// path is not supposed to include the name of the torrent itself.
@ -352,14 +364,6 @@ namespace libtorrent
update_path_index(m_files[index], new_filename);
}
namespace
{
bool compare_file_offset(internal_file_entry const& lhs, internal_file_entry const& rhs)
{
return lhs.offset < rhs.offset;
}
}
#ifndef TORRENT_NO_DEPRECATE
file_storage::iterator file_storage::file_at_offset_deprecated(boost::int64_t offset) const
{
@ -889,9 +893,6 @@ namespace libtorrent
{ return at(i - m_files.begin()); }
#endif // TORRENT_NO_DEPRECATE
bool compare_file_entry_size(internal_file_entry const& fe1, internal_file_entry const& fe2)
{ return fe1.size < fe2.size; }
void file_storage::reorder_file(int index, int dst)
{
TORRENT_ASSERT(index < int(m_files.size()));

View File

@ -109,6 +109,8 @@ namespace libtorrent
}
}
namespace
{
// returns -1 if gzip header is invalid or the header size in bytes
int gzip_header(const char* buf, int size)
{
@ -182,6 +184,7 @@ namespace libtorrent
return total_size - size;
}
} // anonymous namespace
TORRENT_EXTRA_EXPORT void inflate_gzip(
char const* in

View File

@ -67,11 +67,10 @@ namespace libtorrent
if (error_pos) *error_pos = start - orig_start;
return -1;
}
}
#define TORRENT_FAIL_BDECODE(code) do { ec = make_error_code(code); return fail(error_pos, stack, start, orig_start); } while (false)
namespace { bool numeric(char c) { return c >= '0' && c <= '9'; } }
bool numeric(char c) { return c >= '0' && c <= '9'; }
char const* find_char(char const* start, char const* end, char delimiter)
{
@ -79,6 +78,8 @@ namespace libtorrent
return start;
}
} // anonymous namespace
#ifndef TORRENT_NO_DEPRECATE
int lazy_bdecode(char const* start, char const* end
, lazy_entry& ret, int depth_limit, int item_limit)
@ -170,10 +171,10 @@ namespace libtorrent
{
case 'd':
top->construct_dict(start - 1);
continue;
break;
case 'l':
top->construct_list(start - 1);
continue;
break;
case 'i':
{
char const* int_start = start;
@ -183,7 +184,7 @@ namespace libtorrent
TORRENT_ASSERT(*start == 'e');
++start;
stack.pop_back();
continue;
break;
}
default:
{
@ -204,10 +205,9 @@ namespace libtorrent
top->construct_string(start, int(len));
stack.pop_back();
start += len;
continue;
break;
}
}
return 0;
}
return 0;
}
@ -477,6 +477,8 @@ namespace libtorrent
return return_t(m_begin, m_len);
}
namespace {
int line_longer_than(lazy_entry const& e, int limit)
{
int line_len = 0;
@ -580,6 +582,7 @@ namespace libtorrent
}
ret += "'";
}
} // anonymous namespace
std::string print_entry(lazy_entry const& e, bool single_line, int indent)
{

View File

@ -97,11 +97,15 @@ namespace libtorrent
min_request_queue = 2,
};
namespace {
bool pending_block_in_buffer(pending_block const& pb)
{
return pb.send_buffer_offset != pending_block::not_in_buffer;
}
}
#if defined TORRENT_REQUEST_LOGGING
void write_request_log(FILE* f, sha1_hash const& ih
, peer_connection* p, peer_request const& r)
@ -1398,6 +1402,8 @@ namespace libtorrent
}
}
namespace {
bool match_request(peer_request const& r, piece_block const& b, int block_size)
{
if (int(b.piece_index) != r.piece) return false;
@ -1405,6 +1411,7 @@ namespace libtorrent
if (r.start % block_size != 0) return false;
return true;
}
}
// -----------------------------
// -------- REJECT PIECE -------
@ -5673,11 +5680,13 @@ namespace libtorrent
, userdata, ref);
}
namespace {
void session_free_buffer(char* buffer, void* userdata, block_cache_reference)
{
aux::session_interface* ses = (aux::session_interface*)userdata;
ses->free_buffer(buffer);
}
}
void peer_connection::send_buffer(char const* buf, int size, int flags)
{

View File

@ -34,10 +34,12 @@ POSSIBILITY OF SUCH DAMAGE.
namespace libtorrent {
int round_up8(int v)
{
namespace {
int round_up8(int v)
{
return ((v & 7) == 0) ? v : v + (8 - (v & 7));
}
}
}
int receive_buffer::max_receive()
{

View File

@ -3219,6 +3219,7 @@ retry:
// m_peer_pool.release_memory();
}
namespace {
// returns the index of the first set bit.
int log2(boost::uint32_t v)
{
@ -3238,6 +3239,8 @@ retry:
return MultiplyDeBruijnBitPosition[boost::uint32_t(v * 0x07C4ACDDU) >> 27];
}
} // anonymous namespace
void session_impl::received_buffer(int s)
{
int index = (std::min)(log2(s >> 3), 17);
@ -5376,11 +5379,14 @@ retry:
void session_impl::start_dht()
{ start_dht(m_dht_state); }
namespace {
void on_bootstrap(alert_manager& alerts)
{
if (alerts.should_post<dht_bootstrap_alert>())
alerts.emplace_alert<dht_bootstrap_alert>();
}
}
void session_impl::start_dht(entry const& startup_state)
{
@ -5496,19 +5502,14 @@ retry:
, this, _1), salt);
}
namespace {
void on_dht_put(alert_manager& alerts, sha1_hash target)
{
if (alerts.should_post<dht_put_alert>())
alerts.emplace_alert<dht_put_alert>(target);
}
void session_impl::dht_put_item(entry data, sha1_hash target)
{
if (!m_dht) return;
m_dht->put_item(data, boost::bind(&on_dht_put, boost::ref(m_alerts)
, target));
}
void put_mutable_callback(alert_manager& alerts, dht::item& i
, boost::function<void(entry&, boost::array<char,64>&
, boost::uint64_t&, std::string const&)> cb)
@ -5525,6 +5526,15 @@ retry:
alerts.emplace_alert<dht_put_alert>(pk, sig, salt, seq);
}
} // anonymous namespace
void session_impl::dht_put_item(entry data, sha1_hash target)
{
if (!m_dht) return;
m_dht->put_item(data, boost::bind(&on_dht_put, boost::ref(m_alerts)
, target));
}
void session_impl::dht_put_mutable_item(boost::array<char, 32> key
, boost::function<void(entry&, boost::array<char,64>&
, boost::uint64_t&, std::string const&)> cb

View File

@ -64,6 +64,7 @@ namespace libtorrent
};
#undef CASE
#else
TORRENT_UNUSED(s);
return false;
#endif
}
@ -94,7 +95,8 @@ namespace libtorrent
// for SSL connections, make sure to authenticate the hostname
// of the certificate
#define CASE(t) case socket_type_int_impl<ssl_stream<t> >::value: \
s.get<ssl_stream<t> >()->set_verify_callback(asio::ssl::rfc2818_verification(hostname), ec); \
s.get<ssl_stream<t> >()->set_verify_callback( \
asio::ssl::rfc2818_verification(hostname), ec); \
ctx = SSL_get_SSL_CTX(s.get<ssl_stream<t> >()->native_handle()); \
break;
@ -116,11 +118,16 @@ namespace libtorrent
SSL_CTX_set_tlsext_servername_arg(ctx, 0);
}
#endif // OPENSSL_VERSION_NUMBER
#else
TORRENT_UNUSED(ec);
TORRENT_UNUSED(hostname);
TORRENT_UNUSED(s);
#endif
}
void on_close_socket(socket_type* s, boost::shared_ptr<void> holder)
namespace {
void on_close_socket(socket_type* s, boost::shared_ptr<void>)
{
#if defined TORRENT_ASIO_DEBUGGING
complete_async("on_close_socket");
@ -129,6 +136,8 @@ namespace libtorrent
s->close(ec);
}
} // anonymous namespace
// the second argument is a shared pointer to an object that
// will keep the socket (s) alive for the duration of the async operation
void async_shutdown(socket_type& s, boost::shared_ptr<void> holder)
@ -158,6 +167,7 @@ namespace libtorrent
}
#undef CASE
#else
TORRENT_UNUSED(holder);
s.close(e);
#endif // TORRENT_USE_OPENSSL
}
@ -247,6 +257,8 @@ namespace libtorrent
new ((ssl_stream<utp_stream>*)m_data) ssl_stream<utp_stream>(m_io_service
, *((boost::asio::ssl::context*)userdata));
break;
#else
TORRENT_UNUSED(userdata);
#endif
default: TORRENT_ASSERT(false);
}

View File

@ -37,6 +37,7 @@ POSSIBILITY OF SUCH DAMAGE.
#include <boost/version.hpp>
#include "libtorrent/config.hpp"
#include "libtorrent/time.hpp"
#include "libtorrent/aux_/time.hpp"
#ifndef _WIN32
#include <unistd.h>

View File

@ -80,6 +80,8 @@ POSSIBILITY OF SUCH DAMAGE.
namespace libtorrent
{
namespace {
bool valid_path_character(char c)
{
#ifdef TORRENT_WINDOWS
@ -91,6 +93,8 @@ namespace libtorrent
return std::strchr(invalid_chars, c) == 0;
}
} // anonymous namespace
// fixes invalid UTF-8 sequences and
// replaces characters that are invalid
// in paths
@ -360,6 +364,8 @@ namespace libtorrent
if (path.empty()) path = "_";
}
namespace {
// 'top_level' is extracting the file for a single-file torrent. The
// distinction is that the filename is found in "name" rather than
// "path"
@ -572,6 +578,32 @@ namespace libtorrent
return true;
}
int load_file(std::string const& filename, std::vector<char>& v
, error_code& ec, int limit = 8000000)
{
ec.clear();
file f;
if (!f.open(filename, file::read_only, ec)) return -1;
boost::int64_t s = f.get_size(ec);
if (ec) return -1;
if (s > limit)
{
ec = errors::metadata_too_large;
return -2;
}
v.resize((unsigned int)s);
if (s == 0) return 0;
file::iovec_t b = {&v[0], size_t(s) };
boost::int64_t read = f.readv(0, &b, 1, ec);
if (read != s) return -3;
if (ec) return -3;
return 0;
}
} // anonymous namespace
// TODO: 3 move the merkle functions out into its own file
// and header file
int merkle_get_parent(int tree_node)
{
// node 0 doesn't have a parent
@ -603,27 +635,6 @@ namespace libtorrent
return ret;
}
int load_file(std::string const& filename, std::vector<char>& v, error_code& ec, int limit = 8000000)
{
ec.clear();
file f;
if (!f.open(filename, file::read_only, ec)) return -1;
boost::int64_t s = f.get_size(ec);
if (ec) return -1;
if (s > limit)
{
ec = errors::metadata_too_large;
return -2;
}
v.resize((unsigned int)s);
if (s == 0) return 0;
file::iovec_t b = {&v[0], size_t(s) };
boost::int64_t read = f.readv(0, &b, 1, ec);
if (read != s) return -3;
if (ec) return -3;
return 0;
}
announce_entry::announce_entry(std::string const& u)
: url(u)
, next_announce(min_time())
@ -1470,6 +1481,9 @@ namespace libtorrent
}
#if TORRENT_USE_I2P
// TODO: 3 this function is used in other translation units. Make sure
// it's declared in an appropriate header.
bool is_i2p_url(std::string const& url)
{
using boost::tuples::ignore;
@ -1480,6 +1494,7 @@ namespace libtorrent
char const* top_domain = strrchr(hostname.c_str(), '.');
return top_domain && strcmp(top_domain, ".i2p") == 0;
}
#endif
bool torrent_info::parse_torrent_file(bdecode_node const& torrent_file

View File

@ -39,6 +39,8 @@ POSSIBILITY OF SUCH DAMAGE.
namespace libtorrent
{
namespace {
void apply_mask(boost::uint8_t* b, boost::uint8_t const* mask, int size)
{
for (int i = 0; i < size; ++i)
@ -48,6 +50,7 @@ namespace libtorrent
++mask;
}
}
}
// 1. if the IP addresses are identical, hash the ports in 16 bit network-order
// binary representation, ordered lowest first.