Use string_view in basic_resolver and basic_resolver_entry.

This commit is contained in:
Christopher Kohlhoff 2016-09-23 08:16:51 +10:00
parent 6c97b611fd
commit cb22512a90
2 changed files with 47 additions and 31 deletions

View File

@ -20,6 +20,7 @@
#include "asio/async_result.hpp"
#include "asio/basic_io_object.hpp"
#include "asio/detail/handler_type_requirements.hpp"
#include "asio/detail/string_view.hpp"
#include "asio/detail/throw_error.hpp"
#include "asio/error.hpp"
#include "asio/io_context.hpp"
@ -269,7 +270,8 @@ public:
* <tt>c:\\windows\\system32\\drivers\\etc\\services</tt>. Operating systems
* may use additional locations when resolving service names.
*/
results_type resolve(const std::string& host, const std::string& service)
results_type resolve(ASIO_STRING_VIEW_PARAM host,
ASIO_STRING_VIEW_PARAM service)
{
return resolve(host, service, resolver_base::flags());
}
@ -307,8 +309,8 @@ public:
* <tt>c:\\windows\\system32\\drivers\\etc\\services</tt>. Operating systems
* may use additional locations when resolving service names.
*/
results_type resolve(const std::string& host, const std::string& service,
asio::error_code& ec)
results_type resolve(ASIO_STRING_VIEW_PARAM host,
ASIO_STRING_VIEW_PARAM service, asio::error_code& ec)
{
return resolve(host, service, resolver_base::flags(), ec);
}
@ -350,11 +352,12 @@ public:
* <tt>c:\\windows\\system32\\drivers\\etc\\services</tt>. Operating systems
* may use additional locations when resolving service names.
*/
results_type resolve(const std::string& host, const std::string& service,
resolver_base::flags resolve_flags)
results_type resolve(ASIO_STRING_VIEW_PARAM host,
ASIO_STRING_VIEW_PARAM service, resolver_base::flags resolve_flags)
{
asio::error_code ec;
basic_resolver_query<protocol_type> q(host, service, resolve_flags);
basic_resolver_query<protocol_type> q(static_cast<std::string>(host),
static_cast<std::string>(service), resolve_flags);
results_type r = this->get_service().resolve(
this->get_implementation(), q, ec);
asio::detail::throw_error(ec, "resolve");
@ -398,10 +401,12 @@ public:
* <tt>c:\\windows\\system32\\drivers\\etc\\services</tt>. Operating systems
* may use additional locations when resolving service names.
*/
results_type resolve(const std::string& host, const std::string& service,
resolver_base::flags resolve_flags, asio::error_code& ec)
results_type resolve(ASIO_STRING_VIEW_PARAM host,
ASIO_STRING_VIEW_PARAM service, resolver_base::flags resolve_flags,
asio::error_code& ec)
{
basic_resolver_query<protocol_type> q(host, service, resolve_flags);
basic_resolver_query<protocol_type> q(static_cast<std::string>(host),
static_cast<std::string>(service), resolve_flags);
return this->get_service().resolve(this->get_implementation(), q, ec);
}
@ -441,8 +446,8 @@ public:
* <tt>c:\\windows\\system32\\drivers\\etc\\services</tt>. Operating systems
* may use additional locations when resolving service names.
*/
results_type resolve(const protocol_type& protocol, const std::string& host,
const std::string& service)
results_type resolve(const protocol_type& protocol,
ASIO_STRING_VIEW_PARAM host, ASIO_STRING_VIEW_PARAM service)
{
return resolve(protocol, host, service, resolver_base::flags());
}
@ -483,8 +488,9 @@ public:
* <tt>c:\\windows\\system32\\drivers\\etc\\services</tt>. Operating systems
* may use additional locations when resolving service names.
*/
results_type resolve(const protocol_type& protocol, const std::string& host,
const std::string& service, asio::error_code& ec)
results_type resolve(const protocol_type& protocol,
ASIO_STRING_VIEW_PARAM host, ASIO_STRING_VIEW_PARAM service,
asio::error_code& ec)
{
return resolve(protocol, host, service, resolver_base::flags(), ec);
}
@ -529,12 +535,14 @@ public:
* <tt>c:\\windows\\system32\\drivers\\etc\\services</tt>. Operating systems
* may use additional locations when resolving service names.
*/
results_type resolve(const protocol_type& protocol, const std::string& host,
const std::string& service, resolver_base::flags resolve_flags)
results_type resolve(const protocol_type& protocol,
ASIO_STRING_VIEW_PARAM host, ASIO_STRING_VIEW_PARAM service,
resolver_base::flags resolve_flags)
{
asio::error_code ec;
basic_resolver_query<protocol_type> q(
protocol, host, service, resolve_flags);
protocol, static_cast<std::string>(host),
static_cast<std::string>(service), resolve_flags);
results_type r = this->get_service().resolve(
this->get_implementation(), q, ec);
asio::detail::throw_error(ec, "resolve");
@ -581,12 +589,13 @@ public:
* <tt>c:\\windows\\system32\\drivers\\etc\\services</tt>. Operating systems
* may use additional locations when resolving service names.
*/
results_type resolve(const protocol_type& protocol, const std::string& host,
const std::string& service, resolver_base::flags resolve_flags,
asio::error_code& ec)
results_type resolve(const protocol_type& protocol,
ASIO_STRING_VIEW_PARAM host, ASIO_STRING_VIEW_PARAM service,
resolver_base::flags resolve_flags, asio::error_code& ec)
{
basic_resolver_query<protocol_type> q(
protocol, host, service, resolve_flags);
protocol, static_cast<std::string>(host),
static_cast<std::string>(service), resolve_flags);
return this->get_service().resolve(this->get_implementation(), q, ec);
}
@ -685,7 +694,8 @@ public:
template <typename ResolveHandler>
ASIO_INITFN_RESULT_TYPE(ResolveHandler,
void (asio::error_code, results_type))
async_resolve(const std::string& host, const std::string& service,
async_resolve(ASIO_STRING_VIEW_PARAM host,
ASIO_STRING_VIEW_PARAM service,
ASIO_MOVE_ARG(ResolveHandler) handler)
{
return async_resolve(host, service, resolver_base::flags(),
@ -741,7 +751,8 @@ public:
template <typename ResolveHandler>
ASIO_INITFN_RESULT_TYPE(ResolveHandler,
void (asio::error_code, results_type))
async_resolve(const std::string& host, const std::string& service,
async_resolve(ASIO_STRING_VIEW_PARAM host,
ASIO_STRING_VIEW_PARAM service,
resolver_base::flags resolve_flags,
ASIO_MOVE_ARG(ResolveHandler) handler)
{
@ -750,7 +761,8 @@ public:
ASIO_RESOLVE_HANDLER_CHECK(
ResolveHandler, handler, results_type) type_check;
basic_resolver_query<protocol_type> q(host, service, resolve_flags);
basic_resolver_query<protocol_type> q(static_cast<std::string>(host),
static_cast<std::string>(service), resolve_flags);
#if defined(ASIO_ENABLE_OLD_SERVICES)
return this->get_service().async_resolve(this->get_implementation(), q,
@ -814,8 +826,9 @@ public:
template <typename ResolveHandler>
ASIO_INITFN_RESULT_TYPE(ResolveHandler,
void (asio::error_code, results_type))
async_resolve(const protocol_type& protocol, const std::string& host,
const std::string& service, ASIO_MOVE_ARG(ResolveHandler) handler)
async_resolve(const protocol_type& protocol,
ASIO_STRING_VIEW_PARAM host, ASIO_STRING_VIEW_PARAM service,
ASIO_MOVE_ARG(ResolveHandler) handler)
{
return async_resolve(protocol, host, service, resolver_base::flags(),
ASIO_MOVE_CAST(ResolveHandler)(handler));
@ -873,8 +886,9 @@ public:
template <typename ResolveHandler>
ASIO_INITFN_RESULT_TYPE(ResolveHandler,
void (asio::error_code, results_type))
async_resolve(const protocol_type& protocol, const std::string& host,
const std::string& service, resolver_base::flags resolve_flags,
async_resolve(const protocol_type& protocol,
ASIO_STRING_VIEW_PARAM host, ASIO_STRING_VIEW_PARAM service,
resolver_base::flags resolve_flags,
ASIO_MOVE_ARG(ResolveHandler) handler)
{
// If you get an error on the following line it means that your handler does
@ -883,7 +897,8 @@ public:
ResolveHandler, handler, results_type) type_check;
basic_resolver_query<protocol_type> q(
protocol, host, service, resolve_flags);
protocol, static_cast<std::string>(host),
static_cast<std::string>(service), resolve_flags);
#if defined(ASIO_ENABLE_OLD_SERVICES)
return this->get_service().async_resolve(this->get_implementation(), q,

View File

@ -17,6 +17,7 @@
#include "asio/detail/config.hpp"
#include <string>
#include "asio/detail/string_view.hpp"
#include "asio/detail/push_options.hpp"
@ -49,10 +50,10 @@ public:
/// Construct with specified endpoint, host name and service name.
basic_resolver_entry(const endpoint_type& ep,
const std::string& host, const std::string& service)
ASIO_STRING_VIEW_PARAM host, ASIO_STRING_VIEW_PARAM service)
: endpoint_(ep),
host_name_(host),
service_name_(service)
host_name_(static_cast<std::string>(host)),
service_name_(static_cast<std::string>(service))
{
}