Disable old resolver functionality if ASIO_NO_DEPRECATED is defined.

This commit is contained in:
Christopher Kohlhoff 2015-05-03 15:27:26 +10:00
parent 69ff104a00
commit 5ab5356e33
11 changed files with 63 additions and 35 deletions

View File

@ -46,9 +46,9 @@
// init_buffers(); // init_buffers();
// this->basic_socket<Protocol, StreamSocketService>::close(ec_); // this->basic_socket<Protocol, StreamSocketService>::close(ec_);
// typedef typename Protocol::resolver resolver_type; // typedef typename Protocol::resolver resolver_type;
// typedef typename resolver_type::query resolver_query; // resolver_type resolver(detail::socket_streambuf_base::io_service_);
// resolver_query query(x1, ..., xn); // connect_to_endpoints(
// resolve_and_connect(query); // resolver.resolve(x1, ..., xn, ec_));
// return !ec_ ? this : 0; // return !ec_ ? this : 0;
// } // }
// This macro should only persist within this file. // This macro should only persist within this file.
@ -62,9 +62,9 @@
init_buffers(); \ init_buffers(); \
this->basic_socket<Protocol, StreamSocketService>::close(ec_); \ this->basic_socket<Protocol, StreamSocketService>::close(ec_); \
typedef typename Protocol::resolver resolver_type; \ typedef typename Protocol::resolver resolver_type; \
typedef typename resolver_type::query resolver_query; \ resolver_type resolver(detail::socket_streambuf_base::io_service_); \
resolver_query query(ASIO_VARIADIC_BYVAL_ARGS(n)); \ connect_to_endpoints( \
resolve_and_connect(query); \ resolver.resolve(ASIO_VARIADIC_BYVAL_ARGS(n), ec_)); \
return !ec_ ? this : 0; \ return !ec_ ? this : 0; \
} \ } \
/**/ /**/
@ -212,9 +212,8 @@ public:
init_buffers(); init_buffers();
this->basic_socket<Protocol, StreamSocketService>::close(ec_); this->basic_socket<Protocol, StreamSocketService>::close(ec_);
typedef typename Protocol::resolver resolver_type; typedef typename Protocol::resolver resolver_type;
typedef typename resolver_type::query resolver_query; resolver_type resolver(detail::socket_streambuf_base::io_service_);
resolver_query query(x...); connect_to_endpoints(resolver.resolve(x..., ec_));
resolve_and_connect(query);
return !ec_ ? this : 0; return !ec_ ? this : 0;
} }
#else #else
@ -518,16 +517,13 @@ private:
setp(&put_buffer_[0], &put_buffer_[0] + put_buffer_.size()); setp(&put_buffer_[0], &put_buffer_[0] + put_buffer_.size());
} }
template <typename ResolverQuery> template <typename EndpointSequence>
void resolve_and_connect(const ResolverQuery& query) void connect_to_endpoints(const EndpointSequence& endpoints)
{ {
typedef typename Protocol::resolver resolver_type;
typedef typename resolver_type::iterator iterator_type;
resolver_type resolver(detail::socket_streambuf_base::io_service_);
iterator_type i = resolver.resolve(query, ec_);
if (!ec_) if (!ec_)
{ {
iterator_type end; typename EndpointSequence::iterator i = endpoints.begin();
typename EndpointSequence::iterator end = endpoints.end();
ec_ = asio::error::host_not_found; ec_ = asio::error::host_not_found;
while (ec_ && i != end) while (ec_ && i != end)
{ {

View File

@ -128,6 +128,7 @@ typename Protocol::endpoint connect(basic_socket<Protocol, SocketService>& s,
typename enable_if<is_endpoint_sequence< typename enable_if<is_endpoint_sequence<
EndpointSequence>::value>::type* = 0); EndpointSequence>::value>::type* = 0);
#if !defined(ASIO_NO_DEPRECATED)
/// (Deprecated.) Establishes a socket connection by trying each endpoint in a /// (Deprecated.) Establishes a socket connection by trying each endpoint in a
/// sequence. /// sequence.
/** /**
@ -184,6 +185,7 @@ template <typename Protocol, typename SocketService, typename Iterator>
Iterator connect(basic_socket<Protocol, SocketService>& s, Iterator connect(basic_socket<Protocol, SocketService>& s,
Iterator begin, asio::error_code& ec, Iterator begin, asio::error_code& ec,
typename enable_if<!is_endpoint_sequence<Iterator>::value>::type* = 0); typename enable_if<!is_endpoint_sequence<Iterator>::value>::type* = 0);
#endif // !defined(ASIO_NO_DEPRECATED)
/// Establishes a socket connection by trying each endpoint in a sequence. /// Establishes a socket connection by trying each endpoint in a sequence.
/** /**
@ -379,6 +381,7 @@ typename Protocol::endpoint connect(basic_socket<Protocol, SocketService>& s,
typename enable_if<is_endpoint_sequence< typename enable_if<is_endpoint_sequence<
EndpointSequence>::value>::type* = 0); EndpointSequence>::value>::type* = 0);
#if !defined(ASIO_NO_DEPRECATED)
/// (Deprecated.) Establishes a socket connection by trying each endpoint in a /// (Deprecated.) Establishes a socket connection by trying each endpoint in a
/// sequence. /// sequence.
/** /**
@ -460,6 +463,7 @@ template <typename Protocol, typename SocketService,
Iterator connect(basic_socket<Protocol, SocketService>& s, Iterator begin, Iterator connect(basic_socket<Protocol, SocketService>& s, Iterator begin,
ConnectCondition connect_condition, asio::error_code& ec, ConnectCondition connect_condition, asio::error_code& ec,
typename enable_if<!is_endpoint_sequence<Iterator>::value>::type* = 0); typename enable_if<!is_endpoint_sequence<Iterator>::value>::type* = 0);
#endif // !defined(ASIO_NO_DEPRECATED)
/// Establishes a socket connection by trying each endpoint in a sequence. /// Establishes a socket connection by trying each endpoint in a sequence.
/** /**
@ -670,6 +674,7 @@ async_connect(basic_socket<Protocol, SocketService>& s,
typename enable_if<is_endpoint_sequence< typename enable_if<is_endpoint_sequence<
EndpointSequence>::value>::type* = 0); EndpointSequence>::value>::type* = 0);
#if !defined(ASIO_NO_DEPRECATED)
/// (Deprecated.) Asynchronously establishes a socket connection by trying each /// (Deprecated.) Asynchronously establishes a socket connection by trying each
/// endpoint in a sequence. /// endpoint in a sequence.
/** /**
@ -712,6 +717,7 @@ ASIO_INITFN_RESULT_TYPE(IteratorConnectHandler,
async_connect(basic_socket<Protocol, SocketService>& s, async_connect(basic_socket<Protocol, SocketService>& s,
Iterator begin, ASIO_MOVE_ARG(IteratorConnectHandler) handler, Iterator begin, ASIO_MOVE_ARG(IteratorConnectHandler) handler,
typename enable_if<!is_endpoint_sequence<Iterator>::value>::type* = 0); typename enable_if<!is_endpoint_sequence<Iterator>::value>::type* = 0);
#endif // !defined(ASIO_NO_DEPRECATED)
/// Asynchronously establishes a socket connection by trying each endpoint in a /// Asynchronously establishes a socket connection by trying each endpoint in a
/// sequence. /// sequence.
@ -875,6 +881,7 @@ async_connect(basic_socket<Protocol, SocketService>& s,
typename enable_if<is_endpoint_sequence< typename enable_if<is_endpoint_sequence<
EndpointSequence>::value>::type* = 0); EndpointSequence>::value>::type* = 0);
#if !defined(ASIO_NO_DEPRECATED)
/// (Deprecated.) Asynchronously establishes a socket connection by trying each /// (Deprecated.) Asynchronously establishes a socket connection by trying each
/// endpoint in a sequence. /// endpoint in a sequence.
/** /**
@ -929,6 +936,7 @@ async_connect(basic_socket<Protocol, SocketService>& s, Iterator begin,
ConnectCondition connect_condition, ConnectCondition connect_condition,
ASIO_MOVE_ARG(IteratorConnectHandler) handler, ASIO_MOVE_ARG(IteratorConnectHandler) handler,
typename enable_if<!is_endpoint_sequence<Iterator>::value>::type* = 0); typename enable_if<!is_endpoint_sequence<Iterator>::value>::type* = 0);
#endif // !defined(ASIO_NO_DEPRECATED)
/// Asynchronously establishes a socket connection by trying each endpoint in a /// Asynchronously establishes a socket connection by trying each endpoint in a
/// sequence. /// sequence.

View File

@ -68,6 +68,7 @@ typename Protocol::endpoint connect(basic_socket<Protocol, SocketService>& s,
return ec ? typename Protocol::endpoint() : *iter; return ec ? typename Protocol::endpoint() : *iter;
} }
#if !defined(ASIO_NO_DEPRECATED)
template <typename Protocol, typename SocketService, typename Iterator> template <typename Protocol, typename SocketService, typename Iterator>
Iterator connect(basic_socket<Protocol, SocketService>& s, Iterator begin, Iterator connect(basic_socket<Protocol, SocketService>& s, Iterator begin,
typename enable_if<!is_endpoint_sequence<Iterator>::value>::type*) typename enable_if<!is_endpoint_sequence<Iterator>::value>::type*)
@ -85,6 +86,7 @@ inline Iterator connect(basic_socket<Protocol, SocketService>& s,
{ {
return connect(s, begin, Iterator(), detail::default_connect_condition(), ec); return connect(s, begin, Iterator(), detail::default_connect_condition(), ec);
} }
#endif // !defined(ASIO_NO_DEPRECATED)
template <typename Protocol, typename SocketService, typename Iterator> template <typename Protocol, typename SocketService, typename Iterator>
Iterator connect(basic_socket<Protocol, SocketService>& s, Iterator connect(basic_socket<Protocol, SocketService>& s,
@ -130,6 +132,7 @@ typename Protocol::endpoint connect(basic_socket<Protocol, SocketService>& s,
return ec ? typename Protocol::endpoint() : *iter; return ec ? typename Protocol::endpoint() : *iter;
} }
#if !defined(ASIO_NO_DEPRECATED)
template <typename Protocol, typename SocketService, template <typename Protocol, typename SocketService,
typename Iterator, typename ConnectCondition> typename Iterator, typename ConnectCondition>
Iterator connect(basic_socket<Protocol, SocketService>& s, Iterator connect(basic_socket<Protocol, SocketService>& s,
@ -151,6 +154,7 @@ inline Iterator connect(basic_socket<Protocol, SocketService>& s,
{ {
return connect(s, begin, Iterator(), connect_condition, ec); return connect(s, begin, Iterator(), connect_condition, ec);
} }
#endif // !defined(ASIO_NO_DEPRECATED)
template <typename Protocol, typename SocketService, template <typename Protocol, typename SocketService,
typename Iterator, typename ConnectCondition> typename Iterator, typename ConnectCondition>
@ -654,6 +658,7 @@ async_connect(basic_socket<Protocol, SocketService>& s,
return init.result.get(); return init.result.get();
} }
#if !defined(ASIO_NO_DEPRECATED)
template <typename Protocol, typename SocketService, template <typename Protocol, typename SocketService,
typename Iterator, typename IteratorConnectHandler> typename Iterator, typename IteratorConnectHandler>
inline ASIO_INITFN_RESULT_TYPE(IteratorConnectHandler, inline ASIO_INITFN_RESULT_TYPE(IteratorConnectHandler,
@ -678,6 +683,7 @@ async_connect(basic_socket<Protocol, SocketService>& s,
return init.result.get(); return init.result.get();
} }
#endif // !defined(ASIO_NO_DEPRECATED)
template <typename Protocol, typename SocketService, template <typename Protocol, typename SocketService,
typename Iterator, typename IteratorConnectHandler> typename Iterator, typename IteratorConnectHandler>
@ -732,6 +738,7 @@ async_connect(basic_socket<Protocol, SocketService>& s,
return init.result.get(); return init.result.get();
} }
#if !defined(ASIO_NO_DEPRECATED)
template <typename Protocol, typename SocketService, typename Iterator, template <typename Protocol, typename SocketService, typename Iterator,
typename ConnectCondition, typename IteratorConnectHandler> typename ConnectCondition, typename IteratorConnectHandler>
inline ASIO_INITFN_RESULT_TYPE(IteratorConnectHandler, inline ASIO_INITFN_RESULT_TYPE(IteratorConnectHandler,
@ -757,6 +764,7 @@ async_connect(basic_socket<Protocol, SocketService>& s,
return init.result.get(); return init.result.get();
} }
#endif // !defined(ASIO_NO_DEPRECATED)
template <typename Protocol, typename SocketService, typename Iterator, template <typename Protocol, typename SocketService, typename Iterator,
typename ConnectCondition, typename IteratorConnectHandler> typename ConnectCondition, typename IteratorConnectHandler>

View File

@ -54,11 +54,13 @@ public:
/// The endpoint type. /// The endpoint type.
typedef typename InternetProtocol::endpoint endpoint_type; typedef typename InternetProtocol::endpoint endpoint_type;
#if !defined(ASIO_NO_DEPRECATED)
/// (Deprecated.) The query type. /// (Deprecated.) The query type.
typedef basic_resolver_query<InternetProtocol> query; typedef basic_resolver_query<InternetProtocol> query;
/// (Deprecated.) The iterator type. /// (Deprecated.) The iterator type.
typedef basic_resolver_iterator<InternetProtocol> iterator; typedef basic_resolver_iterator<InternetProtocol> iterator;
#endif // !defined(ASIO_NO_DEPRECATED)
/// The results type. /// The results type.
typedef basic_resolver_results<InternetProtocol> results_type; typedef basic_resolver_results<InternetProtocol> results_type;
@ -86,6 +88,7 @@ public:
return this->get_service().cancel(this->get_implementation()); return this->get_service().cancel(this->get_implementation());
} }
#if !defined(ASIO_NO_DEPRECATED)
/// (Deprecated.) Perform forward resolution of a query to a list of entries. /// (Deprecated.) Perform forward resolution of a query to a list of entries.
/** /**
* This function is used to resolve a query into a list of endpoint entries. * This function is used to resolve a query into a list of endpoint entries.
@ -123,6 +126,7 @@ public:
{ {
return this->get_service().resolve(this->get_implementation(), q, ec); return this->get_service().resolve(this->get_implementation(), q, ec);
} }
#endif // !defined(ASIO_NO_DEPRECATED)
/// Perform forward resolution of a query to a list of entries. /// Perform forward resolution of a query to a list of entries.
/** /**
@ -242,7 +246,7 @@ public:
resolver_base::flags resolve_flags) resolver_base::flags resolve_flags)
{ {
asio::error_code ec; asio::error_code ec;
query q(host, service, resolve_flags); basic_resolver_query<protocol_type> q(host, service, resolve_flags);
results_type r = this->get_service().resolve( results_type r = this->get_service().resolve(
this->get_implementation(), q, ec); this->get_implementation(), q, ec);
asio::detail::throw_error(ec, "resolve"); asio::detail::throw_error(ec, "resolve");
@ -289,7 +293,7 @@ public:
results_type resolve(const std::string& host, const std::string& service, results_type resolve(const std::string& host, const std::string& service,
resolver_base::flags resolve_flags, asio::error_code& ec) resolver_base::flags resolve_flags, asio::error_code& ec)
{ {
query q(host, service, resolve_flags); basic_resolver_query<protocol_type> q(host, service, resolve_flags);
return this->get_service().resolve(this->get_implementation(), q, ec); return this->get_service().resolve(this->get_implementation(), q, ec);
} }
@ -421,7 +425,8 @@ public:
const std::string& service, resolver_base::flags resolve_flags) const std::string& service, resolver_base::flags resolve_flags)
{ {
asio::error_code ec; asio::error_code ec;
query q(protocol, host, service, resolve_flags); basic_resolver_query<protocol_type> q(
protocol, host, service, resolve_flags);
results_type r = this->get_service().resolve( results_type r = this->get_service().resolve(
this->get_implementation(), q, ec); this->get_implementation(), q, ec);
asio::detail::throw_error(ec, "resolve"); asio::detail::throw_error(ec, "resolve");
@ -472,10 +477,12 @@ public:
const std::string& service, resolver_base::flags resolve_flags, const std::string& service, resolver_base::flags resolve_flags,
asio::error_code& ec) asio::error_code& ec)
{ {
query q(protocol, host, service, resolve_flags); basic_resolver_query<protocol_type> q(
protocol, host, service, resolve_flags);
return this->get_service().resolve(this->get_implementation(), q, ec); return this->get_service().resolve(this->get_implementation(), q, ec);
} }
#if !defined(ASIO_NO_DEPRECATED)
/// (Deprecated.) Asynchronously perform forward resolution of a query to a /// (Deprecated.) Asynchronously perform forward resolution of a query to a
/// list of entries. /// list of entries.
/** /**
@ -513,6 +520,7 @@ public:
return this->get_service().async_resolve(this->get_implementation(), q, return this->get_service().async_resolve(this->get_implementation(), q,
ASIO_MOVE_CAST(ResolveHandler)(handler)); ASIO_MOVE_CAST(ResolveHandler)(handler));
} }
#endif // !defined(ASIO_NO_DEPRECATED)
/// Asynchronously perform forward resolution of a query to a list of entries. /// Asynchronously perform forward resolution of a query to a list of entries.
/** /**
@ -624,7 +632,7 @@ public:
ASIO_RESOLVE_HANDLER_CHECK( ASIO_RESOLVE_HANDLER_CHECK(
ResolveHandler, handler, results_type) type_check; ResolveHandler, handler, results_type) type_check;
query q(host, service, resolve_flags); basic_resolver_query<protocol_type> q(host, service, resolve_flags);
return this->get_service().async_resolve(this->get_implementation(), q, return this->get_service().async_resolve(this->get_implementation(), q,
ASIO_MOVE_CAST(ResolveHandler)(handler)); ASIO_MOVE_CAST(ResolveHandler)(handler));
} }
@ -745,7 +753,8 @@ public:
ASIO_RESOLVE_HANDLER_CHECK( ASIO_RESOLVE_HANDLER_CHECK(
ResolveHandler, handler, results_type) type_check; ResolveHandler, handler, results_type) type_check;
query q(protocol, host, service, resolve_flags); basic_resolver_query<protocol_type> q(
protocol, host, service, resolve_flags);
return this->get_service().async_resolve(this->get_implementation(), q, return this->get_service().async_resolve(this->get_implementation(), q,
ASIO_MOVE_CAST(ResolveHandler)(handler)); ASIO_MOVE_CAST(ResolveHandler)(handler));
} }

View File

@ -48,7 +48,11 @@ namespace ip {
*/ */
template <typename InternetProtocol> template <typename InternetProtocol>
class basic_resolver_results class basic_resolver_results
#if !defined(ASIO_NO_DEPRECATED)
: public basic_resolver_iterator<InternetProtocol> : public basic_resolver_iterator<InternetProtocol>
#else // !defined(ASIO_NO_DEPRECATED)
: private basic_resolver_iterator<InternetProtocol>
#endif // !defined(ASIO_NO_DEPRECATED)
{ {
public: public:
/// The protocol type associated with the results. /// The protocol type associated with the results.

View File

@ -32,7 +32,7 @@ int main(int argc, char* argv[])
udp::socket s(io_service, udp::endpoint(udp::v4(), 0)); udp::socket s(io_service, udp::endpoint(udp::v4(), 0));
udp::resolver resolver(io_service); udp::resolver resolver(io_service);
udp::resolver::iterator iterator = udp::resolver::results_type endpoints =
resolver.resolve(udp::v4(), argv[1], argv[2]); resolver.resolve(udp::v4(), argv[1], argv[2]);
using namespace std; // For strlen. using namespace std; // For strlen.
@ -40,7 +40,7 @@ int main(int argc, char* argv[])
char request[max_length]; char request[max_length];
std::cin.getline(request, max_length); std::cin.getline(request, max_length);
size_t request_length = strlen(request); size_t request_length = strlen(request);
s.send_to(asio::buffer(request, request_length), *iterator); s.send_to(asio::buffer(request, request_length), *endpoints.begin());
char reply[max_length]; char reply[max_length];
udp::endpoint sender_endpoint; udp::endpoint sender_endpoint;

View File

@ -28,7 +28,7 @@ public:
: resolver_(io_service), socket_(io_service, icmp::v4()), : resolver_(io_service), socket_(io_service, icmp::v4()),
timer_(io_service), sequence_number_(0), num_replies_(0) timer_(io_service), sequence_number_(0), num_replies_(0)
{ {
destination_ = *resolver_.resolve(icmp::v4(), destination, ""); destination_ = *resolver_.resolve(icmp::v4(), destination, "").begin();
start_send(); start_send();
start_receive(); start_receive();

View File

@ -41,7 +41,7 @@ int main(int argc, char* argv[])
// Determine the location of the server. // Determine the location of the server.
tcp::resolver resolver(io_service); tcp::resolver resolver(io_service);
tcp::endpoint remote_endpoint = *resolver.resolve(host_name, port); tcp::endpoint remote_endpoint = *resolver.resolve(host_name, port).begin();
// Establish the control connection to the server. // Establish the control connection to the server.
tcp::socket control_socket(io_service); tcp::socket control_socket(io_service);

View File

@ -92,11 +92,12 @@ public:
} }
// Called by the user of the client class to initiate the connection process. // Called by the user of the client class to initiate the connection process.
// The endpoint iterator will have been obtained using a tcp::resolver. // The endpoints will have been obtained using a tcp::resolver.
void start(tcp::resolver::iterator endpoint_iter) void start(tcp::resolver::results_type endpoints)
{ {
// Start the connect actor. // Start the connect actor.
start_connect(endpoint_iter); endpoints_ = endpoints;
start_connect(endpoints_.begin());
// Start the deadline actor. You will note that we're not setting any // Start the deadline actor. You will note that we're not setting any
// particular deadline here. Instead, the connect and input actors will // particular deadline here. Instead, the connect and input actors will
@ -117,9 +118,9 @@ public:
} }
private: private:
void start_connect(tcp::resolver::iterator endpoint_iter) void start_connect(tcp::resolver::results_type::iterator endpoint_iter)
{ {
if (endpoint_iter != tcp::resolver::iterator()) if (endpoint_iter != endpoints_.end())
{ {
std::cout << "Trying " << endpoint_iter->endpoint() << "...\n"; std::cout << "Trying " << endpoint_iter->endpoint() << "...\n";
@ -139,7 +140,7 @@ private:
} }
void handle_connect(const asio::error_code& ec, void handle_connect(const asio::error_code& ec,
tcp::resolver::iterator endpoint_iter) tcp::resolver::results_type::iterator endpoint_iter)
{ {
if (stopped_) if (stopped_)
return; return;
@ -273,6 +274,7 @@ private:
private: private:
bool stopped_; bool stopped_;
tcp::resolver::results_type endpoints_;
tcp::socket socket_; tcp::socket socket_;
asio::streambuf input_buffer_; asio::streambuf input_buffer_;
deadline_timer deadline_; deadline_timer deadline_;

View File

@ -32,13 +32,14 @@ int main(int argc, char* argv[])
udp::socket s(io_service, udp::endpoint(udp::v4(), 0)); udp::socket s(io_service, udp::endpoint(udp::v4(), 0));
udp::resolver resolver(io_service); udp::resolver resolver(io_service);
udp::endpoint endpoint = *resolver.resolve(udp::v4(), argv[1], argv[2]); udp::resolver::results_type endpoints =
resolver.resolve(udp::v4(), argv[1], argv[2]);
std::cout << "Enter message: "; std::cout << "Enter message: ";
char request[max_length]; char request[max_length];
std::cin.getline(request, max_length); std::cin.getline(request, max_length);
size_t request_length = std::strlen(request); size_t request_length = std::strlen(request);
s.send_to(asio::buffer(request, request_length), endpoint); s.send_to(asio::buffer(request, request_length), *endpoints.begin());
char reply[max_length]; char reply[max_length];
udp::endpoint sender_endpoint; udp::endpoint sender_endpoint;

View File

@ -255,7 +255,7 @@ int main(int argc, char* argv[])
asio::ip::tcp::resolver r(ios); asio::ip::tcp::resolver r(ios);
asio::ip::tcp::resolver::results_type endpoints = asio::ip::tcp::resolver::results_type endpoints =
r.resolve(asio::ip::tcp::resolver::query(host, port)); r.resolve(host, port);
client c(ios, endpoints, block_size, session_count, timeout); client c(ios, endpoints, block_size, session_count, timeout);