Skip to content

Commit fdc7d28

Browse files
committed
Builds with std::* and Boost.Asio
Changes to use std:: version of some Boost libraries. Currently this builds with Boost.Asio even in C++11 mode. We'll use standalone Asio in C++11 mode another day.
1 parent b64608f commit fdc7d28

17 files changed

+273
-283
lines changed

include/network/protocol/http/client/client_connection.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
#include <functional>
1111
#include <boost/range/iterator_range.hpp>
12-
#include <asio/error_code.hpp>
12+
#include <boost/asio/error.hpp>
1313

1414
namespace network { namespace http {
1515

@@ -21,7 +21,7 @@ class request_options;
2121
struct client_connection {
2222
typedef std::function<
2323
void(boost::iterator_range<char const *> const &,
24-
asio::error_code const &)>
24+
boost::system::error_code const &)>
2525
callback_type;
2626
virtual response send_request(std::string const & method,
2727
request const & request,

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
#ifndef NETWORK_PROTOCOL_HTTP_CLIENT_CONNECTION_ASYNC_RESOLVER_20111126
88
#define NETWORK_PROTOCOL_HTTP_CLIENT_CONNECTION_ASYNC_RESOLVER_20111126
99

10-
#include <boost/shared_ptr.hpp>
10+
#include <memory>
1111
#include <network/protocol/http/client/connection/resolver_delegate.hpp>
1212

1313
namespace network {
@@ -18,7 +18,7 @@ struct async_resolver_pimpl;
1818
struct async_resolver : resolver_delegate {
1919
using resolver_delegate::resolve_completion_function;
2020

21-
async_resolver(asio::io_service & service, bool cache_resolved);
21+
async_resolver(boost::asio::io_service & service, bool cache_resolved);
2222
virtual void resolve(std::string const & host,
2323
uint16_t port,
2424
resolve_completion_function once_resolved); // override
@@ -28,7 +28,7 @@ struct async_resolver : resolver_delegate {
2828
protected:
2929
// We need a shared_ptr because the pimpl may live on long after the resolver
3030
// delegate (instances of this type) is actually destroyed.
31-
boost::shared_ptr<async_resolver_pimpl> pimpl;
31+
std::shared_ptr<async_resolver_pimpl> pimpl;
3232
};
3333

3434
} // namespace http

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

Lines changed: 99 additions & 101 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,13 @@
99

1010
#include <string>
1111
#include <utility>
12-
#include <asio/io_service.hpp>
13-
#include <asio/ip/udp.hpp>
14-
#include <asio/placeholders.hpp>
15-
#include <asio/strand.hpp>
12+
#include <memory>
13+
#include <unordered_map>
14+
#include <boost/asio/io_service.hpp>
15+
#include <boost/asio/ip/udp.hpp>
16+
#include <boost/asio/placeholders.hpp>
17+
#include <boost/asio/strand.hpp>
1618
#include <functional>
17-
#include <boost/enable_shared_from_this.hpp>
1819
#include <boost/lexical_cast.hpp>
1920
#include <boost/unordered_map.hpp>
2021
#include <boost/algorithm/string/case_conv.hpp>
@@ -24,114 +25,111 @@
2425
#include <network/protocol/http/client/connection/async_resolver.hpp>
2526

2627
namespace network { namespace http {
27-
struct async_resolver_pimpl : boost::enable_shared_from_this<async_resolver_pimpl> {
28-
typedef resolver_delegate::resolve_completion_function resolve_completion_function;
29-
async_resolver_pimpl(asio::io_service & service, bool cache_resolved);
30-
void resolve(std::string const & host,
31-
uint16_t port,
32-
resolve_completion_function once_resolved);
33-
void clear_resolved_cache();
34-
private:
35-
asio::ip::udp::resolver resolver_;
36-
bool cache_resolved_;
37-
typedef asio::ip::udp::resolver::iterator
38-
resolver_iterator;
39-
typedef boost::unordered_map<std::string, std::pair<resolver_iterator,resolver_iterator> >
40-
endpoint_cache;
41-
endpoint_cache endpoint_cache_;
42-
boost::scoped_ptr<asio::io_service::strand> resolver_strand_;
28+
struct async_resolver_pimpl : std::enable_shared_from_this<async_resolver_pimpl> {
29+
typedef resolver_delegate::resolve_completion_function resolve_completion_function;
30+
async_resolver_pimpl(boost::asio::io_service & service, bool cache_resolved);
31+
void resolve(std::string const & host,
32+
uint16_t port,
33+
resolve_completion_function once_resolved);
34+
void clear_resolved_cache();
35+
private:
36+
boost::asio::ip::udp::resolver resolver_;
37+
bool cache_resolved_;
38+
typedef boost::asio::ip::udp::resolver::iterator
39+
resolver_iterator;
40+
typedef std::unordered_map<std::string, std::pair<resolver_iterator,resolver_iterator> >
41+
endpoint_cache;
42+
endpoint_cache endpoint_cache_;
43+
std::unique_ptr<boost::asio::io_service::strand> resolver_strand_;
4344

44-
void handle_resolve(std::string const & host,
45-
resolve_completion_function once_resolved,
46-
asio::error_code const & ec,
47-
resolver_iterator endpoint_iterator);
48-
};
49-
50-
async_resolver_pimpl::async_resolver_pimpl(asio::io_service & service, bool cache_resolved)
45+
void handle_resolve(std::string const & host,
46+
resolve_completion_function once_resolved,
47+
boost::system::error_code const & ec,
48+
resolver_iterator endpoint_iterator);
49+
};
50+
51+
async_resolver_pimpl::async_resolver_pimpl(boost::asio::io_service & service, bool cache_resolved)
5152
: resolver_(service),
52-
cache_resolved_(cache_resolved),
53-
endpoint_cache_(),
54-
resolver_strand_(new(std::nothrow) asio::io_service::strand(service))
55-
{
56-
// Do nothing
57-
}
53+
cache_resolved_(cache_resolved),
54+
endpoint_cache_(),
55+
resolver_strand_(new(std::nothrow) boost::asio::io_service::strand(service))
56+
{
57+
// Do nothing
58+
}
5859

59-
void async_resolver_pimpl::clear_resolved_cache() {
60-
if (cache_resolved_)
61-
endpoint_cache().swap(endpoint_cache_);
62-
}
60+
void async_resolver_pimpl::clear_resolved_cache() {
61+
if (cache_resolved_)
62+
endpoint_cache().swap(endpoint_cache_);
63+
}
6364

64-
void async_resolver_pimpl::resolve(std::string const & host,
65-
boost::uint16_t port,
66-
resolve_completion_function once_resolved) {
67-
if (!resolver_strand_.get())
68-
BOOST_THROW_EXCEPTION(std::runtime_error(
69-
"Uninitialized resolver strand, ran out of memory."));
65+
void async_resolver_pimpl::resolve(std::string const & host,
66+
boost::uint16_t port,
67+
resolve_completion_function once_resolved) {
68+
if (!resolver_strand_.get())
69+
BOOST_THROW_EXCEPTION(std::runtime_error(
70+
"Uninitialized resolver strand, ran out of memory."));
7071

71-
if (cache_resolved_) {
72-
endpoint_cache::iterator iter =
73-
endpoint_cache_.find(boost::to_lower_copy(host));
74-
if (iter != endpoint_cache_.end()) {
75-
asio::error_code ignored;
76-
once_resolved(ignored, iter->second);
77-
return;
72+
if (cache_resolved_) {
73+
endpoint_cache::iterator iter =
74+
endpoint_cache_.find(boost::to_lower_copy(host));
75+
if (iter != endpoint_cache_.end()) {
76+
boost::system::error_code ignored;
77+
once_resolved(ignored, iter->second);
78+
return;
79+
}
7880
}
79-
}
8081

81-
std::string port_str = boost::lexical_cast<std::string>(port);
82-
asio::ip::udp::resolver::query query(host, port_str);
83-
using namespace std::placeholders;
84-
resolver_.async_resolve(
85-
query,
86-
resolver_strand_->wrap(
87-
std::bind(
88-
&async_resolver_pimpl::handle_resolve,
89-
async_resolver_pimpl::shared_from_this(),
90-
boost::to_lower_copy(host),
91-
once_resolved,
92-
_1,
93-
_2)));
94-
}
82+
std::string port_str = boost::lexical_cast<std::string>(port);
83+
boost::asio::ip::udp::resolver::query query(host, port_str);
84+
using namespace std::placeholders;
85+
resolver_.async_resolve(query,
86+
resolver_strand_->wrap(std::bind(&async_resolver_pimpl::handle_resolve,
87+
async_resolver_pimpl::shared_from_this(),
88+
boost::to_lower_copy(host),
89+
once_resolved,
90+
_1,
91+
_2)));
92+
}
9593

96-
void async_resolver_pimpl::handle_resolve(std::string const & host,
97-
resolve_completion_function once_resolved,
98-
asio::error_code const & ec,
99-
resolver_iterator endpoint_iterator) {
100-
endpoint_cache::iterator iter;
101-
bool inserted = false;
102-
if (!ec && cache_resolved_) {
103-
boost::fusion::tie(iter, inserted) =
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) {
98+
endpoint_cache::iterator iter;
99+
bool inserted = false;
100+
if (!ec && cache_resolved_) {
101+
boost::fusion::tie(iter, inserted) =
104102
endpoint_cache_.insert(
105-
std::make_pair(host,
106-
std::make_pair(endpoint_iterator,
107-
resolver_iterator())));
108-
once_resolved(ec, iter->second);
109-
} else {
110-
once_resolved(ec, std::make_pair(endpoint_iterator,resolver_iterator()));
103+
std::make_pair(host,
104+
std::make_pair(endpoint_iterator,
105+
resolver_iterator())));
106+
once_resolved(ec, iter->second);
107+
} else {
108+
once_resolved(ec, std::make_pair(endpoint_iterator,resolver_iterator()));
109+
}
111110
}
112-
}
113-
114-
async_resolver::async_resolver(asio::io_service & service, bool cache_resolved)
115-
: pimpl(new (std::nothrow) async_resolver_pimpl(service, cache_resolved))
116-
{}
117-
118-
void async_resolver::resolve(std::string const & host,
119-
uint16_t port,
120-
resolve_completion_function once_resolved) {
121-
BOOST_ASSERT(pimpl.get() && "Uninitialized pimpl, probably ran out of memory.");
122-
pimpl->resolve(host, port, once_resolved);
123-
}
124111

125-
void async_resolver::clear_resolved_cache() {
126-
BOOST_ASSERT(pimpl.get() && "Uninitialized pimpl, probably ran out of memory.");
127-
pimpl->clear_resolved_cache();
128-
}
129-
130-
async_resolver::~async_resolver() {
131-
// Do nothing
132-
}
112+
async_resolver::async_resolver(boost::asio::io_service & service, bool cache_resolved)
113+
: pimpl(new (std::nothrow) async_resolver_pimpl(service, cache_resolved))
114+
{}
133115

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+
134132
} // namespace http
135133
} // namespace network
136-
134+
137135
#endif /* NETWORK_PROTOCOL_HTTP_CLIENT_CONNECTION_ASYNC_RESOLVER_IPP_20111126 */

include/network/protocol/http/client/connection/connection_delegate.hpp

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,21 +7,21 @@
77
#ifndef NETWORK_PROTOCOL_HTTP_CLIENT_CONNECTION_CONNECTION_DELEGATE_HPP_
88
#define NETWORK_PROTOCOL_HTTP_CLIENT_CONNECTION_CONNECTION_DELEGATE_HPP_
99

10-
#include <asio/ip/tcp.hpp>
11-
#include <asio/streambuf.hpp>
10+
#include <boost/asio/ip/tcp.hpp>
11+
#include <boost/asio/streambuf.hpp>
1212
#include <functional>
1313

1414
namespace network {
1515
namespace http {
1616

1717
struct connection_delegate {
18-
virtual void connect(asio::ip::tcp::endpoint & endpoint,
18+
virtual void connect(boost::asio::ip::tcp::endpoint & endpoint,
1919
std::string const & host,
20-
std::function<void(asio::error_code const &)> handler) = 0;
21-
virtual void write(asio::streambuf & command_streambuf,
22-
std::function<void(asio::error_code const &, size_t)> handler) = 0;
23-
virtual void read_some(asio::mutable_buffers_1 const & read_buffer,
24-
std::function<void(asio::error_code const &, size_t)> handler) = 0;
20+
std::function<void(boost::system::error_code const &)> handler) = 0;
21+
virtual void write(boost::asio::streambuf & command_streambuf,
22+
std::function<void(boost::system::error_code const &, size_t)> handler) = 0;
23+
virtual void read_some(boost::asio::mutable_buffers_1 const & read_buffer,
24+
std::function<void(boost::system::error_code const &, size_t)> handler) = 0;
2525
virtual ~connection_delegate() {}
2626
};
2727

include/network/protocol/http/client/connection/connection_delegate_factory.hpp

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -7,33 +7,33 @@
77
#ifndef NETWORK_PROTOCOL_HTTP_CLIENT_CONNECTION_DELEGATE_FACTORY_HPP_20110819
88
#define NETWORK_PROTOCOL_HTTP_CLIENT_CONNECTION_DELEGATE_FACTORY_HPP_20110819
99

10+
#include <memory>
1011
#include <boost/throw_exception.hpp>
1112
#include <network/protocol/http/client/connection/connection_delegate.hpp>
1213

1314
namespace network {
14-
namespace http {
15+
namespace http {
1516

16-
class client_options;
17+
class client_options;
1718

18-
struct connection_delegate_factory {
19-
typedef boost::shared_ptr<connection_delegate> connection_delegate_ptr;
19+
struct connection_delegate_factory {
20+
typedef std::shared_ptr<connection_delegate> connection_delegate_ptr;
2021

21-
connection_delegate_factory();
22+
connection_delegate_factory();
2223

23-
// This is the factory method that actually returns the delegate instance.
24-
virtual connection_delegate_ptr create_connection_delegate(
25-
asio::io_service & service,
26-
bool https,
27-
client_options const &options);
24+
// This is the factory method that actually returns the delegate instance.
25+
virtual connection_delegate_ptr create_connection_delegate(boost::asio::io_service & service,
26+
bool https,
27+
client_options const &options);
2828

29-
virtual ~connection_delegate_factory();
29+
virtual ~connection_delegate_factory();
3030

31-
private:
32-
connection_delegate_factory(connection_delegate_factory const &); // = delete
33-
connection_delegate_factory& operator=(connection_delegate_factory); // = delete
34-
};
35-
36-
} // namespace http
31+
private:
32+
connection_delegate_factory(connection_delegate_factory const &); // = delete
33+
connection_delegate_factory& operator=(connection_delegate_factory); // = delete
34+
};
35+
36+
} // namespace http
3737
} // namespace network
3838

3939
#endif /* NETWORK_PROTOCOL_HTTP_CLIENT_CONNECTION_DELEGATE_FACTORY_HPP_20110819 */

0 commit comments

Comments
 (0)