diff --git a/examples/client_test.cpp b/examples/client_test.cpp index 8bf9424f3..3e142171e 100755 --- a/examples/client_test.cpp +++ b/examples/client_test.cpp @@ -318,7 +318,7 @@ int main(int argc, char* argv[]) session ses; ses.listen_on(std::make_pair(6880, 6889)); -// ses.set_upload_rate_limit(512 * 1024); + //ses.set_upload_rate_limit(512 * 1024); ses.set_http_settings(settings); ses.set_severity_level(alert::debug); // ses.set_severity_level(alert::info); diff --git a/include/libtorrent/resource_request.hpp b/include/libtorrent/resource_request.hpp index ac33f58a3..d4e898454 100755 --- a/include/libtorrent/resource_request.hpp +++ b/include/libtorrent/resource_request.hpp @@ -33,6 +33,8 @@ POSSIBILITY OF SUCH DAMAGE. #ifndef TORRENT_RESOURCE_REQUEST_HPP_INCLUDED #define TORRENT_RESOURCE_REQUEST_HPP_INCLUDED +#include + #ifdef min #undef min #endif @@ -60,6 +62,7 @@ namespace libtorrent return given - used; } + static const int inf = boost::integer_traits::const_max; // I'm right now actively using: int used; diff --git a/src/allocate_resources.cpp b/src/allocate_resources.cpp index ae9066111..f8598b89b 100644 --- a/src/allocate_resources.cpp +++ b/src/allocate_resources.cpp @@ -69,11 +69,11 @@ namespace libtorrent { assert(a >= 0); assert(b >= 0); - assert(std::numeric_limits::max() + std::numeric_limits::max() < 0); + assert(resource_request::inf + resource_request::inf < 0); int sum = a + b; if(sum < 0) - sum = std::numeric_limits::max(); + sum = resource_request::inf; assert(sum >= a && sum >= b); return sum; @@ -165,7 +165,7 @@ namespace libtorrent , res); #endif - if(resources == std::numeric_limits::max()) + if(resources == resource_request::inf) { // No competition for resources. // Just give everyone what they want. @@ -183,7 +183,7 @@ namespace libtorrent for (It i = start; i != end; ++i) { sum_max = saturated_add(sum_max, ((*i).*res).max); - assert(((*i).*res).min < std::numeric_limits::max()); + assert(((*i).*res).min < resource_request::inf); assert(((*i).*res).min >= 0); assert(((*i).*res).min <= ((*i).*res).max); sum_min += ((*i).*res).min; @@ -229,10 +229,10 @@ namespace libtorrent assert(r.given < r.max); size_type used = (size_type)r.used + 1; - size_type toGive = used * kNumer / kDenom; - if(toGive > std::numeric_limits::max()) - toGive = std::numeric_limits::max(); - resources_to_distribute -= give(r, (int)toGive); + size_type to_give = used * kNumer / kDenom; + if(to_give > resource_request::inf) + to_give = resource_request::inf; + resources_to_distribute -= give(r, (int)to_give); } assert(resources_to_distribute >= 0); diff --git a/src/file.cpp b/src/file.cpp index 934805353..bcfe49774 100755 --- a/src/file.cpp +++ b/src/file.cpp @@ -30,10 +30,6 @@ POSSIBILITY OF SUCH DAMAGE. */ -#include -#include "libtorrent/file.hpp" -#include - #ifdef _WIN32 // windows part #include "libtorrent/utf8.hpp" @@ -56,8 +52,17 @@ typedef int mode_t; #include #include +#include +// make sure the _FILE_OFFSET_BITS define worked +// on this platform +BOOST_STATIC_ASSERT(sizeof(lseek(0, 0, 0)) >= 8); + #endif +#include +#include "libtorrent/file.hpp" +#include + #ifndef O_BINARY #define O_BINARY 0 #endif diff --git a/src/peer_connection.cpp b/src/peer_connection.cpp index b30f88120..bcd66b6ed 100755 --- a/src/peer_connection.cpp +++ b/src/peer_connection.cpp @@ -126,12 +126,32 @@ namespace libtorrent // these numbers are used the first second of connection. // then the given upload limits will be applied by running // allocate_resources(). + m_ul_bandwidth_quota.min = 10; - m_ul_bandwidth_quota.max = std::numeric_limits::max(); - m_ul_bandwidth_quota.given = std::numeric_limits::max(); + m_ul_bandwidth_quota.max = resource_request::inf; + + if (m_torrent->m_ul_bandwidth_quota.given == resource_request::inf) + { + m_ul_bandwidth_quota.given = resource_request::inf; + } + else + { + // just enough to get started with the handshake and bitmask + m_ul_bandwidth_quota.given = 400; + } + m_dl_bandwidth_quota.min = 10; - m_dl_bandwidth_quota.max = std::numeric_limits::max(); - m_dl_bandwidth_quota.given = 400; + m_dl_bandwidth_quota.max = resource_request::inf; + + if (m_torrent->m_dl_bandwidth_quota.given == resource_request::inf) + { + m_dl_bandwidth_quota.given = resource_request::inf; + } + else + { + // just enough to get started with the handshake and bitmask + m_dl_bandwidth_quota.given = 400; + } assert(!m_socket->is_blocking()); assert(m_torrent != 0); @@ -219,13 +239,32 @@ namespace libtorrent // after one second, allocate_resources() will be called // and the correct bandwidth limits will be set on all // connections. + m_ul_bandwidth_quota.min = 10; - m_ul_bandwidth_quota.max = std::numeric_limits::max(); - m_ul_bandwidth_quota.given = std::numeric_limits::max(); + m_ul_bandwidth_quota.max = resource_request::inf; + + if (m_ses.m_upload_rate == -1) + { + m_ul_bandwidth_quota.given = resource_request::inf; + } + else + { + // just enough to get started with the handshake and bitmask + m_ul_bandwidth_quota.given = 400; + } m_dl_bandwidth_quota.min = 10; - m_dl_bandwidth_quota.max = std::numeric_limits::max(); - m_dl_bandwidth_quota.given = 400; + m_dl_bandwidth_quota.max = resource_request::inf; + + if (m_ses.m_download_rate == -1) + { + m_dl_bandwidth_quota.given = resource_request::inf; + } + else + { + // just enough to get started with the handshake and bitmask + m_dl_bandwidth_quota.given = 400; + } assert(!m_socket->is_blocking()); @@ -1840,7 +1879,7 @@ namespace libtorrent // than we have uploaded OR if we are a seed // have an unlimited upload rate if(!m_send_buffer.empty() || (!m_requests.empty() && !is_choked())) - m_ul_bandwidth_quota.max = std::numeric_limits::max(); + m_ul_bandwidth_quota.max = resource_request::inf; else m_ul_bandwidth_quota.max = m_ul_bandwidth_quota.min; } diff --git a/src/torrent.cpp b/src/torrent.cpp index 38b89e186..bbfb4bd63 100755 --- a/src/torrent.cpp +++ b/src/torrent.cpp @@ -187,6 +187,32 @@ namespace libtorrent m_uploads_quota.max = std::numeric_limits::max(); m_connections_quota.max = std::numeric_limits::max(); + m_dl_bandwidth_quota.min = 100; + m_dl_bandwidth_quota.max = resource_request::inf; + + if (m_ses.m_download_rate == -1) + { + m_dl_bandwidth_quota.given = resource_request::inf; + } + else + { + m_dl_bandwidth_quota.given = 400; + } + + m_ul_bandwidth_quota.min = 100; + m_ul_bandwidth_quota.max = resource_request::inf; + + + if (m_ses.m_upload_rate == -1) + { + m_ul_bandwidth_quota.given = resource_request::inf; + } + else + { + m_ul_bandwidth_quota.given = 400; + } + + m_policy.reset(new policy(this)); bencode(std::back_inserter(m_metadata), metadata["info"]); init(); @@ -240,6 +266,33 @@ namespace libtorrent m_uploads_quota.max = std::numeric_limits::max(); m_connections_quota.max = std::numeric_limits::max(); + m_dl_bandwidth_quota.min = 100; + m_dl_bandwidth_quota.max = resource_request::inf; + + if (m_ses.m_download_rate == -1) + { + m_dl_bandwidth_quota.given = resource_request::inf; + } + else + { + m_dl_bandwidth_quota.given = 400; + } + + m_ul_bandwidth_quota.min = 100; + m_ul_bandwidth_quota.max = resource_request::inf; + + + if (m_ses.m_upload_rate == -1) + { + m_ul_bandwidth_quota.given = resource_request::inf; + } + else + { + m_ul_bandwidth_quota.given = 400; + } + + + m_trackers.push_back(announce_entry(tracker_url)); m_requested_metadata.resize(256, 0); m_policy.reset(new policy(this)); @@ -1106,9 +1159,15 @@ namespace libtorrent m_ul_bandwidth_quota.max = std::min(m_ul_bandwidth_quota.max, m_upload_bandwidth_limit); + if (m_upload_bandwidth_limit == resource_request::inf) + m_ul_bandwidth_quota.max = resource_request::inf; + m_dl_bandwidth_quota.max = std::min(m_dl_bandwidth_quota.max, m_download_bandwidth_limit); + if (m_download_bandwidth_limit == resource_request::inf) + m_dl_bandwidth_quota.max = resource_request::inf; + accumulator += m_stat; m_stat.second_tick(); } @@ -1131,7 +1190,7 @@ namespace libtorrent allocate_resources(m_dl_bandwidth_quota.given , m_connections , &peer_connection::m_dl_bandwidth_quota); - + using boost::bind; // tell all peers to reset their used quota. This is