lt sync 3218

This commit is contained in:
Andrew Resch 2009-01-27 17:27:23 +00:00
parent 0808bdaa0f
commit 04bebad82f
40 changed files with 251 additions and 144 deletions

View file

@ -69,7 +69,7 @@ typedef enum {
GEOIP_MEMORY_CACHE = 1,
GEOIP_CHECK_CACHE = 2,
GEOIP_INDEX_CACHE = 4,
GEOIP_MMAP_CACHE = 8,
GEOIP_MMAP_CACHE = 8
} GeoIPOptions;
typedef enum {
@ -89,14 +89,14 @@ typedef enum {
typedef enum {
GEOIP_ANON_PROXY = 1,
GEOIP_HTTP_X_FORWARDED_FOR_PROXY = 2,
GEOIP_HTTP_CLIENT_IP_PROXY = 3,
GEOIP_HTTP_CLIENT_IP_PROXY = 3
} GeoIPProxyTypes;
typedef enum {
GEOIP_UNKNOWN_SPEED = 0,
GEOIP_DIALUP_SPEED = 1,
GEOIP_CABLEDSL_SPEED = 2,
GEOIP_CORPORATE_SPEED = 3,
GEOIP_CORPORATE_SPEED = 3
} GeoIPNetspeedValues;
extern char **GeoIPDBFileName;

View file

@ -223,9 +223,9 @@ namespace libtorrent
tracker_error_alert(torrent_handle const& h
, int times
, int status
, std::string const& url
, std::string const& url_
, std::string const& msg_)
: tracker_alert(h, url)
: tracker_alert(h, url_)
, times_in_row(times)
, status_code(status)
, msg(msg_)
@ -252,9 +252,9 @@ namespace libtorrent
struct TORRENT_EXPORT tracker_warning_alert: tracker_alert
{
tracker_warning_alert(torrent_handle const& h
, std::string const& url
, std::string const& url_
, std::string const& msg_)
: tracker_alert(h, url)
: tracker_alert(h, url_)
, msg(msg_)
{ TORRENT_ASSERT(!url.empty()); }
@ -276,8 +276,8 @@ namespace libtorrent
scrape_reply_alert(torrent_handle const& h
, int incomplete_
, int complete_
, std::string const& url)
: tracker_alert(h, url)
, std::string const& url_)
: tracker_alert(h, url_)
, incomplete(incomplete_)
, complete(complete_)
{ TORRENT_ASSERT(!url.empty()); }
@ -300,9 +300,9 @@ namespace libtorrent
struct TORRENT_EXPORT scrape_failed_alert: tracker_alert
{
scrape_failed_alert(torrent_handle const& h
, std::string const& url
, std::string const& url_
, std::string const& msg_)
: tracker_alert(h, url)
: tracker_alert(h, url_)
, msg(msg_)
{ TORRENT_ASSERT(!url.empty()); }
@ -323,8 +323,8 @@ namespace libtorrent
{
tracker_reply_alert(torrent_handle const& h
, int np
, std::string const& url)
: tracker_alert(h, url)
, std::string const& url_)
: tracker_alert(h, url_)
, num_peers(np)
{ TORRENT_ASSERT(!url.empty()); }
@ -367,8 +367,8 @@ namespace libtorrent
struct TORRENT_EXPORT tracker_announce_alert: tracker_alert
{
tracker_announce_alert(torrent_handle const& h
, std::string const& url, int event_)
: tracker_alert(h, url)
, std::string const& url_, int event_)
: tracker_alert(h, url_)
, event(event_)
{ TORRENT_ASSERT(!url.empty()); }

View file

@ -61,17 +61,11 @@ POSSIBILITY OF SUCH DAMAGE.
#include "libtorrent/torrent_handle.hpp"
#include "libtorrent/entry.hpp"
#include "libtorrent/torrent_info.hpp"
#include "libtorrent/socket.hpp"
#include "libtorrent/peer_connection.hpp"
#include "libtorrent/peer_id.hpp"
#include "libtorrent/policy.hpp"
#include "libtorrent/tracker_manager.hpp"
#include "libtorrent/peer_info.hpp"
#include "libtorrent/alert.hpp"
#include "libtorrent/fingerprint.hpp"
#include "libtorrent/debug.hpp"
#include "libtorrent/peer_request.hpp"
#include "libtorrent/piece_block_progress.hpp"
#include "libtorrent/ip_filter.hpp"
#include "libtorrent/config.hpp"
@ -82,9 +76,6 @@ POSSIBILITY OF SUCH DAMAGE.
#include "libtorrent/stat.hpp"
#include "libtorrent/file_pool.hpp"
#include "libtorrent/bandwidth_manager.hpp"
#include "libtorrent/natpmp.hpp"
#include "libtorrent/upnp.hpp"
#include "libtorrent/lsd.hpp"
#include "libtorrent/socket_type.hpp"
#include "libtorrent/connection_queue.hpp"
#include "libtorrent/disk_io_thread.hpp"
@ -94,6 +85,16 @@ namespace libtorrent
{
namespace fs = boost::filesystem;
class peer_connection;
class upnp;
class natpmp;
class lsd;
class fingerprint;
namespace dht
{
class dht_tracker;
};
namespace aux
{
@ -236,13 +237,7 @@ namespace libtorrent
int num_connections() const
{ return m_connections.size(); }
void unchoke_peer(peer_connection& c)
{
torrent* t = c.associated_torrent().lock().get();
TORRENT_ASSERT(t);
if (t->unchoke_peer(c))
++m_num_unchoked;
}
void unchoke_peer(peer_connection& c);
session_status status() const;
void set_peer_id(peer_id const& id);
@ -294,24 +289,6 @@ namespace libtorrent
void load_state(entry const& ses_state);
entry state() const;
#ifdef TORRENT_STATS
void log_buffer_usage()
{
int send_buffer_capacity = 0;
int used_send_buffer = 0;
for (connection_map::const_iterator i = m_connections.begin()
, end(m_connections.end()); i != end; ++i)
{
send_buffer_capacity += (*i)->send_buffer_capacity();
used_send_buffer += (*i)->send_buffer_size();
}
TORRENT_ASSERT(send_buffer_capacity >= used_send_buffer);
m_buffer_usage_logger << log_time() << " send_buffer_size: " << send_buffer_capacity << std::endl;
m_buffer_usage_logger << log_time() << " used_send_buffer: " << used_send_buffer << std::endl;
m_buffer_usage_logger << log_time() << " send_buffer_utilization: "
<< (used_send_buffer * 100.f / send_buffer_capacity) << std::endl;
}
#endif
void start_lsd();
natpmp* start_natpmp();
upnp* start_upnp();
@ -586,6 +563,8 @@ namespace libtorrent
#endif
#ifdef TORRENT_STATS
void log_buffer_usage();
// logger used to write bandwidth usage statistics
std::ofstream m_stats_logger;
int m_second_counter;

View file

@ -269,7 +269,7 @@ private:
if (m_abort) return;
error_code ec;
TORRENT_ASSERT(e.expires_at > time_now());
// TORRENT_ASSERT(e.expires_at > time_now());
m_history_timer.expires_at(e.expires_at, ec);
m_history_timer.async_wait(bind(&bandwidth_manager::on_history_expire, this, _1));
}

View file

@ -60,7 +60,7 @@ namespace libtorrent
~bitfield() { dealloc(); }
void assign(char const* bytes, int bits)
{ resize(bits); memcpy(m_bytes, bytes, (bits + 7) / 8); }
{ resize(bits); std::memcpy(m_bytes, bytes, (bits + 7) / 8); }
bool operator[](int index) const
{ return get_bit(index); }
@ -197,23 +197,23 @@ namespace libtorrent
{
if (old_size_bytes && b) m_bytes[old_size_bytes - 1] |= (0xff >> b);
if (old_size_bytes < new_size_bytes)
memset(m_bytes + old_size_bytes, 0xff, new_size_bytes - old_size_bytes);
std::memset(m_bytes + old_size_bytes, 0xff, new_size_bytes - old_size_bytes);
}
else
{
if (old_size_bytes < new_size_bytes)
memset(m_bytes + old_size_bytes, 0x00, new_size_bytes - old_size_bytes);
std::memset(m_bytes + old_size_bytes, 0x00, new_size_bytes - old_size_bytes);
}
}
void set_all()
{
memset(m_bytes, 0xff, (m_size + 7) / 8);
std::memset(m_bytes, 0xff, (m_size + 7) / 8);
}
void clear_all()
{
memset(m_bytes, 0x00, (m_size + 7) / 8);
std::memset(m_bytes, 0x00, (m_size + 7) / 8);
}
void resize(int bits)
@ -223,20 +223,20 @@ namespace libtorrent
{
if (m_own)
{
m_bytes = (unsigned char*)realloc(m_bytes, bytes);
m_bytes = (unsigned char*)std::realloc(m_bytes, bytes);
m_own = true;
}
else if (bits > m_size)
{
unsigned char* tmp = (unsigned char*)malloc(bytes);
memcpy(tmp, m_bytes, (std::min)((m_size + 7)/ 8, bytes));
unsigned char* tmp = (unsigned char*)std::malloc(bytes);
std::memcpy(tmp, m_bytes, (std::min)((m_size + 7)/ 8, bytes));
m_bytes = tmp;
m_own = true;
}
}
else
{
m_bytes = (unsigned char*)malloc(bytes);
m_bytes = (unsigned char*)std::malloc(bytes);
m_own = true;
}
m_size = bits;
@ -246,7 +246,7 @@ namespace libtorrent
private:
void dealloc() { if (m_own) free(m_bytes); m_bytes = 0; }
void dealloc() { if (m_own) std::free(m_bytes); m_bytes = 0; }
unsigned char* m_bytes;
int m_size; // in bits
bool m_own;

View file

@ -275,7 +275,7 @@ public:
// these functions encrypt the send buffer if m_rc4_encrypted
// is true, otherwise it passes the call to the
// peer_connection functions of the same names
void send_buffer(char* buf, int size, int flags = 0);
void send_buffer(char const* buf, int size, int flags = 0);
buffer::interval allocate_send_buffer(int size);
template <class Destructor>
void append_send_buffer(char* buffer, int size, Destructor const& destructor)

View file

@ -77,6 +77,8 @@ POSSIBILITY OF SUCH DAMAGE.
#define TORRENT_LINUX
#elif defined WIN32
#define TORRENT_WINDOWS
#elif defined sun || defined __sun
#define TORRENT_SOLARIS
#else
#warning unkown OS, assuming BSD
#define TORRENT_BSD

View file

@ -34,11 +34,16 @@ POSSIBILITY OF SUCH DAMAGE.
#define TORRENT_ESCAPE_STRING_HPP_INCLUDED
#include <string>
#include <limits>
#include <boost/optional.hpp>
#include <boost/array.hpp>
#include "libtorrent/config.hpp"
#include "libtorrent/size_type.hpp"
namespace libtorrent
{
boost::array<char, 3 + std::numeric_limits<size_type>::digits10> to_string(size_type n);
std::string TORRENT_EXPORT unescape_string(std::string const& s);
std::string TORRENT_EXPORT escape_string(const char* str, int len);
std::string TORRENT_EXPORT escape_path(const char* str, int len);

View file

@ -78,6 +78,10 @@ POSSIBILITY OF SUCH DAMAGE.
#include "libtorrent/disk_buffer_holder.hpp"
#include "libtorrent/bitfield.hpp"
#ifdef TORRENT_STATS
#include "libtorrent/aux_/session_impl.hpp"
#endif
namespace libtorrent
{
class torrent;

View file

@ -46,6 +46,7 @@ POSSIBILITY OF SUCH DAMAGE.
namespace libtorrent
{
typedef boost::int64_t size_type;
typedef boost::uint64_t unsigned_size_type;
}

View file

@ -212,7 +212,7 @@ namespace libtorrent
void ip_filter_updated() { m_policy.ip_filter_updated(); }
void set_error(std::string const& msg) { m_error = msg; }
void set_error(std::string const& msg);
bool has_error() const { return !m_error.empty(); }
void pause();
void resume();
@ -229,6 +229,8 @@ namespace libtorrent
bool is_auto_managed() const { return m_auto_managed; }
void auto_managed(bool a);
bool should_check_files() const;
void delete_files();
// ============ start deprecation =============

View file

@ -128,7 +128,7 @@ namespace libtorrent
*(p-1) = '?';
tag_end = p - 1;
}
else if (start + 5 < p && memcmp(start, "!--", 3) == 0 && memcmp(p-2, "--", 2) == 0)
else if (start + 5 < p && std::memcmp(start, "!--", 3) == 0 && std::memcmp(p-2, "--", 2) == 0)
{
start += 3;
*(p-2) = 0;

View file

@ -50,6 +50,7 @@ POSSIBILITY OF SUCH DAMAGE.
#include "libtorrent/version.hpp"
#include "libtorrent/extensions.hpp"
#include "libtorrent/aux_/session_impl.hpp"
#include "libtorrent/broadcast_socket.hpp"
#ifndef TORRENT_DISABLE_ENCRYPTION
#include "libtorrent/pe_crypto.hpp"
@ -605,13 +606,13 @@ namespace libtorrent
#endif
}
void bt_peer_connection::send_buffer(char* buf, int size, int flags)
void bt_peer_connection::send_buffer(char const* buf, int size, int flags)
{
TORRENT_ASSERT(buf);
TORRENT_ASSERT(size > 0);
if (m_encrypted && m_rc4_encrypted)
m_RC4_handler->encrypt(buf, size);
m_RC4_handler->encrypt(const_cast<char*>(buf), size);
peer_connection::send_buffer(buf, size, flags);
}

View file

@ -41,16 +41,20 @@ POSSIBILITY OF SUCH DAMAGE.
#include <boost/asio/ip/host_name.hpp>
#endif
#if defined TORRENT_BSD
#if defined TORRENT_BSD || defined TORRENT_SOLARIS
#include <sys/ioctl.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <net/if.h>
#include <net/route.h>
#include <sys/sysctl.h>
#include <string.h>
#include <boost/scoped_array.hpp>
#endif
#if defined TORRENT_BSD
#include <sys/sysctl.h>
#endif
#if defined TORRENT_WINDOWS
#ifndef WIN32_LEAN_AND_MEAN
#define WIN32_LEAN_AND_MEAN
@ -83,7 +87,7 @@ namespace libtorrent { namespace
{
typedef asio::ip::address_v4::bytes_type bytes_t;
bytes_t b;
memcpy(&b[0], ina, b.size());
std::memcpy(&b[0], ina, b.size());
return address_v4(b);
}
@ -91,7 +95,7 @@ namespace libtorrent { namespace
{
typedef asio::ip::address_v6::bytes_type bytes_t;
bytes_t b;
memcpy(&b[0], ina6, b.size());
std::memcpy(&b[0], ina6, b.size());
return address_v6(b);
}
@ -244,11 +248,11 @@ namespace libtorrent
{
std::vector<ip_interface> ret;
// covers linux, MacOS X and BSD distributions
#if defined TORRENT_LINUX || defined TORRENT_BSD
#if defined TORRENT_LINUX || defined TORRENT_BSD || defined TORRENT_SOLARIS
int s = socket(AF_INET, SOCK_DGRAM, 0);
if (s < 0)
{
ec = asio::error::fault;
ec = error_code(errno, asio::error::system_category);
return ret;
}
ifconf ifc;
@ -300,7 +304,7 @@ namespace libtorrent
#if defined TORRENT_BSD
int current_size = item.ifr_addr.sa_len + IFNAMSIZ;
#elif defined TORRENT_LINUX
#elif defined TORRENT_LINUX || defined TORRENT_SOLARIS
int current_size = sizeof(ifreq);
#endif
ifr += current_size;

View file

@ -39,13 +39,35 @@ POSSIBILITY OF SUCH DAMAGE.
#include <cctype>
#include <algorithm>
#include <iostream>
#include <limits>
#include <boost/optional.hpp>
#include <boost/array.hpp>
#include "libtorrent/assert.hpp"
#include "libtorrent/escape_string.hpp"
namespace libtorrent
{
// lexical_cast's result depends on the locale. We need
// a well defined result
boost::array<char, 3 + std::numeric_limits<size_type>::digits10> to_string(size_type n)
{
boost::array<char, 3 + std::numeric_limits<size_type>::digits10> ret;
char *p = &ret.back();;
*p = '\0';
unsigned_size_type un = n;
if (n < 0) un = -un;
do {
*--p = '0' + un % 10;
un /= 10;
} while (un);
if (n < 0) *--p = '-';
std::memmove(&ret.front(), p, sizeof(ret.elems));
return ret;
}
std::string unescape_string(std::string const& s)
{
std::string ret;

View file

@ -39,7 +39,6 @@ POSSIBILITY OF SUCH DAMAGE.
#include "libtorrent/connection_queue.hpp"
#include <boost/bind.hpp>
#include <boost/lexical_cast.hpp>
#include <string>
#include <algorithm>
@ -116,7 +115,7 @@ void http_connection::get(std::string const& url, time_duration timeout, int pri
sendbuffer = headers.str();
m_url = url;
start(hostname, boost::lexical_cast<std::string>(port), timeout, prio
start(hostname, to_string(port).elems, timeout, prio
, ps, ssl, handle_redirects, bind_addr);
}

View file

@ -34,6 +34,7 @@ POSSIBILITY OF SUCH DAMAGE.
#include <cctype>
#include <algorithm>
#include <stdlib.h>
#include "libtorrent/config.hpp"
#include "libtorrent/http_parser.hpp"
@ -162,7 +163,7 @@ namespace libtorrent
if (name == "content-length")
{
#ifdef WIN32
#ifdef TORRENT_WINDOWS
m_content_length = _atoi64(value.c_str());
#else
m_content_length = atoll(value.c_str());

View file

@ -134,7 +134,7 @@ namespace libtorrent
if (found_end)
{
m_buffer.push_back(0);
char* status = strchr(&m_buffer[0], ' ');
char* status = std::strchr(&m_buffer[0], ' ');
if (status == 0)
{
(*h)(asio::error::operation_not_supported);
@ -144,7 +144,7 @@ namespace libtorrent
}
status++;
int code = atoi(status);
int code = std::atoi(status);
if (code != 200)
{
(*h)(asio::error::operation_not_supported);

View file

@ -126,16 +126,16 @@ namespace libtorrent
reinterpret_cast<const char*>(tracker_req().pid.begin()), 20);
url += "&port=";
url += boost::lexical_cast<std::string>(tracker_req().listen_port);
url += to_string(tracker_req().listen_port).elems;
url += "&uploaded=";
url += boost::lexical_cast<std::string>(tracker_req().uploaded);
url += to_string(tracker_req().uploaded).elems;
url += "&downloaded=";
url += boost::lexical_cast<std::string>(tracker_req().downloaded);
url += to_string(tracker_req().downloaded).elems;
url += "&left=";
url += boost::lexical_cast<std::string>(tracker_req().left);
url += to_string(tracker_req().left).elems;
if (tracker_req().event != tracker_request::none)
{
@ -152,8 +152,7 @@ namespace libtorrent
url += "&compact=1";
url += "&numwant=";
url += boost::lexical_cast<std::string>(
(std::min)(tracker_req().num_want, 999));
url += to_string((std::min)(tracker_req().num_want, 999)).elems;
if (m_settings.announce_ip != address())
{

View file

@ -34,6 +34,7 @@ POSSIBILITY OF SUCH DAMAGE.
#include <cctype>
#include <algorithm>
#include <stdio.h>
#ifdef _MSC_VER
#pragma warning(push, 1)

View file

@ -82,7 +82,7 @@ void intrusive_ptr_release(observer const* o)
if (--o->m_refs == 0)
{
boost::pool<>& p = o->pool_allocator;
o->~observer();
(const_cast<observer*>(o))->~observer();
p.free(const_cast<observer*>(o));
}
}
@ -106,7 +106,7 @@ typedef mpl::max_element<
rpc_manager::rpc_manager(fun const& f, node_id const& our_id
, routing_table& table, send_fun const& sf)
: m_pool_allocator(sizeof(mpl::deref<max_observer_type_iter::base>::type))
, m_next_transaction_id(rand() % max_transactions)
, m_next_transaction_id(std::rand() % max_transactions)
, m_oldest_transaction_id(m_next_transaction_id)
, m_incoming(f)
, m_send(sf)

View file

@ -37,7 +37,6 @@ POSSIBILITY OF SUCH DAMAGE.
#endif
#include <boost/shared_ptr.hpp>
#include <boost/lexical_cast.hpp>
#include <boost/filesystem/fstream.hpp>
#include <boost/filesystem/convenience.hpp>
@ -214,7 +213,7 @@ namespace
error_code ec;
return boost::shared_ptr<peer_plugin>(new logger_peer_plugin(
pc->remote().address().to_string(ec) + "_"
+ boost::lexical_cast<std::string>(pc->remote().port()) + ".log"));
+ to_string(pc->remote().port()).elems + ".log"));
}
};

View file

@ -175,7 +175,7 @@ void lsd::on_announce(udp::endpoint const& from, char* buffer
sha1_hash ih(0);
std::istringstream ih_sstr(ih_str);
ih_sstr >> ih;
int port = atoi(port_str.c_str());
int port = std::atoi(port_str.c_str());
if (!ih.is_all_zeros() && port != 0)
{

View file

@ -37,7 +37,6 @@ POSSIBILITY OF SUCH DAMAGE.
#endif
#include <boost/shared_ptr.hpp>
#include <boost/lexical_cast.hpp>
#ifdef _MSC_VER
#pragma warning(pop)

View file

@ -115,7 +115,7 @@ namespace libtorrent
{
hostname.assign(start, port_pos);
++port_pos;
port = atoi(std::string(port_pos, end).c_str());
port = std::atoi(std::string(port_pos, end).c_str());
}
else
{

View file

@ -52,6 +52,7 @@ POSSIBILITY OF SUCH DAMAGE.
#include "libtorrent/policy.hpp"
#include "libtorrent/socket_type.hpp"
#include "libtorrent/assert.hpp"
#include "libtorrent/broadcast_socket.hpp"
//#define TORRENT_CORRUPT_DATA
@ -157,7 +158,7 @@ namespace libtorrent
#if defined TORRENT_VERBOSE_LOGGING || defined TORRENT_ERROR_LOGGING
error_code ec;
m_logger = m_ses.create_log(m_remote.address().to_string(ec) + "_"
+ boost::lexical_cast<std::string>(m_remote.port()), m_ses.listen_port());
+ to_string(m_remote.port()).elems, m_ses.listen_port());
(*m_logger) << "*** OUTGOING CONNECTION\n";
#endif
#ifdef TORRENT_DEBUG
@ -265,7 +266,7 @@ namespace libtorrent
error_code ec;
TORRENT_ASSERT(m_socket->remote_endpoint(ec) == m_remote || ec);
m_logger = m_ses.create_log(remote().address().to_string(ec) + "_"
+ boost::lexical_cast<std::string>(remote().port()), m_ses.listen_port());
+ to_string(remote().port()).elems, m_ses.listen_port());
(*m_logger) << "*** INCOMING CONNECTION\n";
#endif

View file

@ -1456,7 +1456,7 @@ namespace libtorrent
// we're not using rarest first (only for the first
// bucket, since that's where the currently downloading
// pieces are)
int start_piece = rand() % m_piece_map.size();
int start_piece = std::rand() % m_piece_map.size();
int piece = start_piece;
while (num_blocks > 0)

View file

@ -55,6 +55,7 @@ POSSIBILITY OF SUCH DAMAGE.
#include "libtorrent/time.hpp"
#include "libtorrent/aux_/session_impl.hpp"
#include "libtorrent/piece_picker.hpp"
#include "libtorrent/broadcast_socket.hpp"
#ifdef TORRENT_DEBUG
#include "libtorrent/bt_peer_connection.hpp"

View file

@ -80,7 +80,6 @@ POSSIBILITY OF SUCH DAMAGE.
using boost::shared_ptr;
using boost::weak_ptr;
using boost::bind;
using boost::mutex;
using libtorrent::aux::session_impl;
#ifdef TORRENT_MEMDEBUG

View file

@ -76,6 +76,9 @@ POSSIBILITY OF SUCH DAMAGE.
#include "libtorrent/kademlia/dht_tracker.hpp"
#include "libtorrent/enum_net.hpp"
#include "libtorrent/config.hpp"
#include "libtorrent/upnp.hpp"
#include "libtorrent/natpmp.hpp"
#include "libtorrent/lsd.hpp"
#ifndef TORRENT_WINDOWS
#include <sys/resource.h>
@ -966,6 +969,14 @@ namespace aux {
m_key = key;
}
void session_impl::unchoke_peer(peer_connection& c)
{
torrent* t = c.associated_torrent().lock().get();
TORRENT_ASSERT(t);
if (t->unchoke_peer(c))
++m_num_unchoked;
}
int session_impl::next_port()
{
std::pair<int, int> const& out_ports = m_settings.outgoing_ports;
@ -1390,12 +1401,8 @@ namespace aux {
{
--hard_limit;
++total_running;
if (t->state() != torrent_status::queued_for_checking
&& t->state() != torrent_status::checking_files)
{
--num_downloaders;
if (t->is_paused()) t->resume();
}
--num_downloaders;
if (t->is_paused()) t->resume();
}
else
{
@ -2500,6 +2507,25 @@ namespace aux {
#endif
}
#ifdef TORRENT_STATS
void session_impl::log_buffer_usage()
{
int send_buffer_capacity = 0;
int used_send_buffer = 0;
for (connection_map::const_iterator i = m_connections.begin()
, end(m_connections.end()); i != end; ++i)
{
send_buffer_capacity += (*i)->send_buffer_capacity();
used_send_buffer += (*i)->send_buffer_size();
}
TORRENT_ASSERT(send_buffer_capacity >= used_send_buffer);
m_buffer_usage_logger << log_time() << " send_buffer_size: " << send_buffer_capacity << std::endl;
m_buffer_usage_logger << log_time() << " used_send_buffer: " << used_send_buffer << std::endl;
m_buffer_usage_logger << log_time() << " send_buffer_utilization: "
<< (used_send_buffer * 100.f / send_buffer_capacity) << std::endl;
}
#endif
void session_impl::free_buffer(char* buf, int size)
{
TORRENT_ASSERT(size > 0);

View file

@ -38,7 +38,6 @@ POSSIBILITY OF SUCH DAMAGE.
#include <boost/shared_ptr.hpp>
#include <boost/enable_shared_from_this.hpp>
#include <boost/lexical_cast.hpp>
#ifdef _MSC_VER
#pragma warning(pop)

View file

@ -987,7 +987,7 @@ namespace libtorrent
ec = error_code(EIO, get_posix_category());
#endif
set_error(m_save_path / file_iter->path, ec);
return -1;
return actual_read;
}
if (actual_read > 0) buf_pos += actual_read;
std::memset(buf + buf_pos, 0, size - buf_pos);
@ -1137,7 +1137,7 @@ namespace libtorrent
ec = error_code(EIO, get_posix_category());
#endif
set_error(m_save_path / file_iter->path, ec);
return -1;
return written;
}
left_to_write -= write_bytes;

View file

@ -46,7 +46,6 @@ POSSIBILITY OF SUCH DAMAGE.
#pragma warning(push, 1)
#endif
#include <boost/lexical_cast.hpp>
#include <boost/filesystem/convenience.hpp>
#include <boost/bind.hpp>
#include <boost/thread/mutex.hpp>
@ -74,13 +73,13 @@ POSSIBILITY OF SUCH DAMAGE.
#include "libtorrent/aux_/session_impl.hpp"
#include "libtorrent/instantiate_connection.hpp"
#include "libtorrent/assert.hpp"
#include "libtorrent/broadcast_socket.hpp"
using namespace libtorrent;
using boost::tuples::tuple;
using boost::tuples::get;
using boost::tuples::make_tuple;
using boost::bind;
using boost::mutex;
using libtorrent::aux::session_impl;
namespace
@ -453,7 +452,7 @@ namespace libtorrent
if (m_torrent_file->num_pieces()
> piece_picker::max_pieces)
{
m_error = "too many pieces in torrent";
set_error("too many pieces in torrent");
pause();
}
@ -527,7 +526,7 @@ namespace libtorrent
" ]\n";
#endif
}
m_error = j.str;
set_error(j.str);
pause();
std::vector<char>().swap(m_resume_data);
@ -710,7 +709,7 @@ namespace libtorrent
" ]\n";
#endif
}
m_error = j.str;
set_error(j.str);
pause();
return;
}
@ -733,7 +732,7 @@ namespace libtorrent
if (ret == piece_manager::disk_check_aborted)
{
m_error = "aborted";
set_error("aborted");
m_ses.done_checking(shared_from_this());
return;
}
@ -749,7 +748,7 @@ namespace libtorrent
" ]\n";
#endif
}
m_error = j.str;
set_error(j.str);
pause();
if (!m_abort) m_ses.done_checking(shared_from_this());
return;
@ -1042,7 +1041,7 @@ namespace libtorrent
// assume this is because we got a hostname instead of
// an ip address from the tracker
tcp::resolver::query q(i->ip, boost::lexical_cast<std::string>(i->port));
tcp::resolver::query q(i->ip, to_string(i->port).elems);
m_host_resolver.async_resolve(q,
bind(&torrent::on_peer_name_lookup, shared_from_this(), _1, _2, i->pid));
}
@ -2186,8 +2185,7 @@ namespace libtorrent
|| ps.type == proxy_settings::http_pw)
{
// use proxy
tcp::resolver::query q(ps.hostname
, boost::lexical_cast<std::string>(ps.port));
tcp::resolver::query q(ps.hostname, to_string(ps.port).elems);
m_host_resolver.async_resolve(q,
bind(&torrent::on_proxy_name_lookup, shared_from_this(), _1, _2, url));
}
@ -2205,7 +2203,7 @@ namespace libtorrent
return;
}
tcp::resolver::query q(hostname, boost::lexical_cast<std::string>(port));
tcp::resolver::query q(hostname, to_string(port).elems);
m_host_resolver.async_resolve(q,
bind(&torrent::on_name_lookup, shared_from_this(), _1, _2, url
, tcp::endpoint()));
@ -2269,7 +2267,7 @@ namespace libtorrent
return;
}
tcp::resolver::query q(hostname, boost::lexical_cast<std::string>(port));
tcp::resolver::query q(hostname, to_string(port).elems);
m_host_resolver.async_resolve(q,
bind(&torrent::on_name_lookup, shared_from_this(), _1, _2, url, a));
}
@ -3173,6 +3171,8 @@ namespace libtorrent
int torrent::disconnect_peers(int num)
{
INVARIANT_CHECK;
int ret = 0;
// buils a list of all connected peers and sort it by 'disconnectability'.
std::vector<peer_connection*> peers(m_connections.size());
@ -3846,9 +3846,25 @@ namespace libtorrent
void torrent::clear_error()
{
if (m_error.empty()) return;
bool checking_files = should_check_files();
if (m_ses.m_auto_manage_time_scaler > 2)
m_ses.m_auto_manage_time_scaler = 2;
m_error.clear();
if (!checking_files && should_check_files())
m_ses.check_torrent(shared_from_this());
}
void torrent::set_error(std::string const& msg)
{
bool checking_files = should_check_files();
m_error = msg;
if (checking_files && !should_check_files())
{
// stop checking
m_storage->abort_disk_io();
m_ses.done_checking(shared_from_this());
set_state(torrent_status::queued_for_checking);
}
}
void torrent::auto_managed(bool a)
@ -3953,7 +3969,15 @@ namespace libtorrent
}
}
}
bool torrent::should_check_files() const
{
return (m_state == torrent_status::checking_files
|| m_state == torrent_status::queued_for_checking)
&& (!is_paused() || m_auto_managed)
&& m_error.empty();
}
bool torrent::is_paused() const
{
return m_paused || m_ses.is_paused();
@ -3964,9 +3988,17 @@ namespace libtorrent
INVARIANT_CHECK;
if (m_paused) return;
bool checking_files = should_check_files();
m_paused = true;
if (m_ses.is_paused()) return;
do_pause();
if (checking_files && !should_check_files())
{
// stop checking
m_storage->abort_disk_io();
m_ses.done_checking(shared_from_this());
set_state(torrent_status::queued_for_checking);
}
}
void torrent::do_pause()
@ -4019,8 +4051,11 @@ namespace libtorrent
INVARIANT_CHECK;
if (!m_paused) return;
bool checking_files = should_check_files();
m_paused = false;
do_resume();
if (!checking_files && should_check_files())
m_ses.check_torrent(shared_from_this());
}
void torrent::do_resume()
@ -4280,7 +4315,7 @@ namespace libtorrent
{
if (alerts().should_post<file_error_alert>())
alerts().post_alert(file_error_alert(j.error_file, get_handle(), j.str));
m_error = j.str;
set_error(j.str);
pause();
}
f(ret);

View file

@ -46,7 +46,6 @@ POSSIBILITY OF SUCH DAMAGE.
#pragma warning(push, 1)
#endif
#include <boost/lexical_cast.hpp>
#include <boost/filesystem/convenience.hpp>
#include <boost/optional.hpp>
#include <boost/bind.hpp>
@ -75,7 +74,6 @@ namespace std
#endif
using boost::bind;
using boost::mutex;
using libtorrent::aux::session_impl;
#ifdef BOOST_NO_EXCEPTIONS

View file

@ -44,7 +44,6 @@ POSSIBILITY OF SUCH DAMAGE.
#pragma warning(push, 1)
#endif
#include <boost/lexical_cast.hpp>
#include <boost/filesystem/path.hpp>
#include <boost/filesystem.hpp>
#include <boost/bind.hpp>
@ -379,7 +378,7 @@ namespace libtorrent
// copy the info section
m_info_section_size = section.second;
m_info_section.reset(new char[m_info_section_size]);
memcpy(m_info_section.get(), section.first, m_info_section_size);
std::memcpy(m_info_section.get(), section.first, m_info_section_size);
TORRENT_ASSERT(section.first[0] == 'd');
TORRENT_ASSERT(section.first[m_info_section_size-1] == 'e');

View file

@ -1,8 +1,40 @@
/*
Copyright (c) 2007, Arvid Norberg
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:
* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in
the documentation and/or other materials provided with the distribution.
* Neither the name of the author nor the names of its
contributors may be used to endorse or promote products derived
from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
POSSIBILITY OF SUCH DAMAGE.
*/
#include "libtorrent/udp_socket.hpp"
#include "libtorrent/connection_queue.hpp"
#include "libtorrent/escape_string.hpp"
#include <stdlib.h>
#include <boost/bind.hpp>
#include <boost/lexical_cast.hpp>
#include <boost/array.hpp>
#if BOOST_VERSION < 103500
#include <asio/read.hpp>
@ -362,8 +394,7 @@ void udp_socket::set_proxy_settings(proxy_settings const& ps)
|| ps.type == proxy_settings::socks5_pw)
{
// connect to socks5 server and open up the UDP tunnel
tcp::resolver::query q(ps.hostname
, boost::lexical_cast<std::string>(ps.port));
tcp::resolver::query q(ps.hostname, to_string(ps.port).elems);
m_resolver.async_resolve(q, boost::bind(
&udp_socket::on_name_lookup, this, _1, _2));
}

View file

@ -55,6 +55,7 @@ POSSIBILITY OF SUCH DAMAGE.
#include "libtorrent/parse_url.hpp"
#include "libtorrent/udp_tracker_connection.hpp"
#include "libtorrent/io.hpp"
#include "libtorrent/escape_string.hpp"
namespace
{
@ -111,7 +112,7 @@ namespace libtorrent
return;
}
udp::resolver::query q(hostname, boost::lexical_cast<std::string>(port));
udp::resolver::query q(hostname, to_string(port).elems);
m_name_lookup.async_resolve(q
, boost::bind(
&udp_tracker_connection::name_lookup, self(), _1, _2));
@ -309,7 +310,7 @@ namespace libtorrent
char* ptr = buf;
if (m_transaction_id == 0)
m_transaction_id = rand() ^ (rand() << 16);
m_transaction_id = std::rand() ^ (std::rand() << 16);
detail::write_uint32(0x417, ptr);
detail::write_uint32(0x27101980, ptr); // connection_id
@ -331,7 +332,7 @@ namespace libtorrent
void udp_tracker_connection::send_udp_scrape()
{
if (m_transaction_id == 0)
m_transaction_id = rand() ^ (rand() << 16);
m_transaction_id = std::rand() ^ (std::rand() << 16);
if (!m_socket.is_open()) return; // the operation was aborted
@ -465,7 +466,7 @@ namespace libtorrent
void udp_tracker_connection::send_udp_announce()
{
if (m_transaction_id == 0)
m_transaction_id = rand() ^ (rand() << 16);
m_transaction_id = std::rand() ^ (std::rand() << 16);
if (!m_socket.is_open()) return; // the operation was aborted

View file

@ -39,6 +39,7 @@ POSSIBILITY OF SUCH DAMAGE.
#include "libtorrent/xml_parse.hpp"
#include "libtorrent/connection_queue.hpp"
#include "libtorrent/enum_net.hpp"
#include "libtorrent/escape_string.hpp"
#include <boost/bind.hpp>
#include <boost/ref.hpp>
@ -683,7 +684,7 @@ void upnp::update_map(rootdevice& d, int i)
, boost::ref(d), i, _5), true
, bind(&upnp::create_port_mapping, self(), _1, boost::ref(d), i)));
d.upnp_connection->start(d.hostname, boost::lexical_cast<std::string>(d.port)
d.upnp_connection->start(d.hostname, to_string(d.port).elems
, seconds(10), 1);
}
else if (m.action == mapping_t::action_delete)
@ -693,7 +694,7 @@ void upnp::update_map(rootdevice& d, int i)
, m_cc, bind(&upnp::on_upnp_unmap_response, self(), _1, _2
, boost::ref(d), i, _5), true
, bind(&upnp::delete_port_mapping, self(), boost::ref(d), i)));
d.upnp_connection->start(d.hostname, boost::lexical_cast<std::string>(d.port)
d.upnp_connection->start(d.hostname, to_string(d.port).elems
, seconds(10), 1);
}
@ -928,7 +929,7 @@ void upnp::on_upnp_xml(error_code const& e
boost::tie(protocol, auth, d.hostname, d.port, d.path, error)
= parse_url_components(d.url);
d.control_url = protocol + "://" + d.hostname + ":"
+ boost::lexical_cast<std::string>(d.port) + s.control_url;
+ to_string(d.port).elems + s.control_url;
}
#ifdef TORRENT_UPNP_LOGGING
@ -986,7 +987,7 @@ namespace
void find_error_code(int type, char const* string, error_code_parse_state& state)
{
if (state.exit) return;
if (type == xml_start_tag && !strcmp("errorCode", string))
if (type == xml_start_tag && !std::strcmp("errorCode", string))
{
state.in_error_code = true;
}
@ -1121,7 +1122,7 @@ void upnp::on_upnp_map_response(error_code const& e
{
// The external port cannot be wildcarder
// pick a random port
m.external_port = 40000 + (rand() % 10000);
m.external_port = 40000 + (std::rand() % 10000);
m.action = mapping_t::action_add;
++m.failcount;
update_map(d, mapping);
@ -1172,7 +1173,7 @@ void upnp::return_error(int mapping, int code)
error_code_t* e = std::lower_bound(error_codes, end, tmp
, bind(&error_code_t::code, _1) < bind(&error_code_t::code, _2));
std::string error_string = "UPnP mapping error ";
error_string += boost::lexical_cast<std::string>(code);
error_string += to_string(code).elems;
if (e != end && e->code == code)
{
error_string += ": ";

View file

@ -37,7 +37,6 @@ POSSIBILITY OF SUCH DAMAGE.
#endif
#include <boost/shared_ptr.hpp>
#include <boost/lexical_cast.hpp>
#ifdef _MSC_VER
#pragma warning(pop)

View file

@ -38,6 +38,7 @@ POSSIBILITY OF SUCH DAMAGE.
#include <limits>
#include <boost/bind.hpp>
#include <sstream>
#include <stdlib.h>
#include "libtorrent/web_peer_connection.hpp"
#include "libtorrent/session.hpp"
@ -230,11 +231,9 @@ namespace libtorrent
request += "\r\nProxy-Connection: keep-alive";
}
request += "\r\nRange: bytes=";
request += boost::lexical_cast<std::string>(size_type(r.piece)
* info.piece_length() + r.start);
request += to_string(size_type(r.piece) * info.piece_length() + r.start).elems;
request += "-";
request += boost::lexical_cast<std::string>(r.piece
* info.piece_length() + r.start + r.length - 1);
request += to_string(r.piece * info.piece_length() + r.start + r.length - 1).elems;
if (m_first_request || using_proxy)
request += "\r\nConnection: keep-alive";
request += "\r\n\r\n";
@ -287,9 +286,9 @@ namespace libtorrent
request += "\r\nProxy-Connection: keep-alive";
}
request += "\r\nRange: bytes=";
request += boost::lexical_cast<std::string>(f.offset);
request += to_string(f.offset).elems;
request += "-";
request += boost::lexical_cast<std::string>(f.offset + f.size - 1);
request += to_string(f.offset + f.size - 1).elems;
if (m_first_request || using_proxy)
request += "\r\nConnection: keep-alive";
request += "\r\n\r\n";
@ -384,8 +383,8 @@ namespace libtorrent
t->retry_url_seed(m_url);
}
t->remove_url_seed(m_url);
std::string error_msg = boost::lexical_cast<std::string>(m_parser.status_code())
+ " " + m_parser.message();
std::string error_msg = to_string(m_parser.status_code()).elems
+ (" " + m_parser.message());
if (m_ses.m_alerts.should_post<url_seed_alert>())
{
session_impl::mutex_t::scoped_lock l(m_ses.m_mutex);
@ -499,7 +498,7 @@ namespace libtorrent
else
{
range_start = 0;
range_end = atol(m_parser.header("content-length").c_str());
range_end = m_parser.content_length();
if (range_end == -1)
{
// we should not try this server again.