Skip to content

Commit 9ad624a

Browse files
committed
Getting the ducks in a neat row...
First, we get the asynchronous resolver delegate into a cpp file that gets built and linked into the cppnetlib-client-connections lib. We then write it up in the connection factory and resolver delegate factory implementation so that we can create instances of these properly. Then lastly we have the default implementation of the pure virtual destructors for the pure interface types we use.
1 parent fab3b5f commit 9ad624a

12 files changed

+127
-38
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ struct async_resolver_pimpl;
1717
struct async_resolver : resolver_delegate {
1818
using resolver_delegate::resolve_completion_function;
1919

20-
explicit async_resolver(asio::io_service & service);
20+
async_resolver(asio::io_service & service, bool cache_resolved);
2121
virtual void resolve(std::string const & host,
2222
uint16_t port,
2323
resolve_completion_function once_resolved); // override

boost/network/protocol/http/client/connection/async_resolver.ipp

Lines changed: 45 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -16,33 +16,16 @@
1616
#include <boost/bind.hpp>
1717
#include <boost/enable_shared_from_this.hpp>
1818
#include <boost/lexical_cast.hpp>
19+
#include <boost/unordered_map.hpp>
20+
#include <boost/algorithm/string/case_conv.hpp>
21+
#include <boost/fusion/tuple.hpp>
22+
#include <boost/fusion/adapted/std_pair.hpp>
23+
#include <boost/network/protocol/http/client/connection/async_resolver.hpp>
1924

2025
namespace boost { namespace network { namespace http {
21-
22-
async_resolver::async_resolver(asio::io_service & service)
23-
: pimpl(new (std::nothrow) async_resolver_pimpl(service))
24-
{}
25-
26-
void async_resolver::resolve(std::string const & host,
27-
uint16_t port,
28-
resolve_completion_function once_resolved) {
29-
BOOST_ASSERT(pimpl.get() && "Uninitialized pimpl, probably ran out of memory.");
30-
pimpl->resolve(host, port, once_resolved);
31-
}
32-
33-
void async_resolver::clear_resolved_cache() {
34-
BOOST_ASSERT(pimpl.get() && "Uninitialized pimpl, probably ran out of memory.");
35-
pimpl->clear_resolved_cache();
36-
}
37-
38-
async_resolver::~async_resolver() {
39-
// Do nothing
40-
}
41-
42-
// Define the actual implementation in a private implementation class.
43-
4426
struct async_resolver_pimpl : enable_shared_from_this<async_resolver_pimpl> {
45-
explicit async_resolver_pimpl(asio::io_service & service);
27+
typedef resolver_delegate::resolve_completion_function resolve_completion_function;
28+
async_resolver_pimpl(asio::io_service & service, bool cache_resolved);
4629
void resolve(std::string const & host,
4730
uint16_t port,
4831
resolve_completion_function once_resolved);
@@ -56,20 +39,30 @@ struct async_resolver_pimpl : enable_shared_from_this<async_resolver_pimpl> {
5639
endpoint_cache;
5740
endpoint_cache endpoint_cache_;
5841
scoped_ptr<asio::io_service::strand> resolver_strand_;
42+
43+
void handle_resolve(std::string const & host,
44+
resolve_completion_function once_resolved,
45+
system::error_code const & ec,
46+
resolver_iterator endpoint_iterator);
5947
};
6048

61-
async_resolver_pimpl::async_resolver_pimpl(asio::io_service & service)
49+
async_resolver_pimpl::async_resolver_pimpl(asio::io_service & service, bool cache_resolved)
6250
: resolver_(service),
63-
cache_resolved(cache_resolved),
51+
cache_resolved_(cache_resolved),
6452
endpoint_cache_(),
6553
resolver_strand_(new(std::nothrow) asio::io_service::strand(service))
6654
{
6755
// Do nothing
6856
}
6957

58+
void async_resolver_pimpl::clear_resolved_cache() {
59+
if (cache_resolved_)
60+
endpoint_cache().swap(endpoint_cache_);
61+
}
62+
7063
void async_resolver_pimpl::resolve(std::string const & host,
71-
boost::uint16_t port,
72-
resolve_completion_function once_resolved) {
64+
boost::uint16_t port,
65+
resolve_completion_function once_resolved) {
7366
if (!resolver_strand_.get())
7467
BOOST_THROW_EXCEPTION(std::runtime_error(
7568
"Uninitialized resolver strand, ran out of memory."));
@@ -98,10 +91,10 @@ void async_resolver_pimpl::resolve(std::string const & host,
9891
boost::asio::placeholders::iterator)));
9992
}
10093

101-
void handle_resolve(std::string const & host,
102-
resolve_completion_function once_resolved,
103-
boost::system::error_code const & ec,
104-
resolver_iterator endpoint_iterator) {
94+
void async_resolver_pimpl::handle_resolve(std::string const & host,
95+
resolve_completion_function once_resolved,
96+
boost::system::error_code const & ec,
97+
resolver_iterator endpoint_iterator) {
10598
endpoint_cache::iterator iter;
10699
bool inserted = false;
107100
if (!ec && cache_resolved_) {
@@ -116,6 +109,26 @@ void handle_resolve(std::string const & host,
116109
}
117110
}
118111

112+
async_resolver::async_resolver(asio::io_service & service, bool cache_resolved)
113+
: pimpl(new (std::nothrow) async_resolver_pimpl(service, cache_resolved))
114+
{}
115+
116+
void async_resolver::resolve(std::string const & host,
117+
uint16_t port,
118+
resolve_completion_function once_resolved) {
119+
BOOST_ASSERT(pimpl.get() && "Uninitialized pimpl, probably ran out of memory.");
120+
pimpl->resolve(host, port, once_resolved);
121+
}
122+
123+
void async_resolver::clear_resolved_cache() {
124+
BOOST_ASSERT(pimpl.get() && "Uninitialized pimpl, probably ran out of memory.");
125+
pimpl->clear_resolved_cache();
126+
}
127+
128+
async_resolver::~async_resolver() {
129+
// Do nothing
130+
}
131+
119132
} /* http */
120133

121134
} /* network */

boost/network/protocol/http/client/connection/connection_delegate_factory.ipp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@ connection_delegate_factory::create_connection_delegate(
3939
return delegate;
4040
}
4141

42+
connection_delegate_factory::~connection_delegate_factory() {}
43+
4244
} /* http */
4345

4446
} /* network */
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
#ifndef BOOST_NETWORK_PROTOCOL_HTTP_CLIENT_CONNECTION_CONNECTION_FACTORY_IPP_20111126
2+
#define BOOST_NETWORK_PROTOCOL_HTTP_CLIENT_CONNECTION_CONNECTION_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/connection_factory.hpp>
11+
12+
namespace boost { namespace network { namespace http {
13+
14+
connection_factory::~connection_factory() {}
15+
16+
} // namespace http
17+
18+
} // namespace network
19+
20+
} // namespace boost
21+
22+
#endif // BOOST_NETWORK_PROTOCOL_HTTP_CLIENT_CONNECTION_CONNECTION_FACTORY_IPP_20111126

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ struct resolver_delegate_factory {
1717
resolver_delegate_factory();
1818
virtual shared_ptr<resolver_delegate> create_resolver_delegate(
1919
asio::io_service & service,
20-
request_base const & request);
20+
bool cache_resolved);
2121
virtual ~resolver_delegate_factory();
2222
private:
2323
resolver_delegate_factory(resolver_delegate_factory const &); // = delete

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,9 @@ resolver_delegate_factory::resolver_delegate_factory() {}
1616

1717
shared_ptr<resolver_delegate>
1818
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));
19+
bool cache_resolved) {
20+
shared_ptr<resolver_delegate> resolver_(
21+
new (std::nothrow) async_resolver(service, cache_resolved));
2122
return resolver_;
2223
}
2324

boost/network/protocol/http/client/connection/simple_connection_factory.ipp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ struct simple_connection_factory_pimpl {
3232
bool https = to_lower_copy(scheme(uri_)) == "https";
3333
shared_ptr<client_connection> conn_;
3434
conn_.reset(new (std::nothrow) http_async_connection(
35-
res_delegate_factory_->create_resolver_delegate(service, request),
35+
res_delegate_factory_->create_resolver_delegate(service, cache_resolved),
3636
conn_delegate_factory_->create_connection_delegate(
3737
service, https, openssl_certificate, openssl_verify_path),
3838
service,

libs/network/src/CMakeLists.txt

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,11 @@ set(CPP-NETLIB_HTTP_CLIENT_CONNECTIONS_SRCS
3333
http/simple_connection_manager.cpp
3434
http/simple_connection_factory.cpp
3535
http/connection_delegate_factory.cpp
36-
http/client_resolver_delegate_factory.cpp)
36+
http/client_resolver_delegate.cpp
37+
http/client_resolver_delegate_factory.cpp
38+
http/client_connection_delegates.cpp
39+
http/client_connection_factory.cpp
40+
http/client_async_resolver.cpp)
3741
add_library(cppnetlib-http-client-connections ${CPP-NETLIB_HTTP_CLIENT_CONNECTIONS_SRCS})
3842

3943
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/async_resolver.ipp>
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
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/normal_delegate.ipp>
12+
#ifdef BOOST_NETWORK_ENABLE_HTTPS
13+
#include <boost/network/protocol/http/client/connection/ssl_delegate.ipp>
14+
#endif

0 commit comments

Comments
 (0)