Disable old resolver functionality if ASIO_NO_DEPRECATED is defined.
This commit is contained in:
parent
69ff104a00
commit
5ab5356e33
@ -46,9 +46,9 @@
|
||||
// init_buffers();
|
||||
// this->basic_socket<Protocol, StreamSocketService>::close(ec_);
|
||||
// typedef typename Protocol::resolver resolver_type;
|
||||
// typedef typename resolver_type::query resolver_query;
|
||||
// resolver_query query(x1, ..., xn);
|
||||
// resolve_and_connect(query);
|
||||
// resolver_type resolver(detail::socket_streambuf_base::io_service_);
|
||||
// connect_to_endpoints(
|
||||
// resolver.resolve(x1, ..., xn, ec_));
|
||||
// return !ec_ ? this : 0;
|
||||
// }
|
||||
// This macro should only persist within this file.
|
||||
@ -62,9 +62,9 @@
|
||||
init_buffers(); \
|
||||
this->basic_socket<Protocol, StreamSocketService>::close(ec_); \
|
||||
typedef typename Protocol::resolver resolver_type; \
|
||||
typedef typename resolver_type::query resolver_query; \
|
||||
resolver_query query(ASIO_VARIADIC_BYVAL_ARGS(n)); \
|
||||
resolve_and_connect(query); \
|
||||
resolver_type resolver(detail::socket_streambuf_base::io_service_); \
|
||||
connect_to_endpoints( \
|
||||
resolver.resolve(ASIO_VARIADIC_BYVAL_ARGS(n), ec_)); \
|
||||
return !ec_ ? this : 0; \
|
||||
} \
|
||||
/**/
|
||||
@ -212,9 +212,8 @@ public:
|
||||
init_buffers();
|
||||
this->basic_socket<Protocol, StreamSocketService>::close(ec_);
|
||||
typedef typename Protocol::resolver resolver_type;
|
||||
typedef typename resolver_type::query resolver_query;
|
||||
resolver_query query(x...);
|
||||
resolve_and_connect(query);
|
||||
resolver_type resolver(detail::socket_streambuf_base::io_service_);
|
||||
connect_to_endpoints(resolver.resolve(x..., ec_));
|
||||
return !ec_ ? this : 0;
|
||||
}
|
||||
#else
|
||||
@ -518,16 +517,13 @@ private:
|
||||
setp(&put_buffer_[0], &put_buffer_[0] + put_buffer_.size());
|
||||
}
|
||||
|
||||
template <typename ResolverQuery>
|
||||
void resolve_and_connect(const ResolverQuery& query)
|
||||
template <typename EndpointSequence>
|
||||
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_)
|
||||
{
|
||||
iterator_type end;
|
||||
typename EndpointSequence::iterator i = endpoints.begin();
|
||||
typename EndpointSequence::iterator end = endpoints.end();
|
||||
ec_ = asio::error::host_not_found;
|
||||
while (ec_ && i != end)
|
||||
{
|
||||
|
@ -128,6 +128,7 @@ typename Protocol::endpoint connect(basic_socket<Protocol, SocketService>& s,
|
||||
typename enable_if<is_endpoint_sequence<
|
||||
EndpointSequence>::value>::type* = 0);
|
||||
|
||||
#if !defined(ASIO_NO_DEPRECATED)
|
||||
/// (Deprecated.) Establishes a socket connection by trying each endpoint in a
|
||||
/// sequence.
|
||||
/**
|
||||
@ -184,6 +185,7 @@ template <typename Protocol, typename SocketService, typename Iterator>
|
||||
Iterator connect(basic_socket<Protocol, SocketService>& s,
|
||||
Iterator begin, asio::error_code& ec,
|
||||
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.
|
||||
/**
|
||||
@ -379,6 +381,7 @@ typename Protocol::endpoint connect(basic_socket<Protocol, SocketService>& s,
|
||||
typename enable_if<is_endpoint_sequence<
|
||||
EndpointSequence>::value>::type* = 0);
|
||||
|
||||
#if !defined(ASIO_NO_DEPRECATED)
|
||||
/// (Deprecated.) Establishes a socket connection by trying each endpoint in a
|
||||
/// sequence.
|
||||
/**
|
||||
@ -460,6 +463,7 @@ template <typename Protocol, typename SocketService,
|
||||
Iterator connect(basic_socket<Protocol, SocketService>& s, Iterator begin,
|
||||
ConnectCondition connect_condition, asio::error_code& ec,
|
||||
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.
|
||||
/**
|
||||
@ -670,6 +674,7 @@ async_connect(basic_socket<Protocol, SocketService>& s,
|
||||
typename enable_if<is_endpoint_sequence<
|
||||
EndpointSequence>::value>::type* = 0);
|
||||
|
||||
#if !defined(ASIO_NO_DEPRECATED)
|
||||
/// (Deprecated.) Asynchronously establishes a socket connection by trying each
|
||||
/// endpoint in a sequence.
|
||||
/**
|
||||
@ -712,6 +717,7 @@ ASIO_INITFN_RESULT_TYPE(IteratorConnectHandler,
|
||||
async_connect(basic_socket<Protocol, SocketService>& s,
|
||||
Iterator begin, ASIO_MOVE_ARG(IteratorConnectHandler) handler,
|
||||
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
|
||||
/// sequence.
|
||||
@ -875,6 +881,7 @@ async_connect(basic_socket<Protocol, SocketService>& s,
|
||||
typename enable_if<is_endpoint_sequence<
|
||||
EndpointSequence>::value>::type* = 0);
|
||||
|
||||
#if !defined(ASIO_NO_DEPRECATED)
|
||||
/// (Deprecated.) Asynchronously establishes a socket connection by trying each
|
||||
/// endpoint in a sequence.
|
||||
/**
|
||||
@ -929,6 +936,7 @@ async_connect(basic_socket<Protocol, SocketService>& s, Iterator begin,
|
||||
ConnectCondition connect_condition,
|
||||
ASIO_MOVE_ARG(IteratorConnectHandler) handler,
|
||||
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
|
||||
/// sequence.
|
||||
|
@ -68,6 +68,7 @@ typename Protocol::endpoint connect(basic_socket<Protocol, SocketService>& s,
|
||||
return ec ? typename Protocol::endpoint() : *iter;
|
||||
}
|
||||
|
||||
#if !defined(ASIO_NO_DEPRECATED)
|
||||
template <typename Protocol, typename SocketService, typename Iterator>
|
||||
Iterator connect(basic_socket<Protocol, SocketService>& s, Iterator begin,
|
||||
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);
|
||||
}
|
||||
#endif // !defined(ASIO_NO_DEPRECATED)
|
||||
|
||||
template <typename Protocol, typename SocketService, typename Iterator>
|
||||
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;
|
||||
}
|
||||
|
||||
#if !defined(ASIO_NO_DEPRECATED)
|
||||
template <typename Protocol, typename SocketService,
|
||||
typename Iterator, typename ConnectCondition>
|
||||
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);
|
||||
}
|
||||
#endif // !defined(ASIO_NO_DEPRECATED)
|
||||
|
||||
template <typename Protocol, typename SocketService,
|
||||
typename Iterator, typename ConnectCondition>
|
||||
@ -654,6 +658,7 @@ async_connect(basic_socket<Protocol, SocketService>& s,
|
||||
return init.result.get();
|
||||
}
|
||||
|
||||
#if !defined(ASIO_NO_DEPRECATED)
|
||||
template <typename Protocol, typename SocketService,
|
||||
typename Iterator, typename IteratorConnectHandler>
|
||||
inline ASIO_INITFN_RESULT_TYPE(IteratorConnectHandler,
|
||||
@ -678,6 +683,7 @@ async_connect(basic_socket<Protocol, SocketService>& s,
|
||||
|
||||
return init.result.get();
|
||||
}
|
||||
#endif // !defined(ASIO_NO_DEPRECATED)
|
||||
|
||||
template <typename Protocol, typename SocketService,
|
||||
typename Iterator, typename IteratorConnectHandler>
|
||||
@ -732,6 +738,7 @@ async_connect(basic_socket<Protocol, SocketService>& s,
|
||||
return init.result.get();
|
||||
}
|
||||
|
||||
#if !defined(ASIO_NO_DEPRECATED)
|
||||
template <typename Protocol, typename SocketService, typename Iterator,
|
||||
typename ConnectCondition, typename IteratorConnectHandler>
|
||||
inline ASIO_INITFN_RESULT_TYPE(IteratorConnectHandler,
|
||||
@ -757,6 +764,7 @@ async_connect(basic_socket<Protocol, SocketService>& s,
|
||||
|
||||
return init.result.get();
|
||||
}
|
||||
#endif // !defined(ASIO_NO_DEPRECATED)
|
||||
|
||||
template <typename Protocol, typename SocketService, typename Iterator,
|
||||
typename ConnectCondition, typename IteratorConnectHandler>
|
||||
|
@ -54,11 +54,13 @@ public:
|
||||
/// The endpoint type.
|
||||
typedef typename InternetProtocol::endpoint endpoint_type;
|
||||
|
||||
#if !defined(ASIO_NO_DEPRECATED)
|
||||
/// (Deprecated.) The query type.
|
||||
typedef basic_resolver_query<InternetProtocol> query;
|
||||
|
||||
/// (Deprecated.) The iterator type.
|
||||
typedef basic_resolver_iterator<InternetProtocol> iterator;
|
||||
#endif // !defined(ASIO_NO_DEPRECATED)
|
||||
|
||||
/// The results type.
|
||||
typedef basic_resolver_results<InternetProtocol> results_type;
|
||||
@ -86,6 +88,7 @@ public:
|
||||
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.
|
||||
/**
|
||||
* 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);
|
||||
}
|
||||
#endif // !defined(ASIO_NO_DEPRECATED)
|
||||
|
||||
/// Perform forward resolution of a query to a list of entries.
|
||||
/**
|
||||
@ -242,7 +246,7 @@ public:
|
||||
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);
|
||||
results_type r = this->get_service().resolve(
|
||||
this->get_implementation(), q, ec);
|
||||
asio::detail::throw_error(ec, "resolve");
|
||||
@ -289,7 +293,7 @@ public:
|
||||
results_type resolve(const std::string& host, const std::string& service,
|
||||
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);
|
||||
}
|
||||
|
||||
@ -421,7 +425,8 @@ public:
|
||||
const std::string& service, resolver_base::flags resolve_flags)
|
||||
{
|
||||
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(
|
||||
this->get_implementation(), q, ec);
|
||||
asio::detail::throw_error(ec, "resolve");
|
||||
@ -472,10 +477,12 @@ public:
|
||||
const std::string& service, resolver_base::flags resolve_flags,
|
||||
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);
|
||||
}
|
||||
|
||||
#if !defined(ASIO_NO_DEPRECATED)
|
||||
/// (Deprecated.) Asynchronously perform forward resolution of a query to a
|
||||
/// list of entries.
|
||||
/**
|
||||
@ -513,6 +520,7 @@ public:
|
||||
return this->get_service().async_resolve(this->get_implementation(), q,
|
||||
ASIO_MOVE_CAST(ResolveHandler)(handler));
|
||||
}
|
||||
#endif // !defined(ASIO_NO_DEPRECATED)
|
||||
|
||||
/// Asynchronously perform forward resolution of a query to a list of entries.
|
||||
/**
|
||||
@ -624,7 +632,7 @@ public:
|
||||
ASIO_RESOLVE_HANDLER_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,
|
||||
ASIO_MOVE_CAST(ResolveHandler)(handler));
|
||||
}
|
||||
@ -745,7 +753,8 @@ public:
|
||||
ASIO_RESOLVE_HANDLER_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,
|
||||
ASIO_MOVE_CAST(ResolveHandler)(handler));
|
||||
}
|
||||
|
@ -48,7 +48,11 @@ namespace ip {
|
||||
*/
|
||||
template <typename InternetProtocol>
|
||||
class basic_resolver_results
|
||||
#if !defined(ASIO_NO_DEPRECATED)
|
||||
: public basic_resolver_iterator<InternetProtocol>
|
||||
#else // !defined(ASIO_NO_DEPRECATED)
|
||||
: private basic_resolver_iterator<InternetProtocol>
|
||||
#endif // !defined(ASIO_NO_DEPRECATED)
|
||||
{
|
||||
public:
|
||||
/// The protocol type associated with the results.
|
||||
|
@ -32,7 +32,7 @@ int main(int argc, char* argv[])
|
||||
udp::socket s(io_service, udp::endpoint(udp::v4(), 0));
|
||||
|
||||
udp::resolver resolver(io_service);
|
||||
udp::resolver::iterator iterator =
|
||||
udp::resolver::results_type endpoints =
|
||||
resolver.resolve(udp::v4(), argv[1], argv[2]);
|
||||
|
||||
using namespace std; // For strlen.
|
||||
@ -40,7 +40,7 @@ int main(int argc, char* argv[])
|
||||
char request[max_length];
|
||||
std::cin.getline(request, max_length);
|
||||
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];
|
||||
udp::endpoint sender_endpoint;
|
||||
|
@ -28,7 +28,7 @@ public:
|
||||
: resolver_(io_service), socket_(io_service, icmp::v4()),
|
||||
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_receive();
|
||||
|
@ -41,7 +41,7 @@ int main(int argc, char* argv[])
|
||||
|
||||
// Determine the location of the server.
|
||||
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.
|
||||
tcp::socket control_socket(io_service);
|
||||
|
@ -92,11 +92,12 @@ public:
|
||||
}
|
||||
|
||||
// Called by the user of the client class to initiate the connection process.
|
||||
// The endpoint iterator will have been obtained using a tcp::resolver.
|
||||
void start(tcp::resolver::iterator endpoint_iter)
|
||||
// The endpoints will have been obtained using a tcp::resolver.
|
||||
void start(tcp::resolver::results_type endpoints)
|
||||
{
|
||||
// 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
|
||||
// particular deadline here. Instead, the connect and input actors will
|
||||
@ -117,9 +118,9 @@ public:
|
||||
}
|
||||
|
||||
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";
|
||||
|
||||
@ -139,7 +140,7 @@ private:
|
||||
}
|
||||
|
||||
void handle_connect(const asio::error_code& ec,
|
||||
tcp::resolver::iterator endpoint_iter)
|
||||
tcp::resolver::results_type::iterator endpoint_iter)
|
||||
{
|
||||
if (stopped_)
|
||||
return;
|
||||
@ -273,6 +274,7 @@ private:
|
||||
|
||||
private:
|
||||
bool stopped_;
|
||||
tcp::resolver::results_type endpoints_;
|
||||
tcp::socket socket_;
|
||||
asio::streambuf input_buffer_;
|
||||
deadline_timer deadline_;
|
||||
|
@ -32,13 +32,14 @@ int main(int argc, char* argv[])
|
||||
udp::socket s(io_service, udp::endpoint(udp::v4(), 0));
|
||||
|
||||
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: ";
|
||||
char request[max_length];
|
||||
std::cin.getline(request, max_length);
|
||||
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];
|
||||
udp::endpoint sender_endpoint;
|
||||
|
@ -255,7 +255,7 @@ int main(int argc, char* argv[])
|
||||
|
||||
asio::ip::tcp::resolver r(ios);
|
||||
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);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user