minor code refactor, more use of auto
This commit is contained in:
parent
e88339378c
commit
a357e490ed
|
@ -36,8 +36,6 @@ POSSIBILITY OF SUCH DAMAGE.
|
||||||
#include "libtorrent/fwd.hpp"
|
#include "libtorrent/fwd.hpp"
|
||||||
#include "libtorrent/error_code.hpp"
|
#include "libtorrent/error_code.hpp"
|
||||||
#include "libtorrent/tailqueue.hpp"
|
#include "libtorrent/tailqueue.hpp"
|
||||||
#include "libtorrent/peer_request.hpp"
|
|
||||||
#include "libtorrent/aux_/block_cache_reference.hpp"
|
|
||||||
#include "libtorrent/sha1_hash.hpp"
|
#include "libtorrent/sha1_hash.hpp"
|
||||||
#include "libtorrent/disk_interface.hpp"
|
#include "libtorrent/disk_interface.hpp"
|
||||||
#include "libtorrent/aux_/vector.hpp"
|
#include "libtorrent/aux_/vector.hpp"
|
||||||
|
|
|
@ -169,9 +169,9 @@ namespace libtorrent {
|
||||||
{
|
{
|
||||||
explicit scoped_unlocker_impl(Lock& l) : m_lock(&l) { m_lock->unlock(); }
|
explicit scoped_unlocker_impl(Lock& l) : m_lock(&l) { m_lock->unlock(); }
|
||||||
~scoped_unlocker_impl() { if (m_lock) m_lock->lock(); }
|
~scoped_unlocker_impl() { if (m_lock) m_lock->lock(); }
|
||||||
scoped_unlocker_impl(scoped_unlocker_impl&& rhs) : m_lock(rhs.m_lock)
|
scoped_unlocker_impl(scoped_unlocker_impl&& rhs) noexcept : m_lock(rhs.m_lock)
|
||||||
{ rhs.m_lock = nullptr; }
|
{ rhs.m_lock = nullptr; }
|
||||||
scoped_unlocker_impl& operator=(scoped_unlocker_impl&& rhs)
|
scoped_unlocker_impl& operator=(scoped_unlocker_impl&& rhs) noexcept
|
||||||
{
|
{
|
||||||
if (&rhs == this) return *this;
|
if (&rhs == this) return *this;
|
||||||
if (m_lock) m_lock->lock();
|
if (m_lock) m_lock->lock();
|
||||||
|
|
|
@ -232,4 +232,3 @@ namespace libtorrent { namespace aux {
|
||||||
}
|
}
|
||||||
|
|
||||||
}}
|
}}
|
||||||
|
|
||||||
|
|
|
@ -85,7 +85,7 @@ namespace libtorrent {
|
||||||
m_job_pool.free(j);
|
m_job_pool.free(j);
|
||||||
}
|
}
|
||||||
|
|
||||||
void disk_job_pool::free_jobs(disk_io_job** j, int num)
|
void disk_job_pool::free_jobs(disk_io_job** j, int const num)
|
||||||
{
|
{
|
||||||
if (num == 0) return;
|
if (num == 0) return;
|
||||||
|
|
||||||
|
|
|
@ -51,12 +51,11 @@ namespace libtorrent {
|
||||||
std::string::iterator port_pos;
|
std::string::iterator port_pos;
|
||||||
|
|
||||||
// PARSE URL
|
// PARSE URL
|
||||||
std::string::iterator start = url.begin();
|
auto start = url.begin();
|
||||||
// remove white spaces in front of the url
|
// remove white spaces in front of the url
|
||||||
while (start != url.end() && is_space(*start))
|
while (start != url.end() && is_space(*start))
|
||||||
++start;
|
++start;
|
||||||
std::string::iterator end
|
auto end = std::find(url.begin(), url.end(), ':');
|
||||||
= std::find(url.begin(), url.end(), ':');
|
|
||||||
protocol.assign(start, end);
|
protocol.assign(start, end);
|
||||||
|
|
||||||
if (end == url.end())
|
if (end == url.end())
|
||||||
|
@ -116,7 +115,7 @@ namespace libtorrent {
|
||||||
if (port_pos < end)
|
if (port_pos < end)
|
||||||
{
|
{
|
||||||
++port_pos;
|
++port_pos;
|
||||||
for (std::string::iterator i = port_pos; i < end; ++i)
|
for (auto i = port_pos; i < end; ++i)
|
||||||
{
|
{
|
||||||
if (is_digit(*i)) continue;
|
if (is_digit(*i)) continue;
|
||||||
ec = errors::invalid_port;
|
ec = errors::invalid_port;
|
||||||
|
@ -142,14 +141,13 @@ exit:
|
||||||
std::string path;
|
std::string path;
|
||||||
|
|
||||||
// PARSE URL
|
// PARSE URL
|
||||||
std::string::iterator pos
|
auto pos = std::find(url.begin(), url.end(), ':');
|
||||||
= std::find(url.begin(), url.end(), ':');
|
|
||||||
|
|
||||||
if (pos == url.end() || url.end() - pos < 3
|
if (pos == url.end() || url.end() - pos < 3
|
||||||
|| *(pos + 1) != '/' || *(pos + 2) != '/')
|
|| *(pos + 1) != '/' || *(pos + 2) != '/')
|
||||||
{
|
{
|
||||||
ec = errors::unsupported_url_protocol;
|
ec = errors::unsupported_url_protocol;
|
||||||
return std::make_tuple(url, path);
|
return std::make_tuple(std::move(url), std::move(path));
|
||||||
}
|
}
|
||||||
pos += 3; // skip "://"
|
pos += 3; // skip "://"
|
||||||
|
|
||||||
|
|
|
@ -54,14 +54,12 @@ namespace libtorrent {
|
||||||
COMPLETE_ASYNC("resolver::on_lookup");
|
COMPLETE_ASYNC("resolver::on_lookup");
|
||||||
if (ec)
|
if (ec)
|
||||||
{
|
{
|
||||||
std::vector<address> empty;
|
h(ec, {});
|
||||||
h(ec, empty);
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
dns_cache_entry& ce = m_cache[hostname];
|
dns_cache_entry& ce = m_cache[hostname];
|
||||||
time_point now = aux::time_now();
|
ce.last_seen = aux::time_now();
|
||||||
ce.last_seen = now;
|
|
||||||
ce.addresses.clear();
|
ce.addresses.clear();
|
||||||
while (i != tcp::resolver::iterator())
|
while (i != tcp::resolver::iterator())
|
||||||
{
|
{
|
||||||
|
@ -96,9 +94,7 @@ namespace libtorrent {
|
||||||
address const ip = make_address(host, ec);
|
address const ip = make_address(host, ec);
|
||||||
if (!ec)
|
if (!ec)
|
||||||
{
|
{
|
||||||
std::vector<address> addresses;
|
m_ios.post(std::bind(h, ec, std::vector<address>{ip}));
|
||||||
addresses.push_back(ip);
|
|
||||||
m_ios.post(std::bind(h, ec, addresses));
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
ec.clear();
|
ec.clear();
|
||||||
|
@ -119,7 +115,7 @@ namespace libtorrent {
|
||||||
{
|
{
|
||||||
// we did not find a cache entry, fail the lookup
|
// we did not find a cache entry, fail the lookup
|
||||||
m_ios.post(std::bind(h, boost::asio::error::host_not_found
|
m_ios.post(std::bind(h, boost::asio::error::host_not_found
|
||||||
, std::vector<address>()));
|
, std::vector<address>{}));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -145,7 +141,7 @@ namespace libtorrent {
|
||||||
m_resolver.cancel();
|
m_resolver.cancel();
|
||||||
}
|
}
|
||||||
|
|
||||||
void resolver::set_cache_timeout(seconds timeout)
|
void resolver::set_cache_timeout(seconds const timeout)
|
||||||
{
|
{
|
||||||
if (timeout >= seconds(0))
|
if (timeout >= seconds(0))
|
||||||
m_timeout = timeout;
|
m_timeout = timeout;
|
||||||
|
|
Loading…
Reference in New Issue