Skip to content

Commit fab3b5f

Browse files
committed
Step two: implement the resolver delegate factory.
This moves out the policies into the client/connection/ directory and adds the necessary parts that deal with the creation of the async_resolver implementation. We now have wired the async_resolver to derive from a resolver_delegate type that the connections will use to resolve IP addresses of hosts.
1 parent bcdf43c commit fab3b5f

File tree

10 files changed

+142
-56
lines changed

10 files changed

+142
-56
lines changed

boost/network/protocol/http/client/connection/async_normal.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ struct http_async_connection
2323
: client_connection
2424
, enable_shared_from_this<http_async_connection> {
2525
using client_connection::callback_type;
26-
http_async_connection(shared_ptr<resolver_base> resolver_delegate,
26+
http_async_connection(shared_ptr<resolver_delegate> resolver_delegate,
2727
shared_ptr<connection_delegate> connection_delegate,
2828
asio::io_service & io_service,
2929
bool follow_redirects);
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
#ifndef BOOST_NETWORK_PROTOCOL_HTTP_CLIENT_CONNECTION_ASYNC_RESOLVER_20111126
2+
#define BOOST_NETWORK_PROTOCOL_HTTP_CLIENT_CONNECTION_ASYNC_RESOLVER_20111126
3+
4+
// Copyright 2011 Dean Michael Berris <dberris@google.com>.
5+
// Copyright 2011 Google, Inc.
6+
// Distributed under the Boost Software License, Version 1.0.
7+
// (See accompanying file LICENSE_1_0.txt or copy at
8+
// http://www.boost.org/LICENSE_1_0.txt)
9+
10+
#include <boost/shared_ptr.hpp>
11+
#include <boost/network/protocol/http/client/connection/resolver_delegate.hpp>
12+
13+
namespace boost { namespace network { namespace http {
14+
15+
struct async_resolver_pimpl;
16+
17+
struct async_resolver : resolver_delegate {
18+
using resolver_delegate::resolve_completion_function;
19+
20+
explicit async_resolver(asio::io_service & service);
21+
virtual void resolve(std::string const & host,
22+
uint16_t port,
23+
resolve_completion_function once_resolved); // override
24+
virtual void clear_resolved_cache(); // override
25+
virtual ~async_resolver();
26+
27+
protected:
28+
// We need a shared_ptr because the pimpl may live on long after the resolver
29+
// delegate (instances of this type) is actually destroyed.
30+
shared_ptr<async_resolver_pimpl> pimpl;
31+
};
32+
33+
} // namespace http
34+
35+
} // namespace network
36+
37+
} // namespace boost
38+
39+
#ifdef BOOST_NETWORK_NO_LIB
40+
#include <boost/network/protocol/http/policies/async_resolver.ipp>
41+
#endif
42+
43+
#endif // BOOST_NETWORK_PROTOCOL_HTTP_CLIENT_CONNECTION_ASYNC_RESOLVER_20111126

boost/network/protocol/http/policies/async_resolver.ipp renamed to boost/network/protocol/http/client/connection/async_resolver.ipp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
#ifndef BOOST_NETWORK_PROTOCOL_HTTP_POLICIES_ASYNC_RESOLVER_IPP_20110910
2-
#define BOOST_NETWORK_PROTOCOL_HTTP_POLICIES_ASYNC_RESOLVER_IPP_20110910
1+
#ifndef BOOST_NETWORK_PROTOCOL_HTTP_CLIENT_CONNECTION_ASYNC_RESOLVER_IPP_20110911
2+
#define BOOST_NETWORK_PROTOCOL_HTTP_CLIENT_CONNECTION_ASYNC_RESOLVER_IPP_20111126
33

44
// Copyright 2011 Dean Michael Berris <dberris@google.com>.
55
// Copyright 2011 Google, Inc.
@@ -39,6 +39,8 @@ async_resolver::~async_resolver() {
3939
// Do nothing
4040
}
4141

42+
// Define the actual implementation in a private implementation class.
43+
4244
struct async_resolver_pimpl : enable_shared_from_this<async_resolver_pimpl> {
4345
explicit async_resolver_pimpl(asio::io_service & service);
4446
void resolve(std::string const & host,
@@ -121,4 +123,4 @@ void handle_resolve(std::string const & host,
121123
} /* boost */
122124

123125

124-
#endif /* BOOST_NETWORK_PROTOCOL_HTTP_POLICIES_ASYNC_RESOLVER_IPP_20110910 */
126+
#endif /* BOOST_NETWORK_PROTOCOL_HTTP_CLIENT_CONNECTION_ASYNC_RESOLVER_IPP_20111126 */

boost/network/protocol/http/client/connection/resolver_delegate.hpp

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,22 @@
77
// (See accompanying file LICENSE_1_0.txt or copy at
88
// http://www.boost.org/LICENSE_1_0.txt)
99

10+
#include <utility>
11+
#include <boost/function.hpp>
12+
#include <boost/asio/ip/udp.hpp>
13+
1014
namespace boost { namespace network { namespace http {
1115

1216
struct resolver_delegate {
17+
typedef asio::ip::udp::resolver::iterator resolver_iterator;
18+
typedef std::pair<resolver_iterator, resolver_iterator>
19+
iterator_pair;
20+
typedef function<void(system::error_code const &, iterator_pair)>
21+
resolve_completion_function;
22+
virtual void resolve(std::string const & host,
23+
uint16_t port,
24+
resolve_completion_function once_resolved) = 0;
25+
virtual void clear_resolved_cache() = 0;
1326
virtual ~resolver_delegate() = 0;
1427
};
1528

@@ -19,4 +32,8 @@ struct resolver_delegate {
1932

2033
} /* boost */
2134

35+
#ifdef BOOST_NETWORK_NO_LIB
36+
#include <boost/network/protocol/http/client/connection/resolver_delegate.ipp>
37+
#endif
38+
2239
#endif /* BOOST_NETWORK_PROTOCOL_HTTP_CLIENT_CONNECTION_HPP_20111016 */
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
#ifndef BOOST_NETWORK_PROTOCOL_HTTP_CLIENT_CONNECTION_RESOLVER_DELEGATE_IPP_20111126
2+
#define BOOST_NETWORK_PROTOCOL_HTTP_CLIENT_CONNECTION_RESOLVER_DELEGATE_IPP_20111126
3+
4+
// Copyright 2011 Dean Michael Berris <dberris@google.com>.
5+
// Copyright 2011 Google, Inc.
6+
// Distributed under the Boost Software License, Version 1.0.
7+
// (See accompanying file LICENSE_1_0.txt or copy at
8+
// http://www.boost.org/LICENSE_1_0.txt)
9+
10+
#include <boost/network/protocol/http/client/connection/resolver_delegate_factory.hpp>
11+
#include <boost/network/protocol/http/client/connection/async_resolver.hpp>
12+
13+
namespace boost { namespace network { namespace http {
14+
15+
resolver_delegate::~resolver_delegate() {}
16+
17+
} // namespace http
18+
19+
} // namespace network
20+
21+
} // namespace boost
22+
23+
#endif // BOOST_NETWORK_PROTOCOL_HTTP_CLIENT_CONNECTION_RESOLVER_DELEGATE_IPP_20111126

boost/network/protocol/http/client/connection/resolver_delegate_factory.hpp

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,17 @@
88
// http://www.boost.org/LICENSE_1_0.txt)
99

1010
#include <boost/shared_ptr.hpp>
11+
#include <boost/network/protocol/http/request/request_base.hpp>
12+
#include <boost/network/protocol/http/client/connection/resolver_delegate.hpp>
1113

1214
namespace boost { namespace network { namespace http {
1315

14-
struct resolver_base;
15-
1616
struct resolver_delegate_factory {
1717
resolver_delegate_factory();
18-
virtual shared_ptr<resolver_base> create_resolver_delegate(
18+
virtual shared_ptr<resolver_delegate> create_resolver_delegate(
1919
asio::io_service & service,
2020
request_base const & request);
21+
virtual ~resolver_delegate_factory();
2122
private:
2223
resolver_delegate_factory(resolver_delegate_factory const &); // = delete
2324
resolver_delegate_factory& operator=(resolver_delegate_factory); // = delete
@@ -27,4 +28,8 @@ struct resolver_delegate_factory {
2728
} /* network */
2829
} /* boost */
2930

31+
#ifdef BOOST_NETWORK_NO_LIB
32+
#include <boost/network/protocol/http/client/connection/resolver_deleagte_factory.ipp>
33+
#endif
34+
3035
#endif /* BOOST_NETWORK_PROTOCOL_HTTP_CLIENT_CONNECTION_RESOLVER_DELEGATE_FACTORY_HPP_20110930 */
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
#ifndef BOOST_NETWORK_PROTOCOL_HTTP_CLIENT_CONNECTION_RESOLVER_DELEGATE_FACTORY_IPP_20111126
2+
#define BOOST_NETWORK_PROTOCOL_HTTP_CLIENT_CONNECTION_RESOLVER_DELEGATE_FACTORY_IPP_20111126
3+
4+
// Copyright 2011 Dean Michael Berris <dberris@google.com>.
5+
// Copyright 2011 Google, Inc.
6+
// Distributed under the Boost Software License, Version 1.0.
7+
// (See accompanying file LICENSE_1_0.txt or copy at
8+
// http://www.boost.org/LICENSE_1_0.txt)
9+
10+
#include <boost/network/protocol/http/client/connection/resolver_delegate_factory.hpp>
11+
#include <boost/network/protocol/http/client/connection/async_resolver.hpp>
12+
13+
namespace boost { namespace network { namespace http {
14+
15+
resolver_delegate_factory::resolver_delegate_factory() {}
16+
17+
shared_ptr<resolver_delegate>
18+
resolver_delegate_factory::create_resolver_delegate(asio::io_service & service,
19+
request_base const & request) {
20+
shared_ptr<resolver_delegate> resolver_(new (std::nothrow) async_resolver(service));
21+
return resolver_;
22+
}
23+
24+
resolver_delegate_factory::~resolver_delegate_factory() {}
25+
26+
} // namespace http
27+
28+
} // namespace network
29+
30+
} // namespace boost
31+
32+
#endif // BOOST_NETWORK_PROTOCOL_HTTP_CLIENT_CONNECTION_RESOLVER_DELEGATE_FACTORY_IPP_20111126

boost/network/protocol/http/policies/async_resolver.hpp

Lines changed: 0 additions & 48 deletions
This file was deleted.

libs/network/src/CMakeLists.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,8 @@ set(CPP-NETLIB_HTTP_CLIENT_CONNECTIONS_SRCS
3232
http/client_connections.cpp
3333
http/simple_connection_manager.cpp
3434
http/simple_connection_factory.cpp
35-
http/connection_delegate_factory.cpp)
35+
http/connection_delegate_factory.cpp
36+
http/client_resolver_delegate_factory.cpp)
3637
add_library(cppnetlib-http-client-connections ${CPP-NETLIB_HTTP_CLIENT_CONNECTIONS_SRCS})
3738

3839
set(CPP-NETLIB_HTTP_CLIENT_SRCS
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
// Copyright 2011 Dean Michael Berris <dberris@google.com>.
2+
// Copyright 2011 Google, Inc.
3+
// Distributed under the Boost Software License, Version 1.0.
4+
// (See accompanying file LICENSE_1_0.txt or copy at
5+
// http://www.boost.org/LICENSE_1_0.txt)
6+
7+
#ifdef BOOST_NETWORK_NO_LIB
8+
#undef BOOST_NETWORK_NO_LIB
9+
#endif
10+
11+
#include <boost/network/protocol/http/client/connection/resolver_delegate_factory.ipp>

0 commit comments

Comments
 (0)