diff --git a/libtorrent/include/libtorrent/GeoIP.h b/libtorrent/include/libtorrent/GeoIP.h index d493eccb9..74d5c66c7 100644 --- a/libtorrent/include/libtorrent/GeoIP.h +++ b/libtorrent/include/libtorrent/GeoIP.h @@ -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; diff --git a/libtorrent/include/libtorrent/alert_types.hpp b/libtorrent/include/libtorrent/alert_types.hpp index e2154a4c1..f4dd134c5 100644 --- a/libtorrent/include/libtorrent/alert_types.hpp +++ b/libtorrent/include/libtorrent/alert_types.hpp @@ -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()); } diff --git a/libtorrent/include/libtorrent/aux_/session_impl.hpp b/libtorrent/include/libtorrent/aux_/session_impl.hpp index 04f575a1a..c787874f4 100644 --- a/libtorrent/include/libtorrent/aux_/session_impl.hpp +++ b/libtorrent/include/libtorrent/aux_/session_impl.hpp @@ -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; diff --git a/libtorrent/include/libtorrent/bandwidth_manager.hpp b/libtorrent/include/libtorrent/bandwidth_manager.hpp index dc296a13a..ee37615b7 100644 --- a/libtorrent/include/libtorrent/bandwidth_manager.hpp +++ b/libtorrent/include/libtorrent/bandwidth_manager.hpp @@ -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)); } diff --git a/libtorrent/include/libtorrent/bitfield.hpp b/libtorrent/include/libtorrent/bitfield.hpp index 740b20ffe..db0ca1cd4 100644 --- a/libtorrent/include/libtorrent/bitfield.hpp +++ b/libtorrent/include/libtorrent/bitfield.hpp @@ -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; diff --git a/libtorrent/include/libtorrent/bt_peer_connection.hpp b/libtorrent/include/libtorrent/bt_peer_connection.hpp index da3b0fa27..5d3b9bc48 100644 --- a/libtorrent/include/libtorrent/bt_peer_connection.hpp +++ b/libtorrent/include/libtorrent/bt_peer_connection.hpp @@ -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 void append_send_buffer(char* buffer, int size, Destructor const& destructor) diff --git a/libtorrent/include/libtorrent/config.hpp b/libtorrent/include/libtorrent/config.hpp index a1db4b412..529549977 100644 --- a/libtorrent/include/libtorrent/config.hpp +++ b/libtorrent/include/libtorrent/config.hpp @@ -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 diff --git a/libtorrent/include/libtorrent/escape_string.hpp b/libtorrent/include/libtorrent/escape_string.hpp index 660dd4d08..9f141a923 100644 --- a/libtorrent/include/libtorrent/escape_string.hpp +++ b/libtorrent/include/libtorrent/escape_string.hpp @@ -34,11 +34,16 @@ POSSIBILITY OF SUCH DAMAGE. #define TORRENT_ESCAPE_STRING_HPP_INCLUDED #include +#include #include +#include #include "libtorrent/config.hpp" +#include "libtorrent/size_type.hpp" namespace libtorrent { + boost::array::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); diff --git a/libtorrent/include/libtorrent/peer_connection.hpp b/libtorrent/include/libtorrent/peer_connection.hpp index f4a86a064..bc339f2ce 100644 --- a/libtorrent/include/libtorrent/peer_connection.hpp +++ b/libtorrent/include/libtorrent/peer_connection.hpp @@ -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; diff --git a/libtorrent/include/libtorrent/size_type.hpp b/libtorrent/include/libtorrent/size_type.hpp index 6020a5ac3..ce5e1e1f9 100644 --- a/libtorrent/include/libtorrent/size_type.hpp +++ b/libtorrent/include/libtorrent/size_type.hpp @@ -46,6 +46,7 @@ POSSIBILITY OF SUCH DAMAGE. namespace libtorrent { typedef boost::int64_t size_type; + typedef boost::uint64_t unsigned_size_type; } diff --git a/libtorrent/include/libtorrent/torrent.hpp b/libtorrent/include/libtorrent/torrent.hpp index ac0b03764..8abd81e28 100644 --- a/libtorrent/include/libtorrent/torrent.hpp +++ b/libtorrent/include/libtorrent/torrent.hpp @@ -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 ============= diff --git a/libtorrent/include/libtorrent/xml_parse.hpp b/libtorrent/include/libtorrent/xml_parse.hpp index aaf71a816..4e53afeea 100644 --- a/libtorrent/include/libtorrent/xml_parse.hpp +++ b/libtorrent/include/libtorrent/xml_parse.hpp @@ -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; diff --git a/libtorrent/src/bt_peer_connection.cpp b/libtorrent/src/bt_peer_connection.cpp index 418240ce2..394b1e0d1 100755 --- a/libtorrent/src/bt_peer_connection.cpp +++ b/libtorrent/src/bt_peer_connection.cpp @@ -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(buf), size); peer_connection::send_buffer(buf, size, flags); } diff --git a/libtorrent/src/enum_net.cpp b/libtorrent/src/enum_net.cpp index 7f2a1fef7..babdd94b9 100644 --- a/libtorrent/src/enum_net.cpp +++ b/libtorrent/src/enum_net.cpp @@ -41,16 +41,20 @@ POSSIBILITY OF SUCH DAMAGE. #include #endif -#if defined TORRENT_BSD +#if defined TORRENT_BSD || defined TORRENT_SOLARIS #include #include #include #include #include -#include +#include #include #endif +#if defined TORRENT_BSD +#include +#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 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; diff --git a/libtorrent/src/escape_string.cpp b/libtorrent/src/escape_string.cpp index 386354fe3..533b95634 100755 --- a/libtorrent/src/escape_string.cpp +++ b/libtorrent/src/escape_string.cpp @@ -39,13 +39,35 @@ POSSIBILITY OF SUCH DAMAGE. #include #include #include +#include #include +#include #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::digits10> to_string(size_type n) + { + boost::array::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; diff --git a/libtorrent/src/http_connection.cpp b/libtorrent/src/http_connection.cpp index 4f752ba9f..b831fa4f6 100644 --- a/libtorrent/src/http_connection.cpp +++ b/libtorrent/src/http_connection.cpp @@ -39,7 +39,6 @@ POSSIBILITY OF SUCH DAMAGE. #include "libtorrent/connection_queue.hpp" #include -#include #include #include @@ -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(port), timeout, prio + start(hostname, to_string(port).elems, timeout, prio , ps, ssl, handle_redirects, bind_addr); } diff --git a/libtorrent/src/http_parser.cpp b/libtorrent/src/http_parser.cpp index eb717420f..226cf6bdf 100755 --- a/libtorrent/src/http_parser.cpp +++ b/libtorrent/src/http_parser.cpp @@ -34,6 +34,7 @@ POSSIBILITY OF SUCH DAMAGE. #include #include +#include #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()); diff --git a/libtorrent/src/http_stream.cpp b/libtorrent/src/http_stream.cpp index eaa636bf1..392935941 100644 --- a/libtorrent/src/http_stream.cpp +++ b/libtorrent/src/http_stream.cpp @@ -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); diff --git a/libtorrent/src/http_tracker_connection.cpp b/libtorrent/src/http_tracker_connection.cpp index 6e92a5567..4110a274f 100755 --- a/libtorrent/src/http_tracker_connection.cpp +++ b/libtorrent/src/http_tracker_connection.cpp @@ -126,16 +126,16 @@ namespace libtorrent reinterpret_cast(tracker_req().pid.begin()), 20); url += "&port="; - url += boost::lexical_cast(tracker_req().listen_port); + url += to_string(tracker_req().listen_port).elems; url += "&uploaded="; - url += boost::lexical_cast(tracker_req().uploaded); + url += to_string(tracker_req().uploaded).elems; url += "&downloaded="; - url += boost::lexical_cast(tracker_req().downloaded); + url += to_string(tracker_req().downloaded).elems; url += "&left="; - url += boost::lexical_cast(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::min)(tracker_req().num_want, 999)); + url += to_string((std::min)(tracker_req().num_want, 999)).elems; if (m_settings.announce_ip != address()) { diff --git a/libtorrent/src/identify_client.cpp b/libtorrent/src/identify_client.cpp index 1b0b3be67..f5477e3a4 100755 --- a/libtorrent/src/identify_client.cpp +++ b/libtorrent/src/identify_client.cpp @@ -34,6 +34,7 @@ POSSIBILITY OF SUCH DAMAGE. #include #include +#include #ifdef _MSC_VER #pragma warning(push, 1) diff --git a/libtorrent/src/kademlia/rpc_manager.cpp b/libtorrent/src/kademlia/rpc_manager.cpp index a2082b2e3..1e846831c 100644 --- a/libtorrent/src/kademlia/rpc_manager.cpp +++ b/libtorrent/src/kademlia/rpc_manager.cpp @@ -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(o))->~observer(); p.free(const_cast(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::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) diff --git a/libtorrent/src/logger.cpp b/libtorrent/src/logger.cpp index 944e559ae..154415498 100644 --- a/libtorrent/src/logger.cpp +++ b/libtorrent/src/logger.cpp @@ -37,7 +37,6 @@ POSSIBILITY OF SUCH DAMAGE. #endif #include -#include #include #include @@ -214,7 +213,7 @@ namespace error_code ec; return boost::shared_ptr(new logger_peer_plugin( pc->remote().address().to_string(ec) + "_" - + boost::lexical_cast(pc->remote().port()) + ".log")); + + to_string(pc->remote().port()).elems + ".log")); } }; diff --git a/libtorrent/src/lsd.cpp b/libtorrent/src/lsd.cpp index 495b0efd1..0e63d4856 100644 --- a/libtorrent/src/lsd.cpp +++ b/libtorrent/src/lsd.cpp @@ -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) { diff --git a/libtorrent/src/metadata_transfer.cpp b/libtorrent/src/metadata_transfer.cpp index fe47a88a6..49267464e 100644 --- a/libtorrent/src/metadata_transfer.cpp +++ b/libtorrent/src/metadata_transfer.cpp @@ -37,7 +37,6 @@ POSSIBILITY OF SUCH DAMAGE. #endif #include -#include #ifdef _MSC_VER #pragma warning(pop) diff --git a/libtorrent/src/parse_url.cpp b/libtorrent/src/parse_url.cpp index 2d54277c3..c7e412c95 100644 --- a/libtorrent/src/parse_url.cpp +++ b/libtorrent/src/parse_url.cpp @@ -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 { diff --git a/libtorrent/src/peer_connection.cpp b/libtorrent/src/peer_connection.cpp index 92037a924..2384623cf 100755 --- a/libtorrent/src/peer_connection.cpp +++ b/libtorrent/src/peer_connection.cpp @@ -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(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(remote().port()), m_ses.listen_port()); + + to_string(remote().port()).elems, m_ses.listen_port()); (*m_logger) << "*** INCOMING CONNECTION\n"; #endif diff --git a/libtorrent/src/piece_picker.cpp b/libtorrent/src/piece_picker.cpp index ab30440b0..68f1393a1 100755 --- a/libtorrent/src/piece_picker.cpp +++ b/libtorrent/src/piece_picker.cpp @@ -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) diff --git a/libtorrent/src/policy.cpp b/libtorrent/src/policy.cpp index 2f2987278..8f6386009 100755 --- a/libtorrent/src/policy.cpp +++ b/libtorrent/src/policy.cpp @@ -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" diff --git a/libtorrent/src/session.cpp b/libtorrent/src/session.cpp index e6f2f186d..4ae88ee8c 100755 --- a/libtorrent/src/session.cpp +++ b/libtorrent/src/session.cpp @@ -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 diff --git a/libtorrent/src/session_impl.cpp b/libtorrent/src/session_impl.cpp index 4ccf35066..5ca6c7c59 100755 --- a/libtorrent/src/session_impl.cpp +++ b/libtorrent/src/session_impl.cpp @@ -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 @@ -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 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); diff --git a/libtorrent/src/smart_ban.cpp b/libtorrent/src/smart_ban.cpp index 759377ed8..8e7bc90b4 100644 --- a/libtorrent/src/smart_ban.cpp +++ b/libtorrent/src/smart_ban.cpp @@ -38,7 +38,6 @@ POSSIBILITY OF SUCH DAMAGE. #include #include -#include #ifdef _MSC_VER #pragma warning(pop) diff --git a/libtorrent/src/storage.cpp b/libtorrent/src/storage.cpp index 905ee1da7..64104d467 100755 --- a/libtorrent/src/storage.cpp +++ b/libtorrent/src/storage.cpp @@ -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; diff --git a/libtorrent/src/torrent.cpp b/libtorrent/src/torrent.cpp index 383ea5bc7..8e333f9e5 100755 --- a/libtorrent/src/torrent.cpp +++ b/libtorrent/src/torrent.cpp @@ -46,7 +46,6 @@ POSSIBILITY OF SUCH DAMAGE. #pragma warning(push, 1) #endif -#include #include #include #include @@ -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().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(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(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(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(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 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()) alerts().post_alert(file_error_alert(j.error_file, get_handle(), j.str)); - m_error = j.str; + set_error(j.str); pause(); } f(ret); diff --git a/libtorrent/src/torrent_handle.cpp b/libtorrent/src/torrent_handle.cpp index 9a39e4661..81baf6763 100755 --- a/libtorrent/src/torrent_handle.cpp +++ b/libtorrent/src/torrent_handle.cpp @@ -46,7 +46,6 @@ POSSIBILITY OF SUCH DAMAGE. #pragma warning(push, 1) #endif -#include #include #include #include @@ -75,7 +74,6 @@ namespace std #endif using boost::bind; -using boost::mutex; using libtorrent::aux::session_impl; #ifdef BOOST_NO_EXCEPTIONS diff --git a/libtorrent/src/torrent_info.cpp b/libtorrent/src/torrent_info.cpp index 7c109e693..172477974 100755 --- a/libtorrent/src/torrent_info.cpp +++ b/libtorrent/src/torrent_info.cpp @@ -44,7 +44,6 @@ POSSIBILITY OF SUCH DAMAGE. #pragma warning(push, 1) #endif -#include #include #include #include @@ -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'); diff --git a/libtorrent/src/udp_socket.cpp b/libtorrent/src/udp_socket.cpp index 8ea855a54..d8d3fcc29 100644 --- a/libtorrent/src/udp_socket.cpp +++ b/libtorrent/src/udp_socket.cpp @@ -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 #include -#include #include #if BOOST_VERSION < 103500 #include @@ -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(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)); } diff --git a/libtorrent/src/udp_tracker_connection.cpp b/libtorrent/src/udp_tracker_connection.cpp index 191be4c61..c742aea01 100755 --- a/libtorrent/src/udp_tracker_connection.cpp +++ b/libtorrent/src/udp_tracker_connection.cpp @@ -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(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 diff --git a/libtorrent/src/upnp.cpp b/libtorrent/src/upnp.cpp index cfae4cdfd..706ac6208 100644 --- a/libtorrent/src/upnp.cpp +++ b/libtorrent/src/upnp.cpp @@ -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 #include @@ -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(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(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(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(code); + error_string += to_string(code).elems; if (e != end && e->code == code) { error_string += ": "; diff --git a/libtorrent/src/ut_metadata.cpp b/libtorrent/src/ut_metadata.cpp index d8416e14b..aa1cfede1 100644 --- a/libtorrent/src/ut_metadata.cpp +++ b/libtorrent/src/ut_metadata.cpp @@ -37,7 +37,6 @@ POSSIBILITY OF SUCH DAMAGE. #endif #include -#include #ifdef _MSC_VER #pragma warning(pop) diff --git a/libtorrent/src/web_peer_connection.cpp b/libtorrent/src/web_peer_connection.cpp index b856d0ec4..c350255a7 100755 --- a/libtorrent/src/web_peer_connection.cpp +++ b/libtorrent/src/web_peer_connection.cpp @@ -38,6 +38,7 @@ POSSIBILITY OF SUCH DAMAGE. #include #include #include +#include #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(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(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(f.offset); + request += to_string(f.offset).elems; request += "-"; - request += boost::lexical_cast(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(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()) { 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.