Skip to content

Commit b78f68a

Browse files
committed
WIP: Using stand-alone Asio with C++11
Removing dependency on Boost.Asio and using the standalone Asio version.
1 parent e8bc018 commit b78f68a

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

70 files changed

+758
-768
lines changed

CMakeLists.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,11 @@ if (${CMAKE_CXX_COMPILER_ID} MATCHES GNU)
4040
elseif(${CMAKE_CXX_COMPILER_ID} MATCHES Clang)
4141
set(CMAKE_CXX_FLAGS "-std=c++11 -stdlib=libc++")
4242
set(CMAKE_CXX_LINK_FLAGS "-std=c++11 -stdlib=libc++")
43+
add_definitions(
44+
-DASIO_HAS_MOVE -DASIO_HAS_VARIADIC_TEMPLATES -DASIO_HAS_STD_SYSTEM_ERROR
45+
-DASIO_ERROR_CATEGORY_NOEXCEPT=noexcept -DASIO_HAS_STD_ARRAY
46+
-DASIO_HAS_STD_SHARED_PTR -DASIO_HAS_STD_ATOMIC -DASIO_HAS_STD_CHRONO
47+
-DASIO_HAS_STD_ADDRESSOFF -DASIO_HAS_STD_FUNCTION -DASIO_HAS_STD_TYPE_TRAITS)
4348
message("C++ Flags: ${CMAKE_CXX_FLAGS} link flags: ${CMAKE_CXX_LINK_FLAGS}")
4449
endif()
4550

include/network/include/http/server.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
#ifndef NETWORK_INCLUDE_HTTP_SERVER_HPP_
1010
#define NETWORK_INCLUDE_HTTP_SERVER_HPP_
1111

12-
#include <boost/asio/io_service.hpp>
12+
#include <asio/io_service.hpp>
1313
#include <network/protocol/http/server.hpp>
1414
#include <network/utils/thread_pool.hpp>
1515
#include <network/detail/debug.hpp>

include/network/message/directives/detail/string_value.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
#include <network/traits/string.hpp>
1111
#include <network/support/is_async.hpp>
1212
#include <network/support/is_sync.hpp>
13-
#include <boost/thread/future.hpp>
13+
#include <future>
1414
#include <boost/type_traits/is_same.hpp>
1515
#include <boost/mpl/if.hpp>
1616
#include <boost/mpl/or.hpp>

include/network/message/message.hpp

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

1010
#include <string>
1111
#include <map>
12-
#include <boost/function.hpp>
12+
#include <functional>
1313
#include <network/message/message_base.hpp>
1414
#include <boost/shared_container_iterator.hpp>
1515

@@ -45,16 +45,16 @@ struct message : message_base {
4545
virtual void get_destination(std::string & destination) const;
4646
virtual void get_source(std::string & source) const;
4747
virtual void get_headers(
48-
boost::function<void(std::string const &, std::string const &)> inserter) const;
48+
std::function<void(std::string const &, std::string const &)> inserter) const;
4949
virtual void get_headers(
5050
std::string const & name,
51-
boost::function<void(std::string const &, std::string const &)> inserter) const;
51+
std::function<void(std::string const &, std::string const &)> inserter) const;
5252
virtual void get_headers(
53-
boost::function<bool(std::string const &, std::string const &)> predicate,
54-
boost::function<void(std::string const &, std::string const &)> inserter) const;
53+
std::function<bool(std::string const &, std::string const &)> predicate,
54+
std::function<void(std::string const &, std::string const &)> inserter) const;
5555
virtual void get_body(std::string & body) const;
5656
virtual void get_body(
57-
boost::function<void(boost::iterator_range<char const *>)> chunk_reader,
57+
std::function<void(boost::iterator_range<char const *>)> chunk_reader,
5858
size_t size) const;
5959

6060
void swap(message & other);

include/network/message/message.ipp

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -61,14 +61,14 @@ struct message_pimpl {
6161
source = source_;
6262
}
6363

64-
void get_headers(boost::function<void(std::string const &, std::string const &)> inserter) const {
64+
void get_headers(std::function<void(std::string const &, std::string const &)> inserter) const {
6565
std::multimap<std::string, std::string>::const_iterator it = headers_.begin(),
6666
end = headers_.end();
6767
for (; it != end; ++it) inserter(it->first, it->second);
6868
}
6969

7070
void get_headers(std::string const & name,
71-
boost::function<void(std::string const &, std::string const &)> inserter) const {
71+
std::function<void(std::string const &, std::string const &)> inserter) const {
7272
std::multimap<std::string, std::string>::const_iterator it = headers_.find(name),
7373
end= headers_.end();
7474
while (it != end) {
@@ -77,8 +77,8 @@ struct message_pimpl {
7777
}
7878
}
7979

80-
void get_headers(boost::function<bool(std::string const &, std::string const &)> predicate,
81-
boost::function<void(std::string const &, std::string const &)> inserter) const {
80+
void get_headers(std::function<bool(std::string const &, std::string const &)> predicate,
81+
std::function<void(std::string const &, std::string const &)> inserter) const {
8282
std::multimap<std::string, std::string>::const_iterator it = headers_.begin(),
8383
end = headers_.end();
8484
while (it != end) {
@@ -92,7 +92,7 @@ struct message_pimpl {
9292
body = body_;
9393
}
9494

95-
void get_body(boost::function<void(boost::iterator_range<char const *>)> chunk_reader, size_t size) const {
95+
void get_body(std::function<void(boost::iterator_range<char const *>)> chunk_reader, size_t size) const {
9696
static char const * nullptr_ = 0;
9797
if (body_read_pos == body_.size())
9898
chunk_reader(boost::make_iterator_range(nullptr_, nullptr_));
@@ -179,25 +179,25 @@ void message::get_source(std::string & source) const {
179179
pimpl->get_source(source);
180180
}
181181

182-
void message::get_headers(boost::function<void(std::string const &, std::string const &)> inserter) const {
182+
void message::get_headers(std::function<void(std::string const &, std::string const &)> inserter) const {
183183
pimpl->get_headers(inserter);
184184
}
185185

186186
void message::get_headers(std::string const & name,
187-
boost::function<void(std::string const &, std::string const &)> inserter) const {
187+
std::function<void(std::string const &, std::string const &)> inserter) const {
188188
pimpl->get_headers(name, inserter);
189189
}
190190

191-
void message::get_headers(boost::function<bool(std::string const &, std::string const &)> predicate,
192-
boost::function<void(std::string const &, std::string const &)> inserter) const {
191+
void message::get_headers(std::function<bool(std::string const &, std::string const &)> predicate,
192+
std::function<void(std::string const &, std::string const &)> inserter) const {
193193
pimpl->get_headers(predicate, inserter);
194194
}
195195

196196
void message::get_body(std::string & body) const {
197197
pimpl->get_body(body);
198198
}
199199

200-
void message::get_body(boost::function<void(boost::iterator_range<char const *>)> chunk_reader, size_t size) const {
200+
void message::get_body(std::function<void(boost::iterator_range<char const *>)> chunk_reader, size_t size) const {
201201
pimpl->get_body(chunk_reader, size);
202202
}
203203

include/network/message/message_base.hpp

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

10-
#include <boost/function.hpp>
10+
#include <functional>
1111
#include <boost/range/iterator_range.hpp>
1212

1313
namespace network {
@@ -26,11 +26,11 @@ struct message_base {
2626
// Retrievers
2727
virtual void get_destination(std::string & destination) const = 0;
2828
virtual void get_source(std::string & source) const = 0;
29-
virtual void get_headers(boost::function<void(std::string const &, std::string const &)> inserter) const = 0;
30-
virtual void get_headers(std::string const & name, boost::function<void(std::string const &, std::string const &)> inserter) const = 0;
31-
virtual void get_headers(boost::function<bool(std::string const &, std::string const &)> predicate, boost::function<void(std::string const &, std::string const &)> inserter) const = 0;
29+
virtual void get_headers(std::function<void(std::string const &, std::string const &)> inserter) const = 0;
30+
virtual void get_headers(std::string const & name, std::function<void(std::string const &, std::string const &)> inserter) const = 0;
31+
virtual void get_headers(std::function<bool(std::string const &, std::string const &)> predicate, std::function<void(std::string const &, std::string const &)> inserter) const = 0;
3232
virtual void get_body(std::string & body) const = 0;
33-
virtual void get_body(boost::function<void(boost::iterator_range<char const *>)> chunk_reader, size_t size) const = 0;
33+
virtual void get_body(std::function<void(boost::iterator_range<char const *>)> chunk_reader, size_t size) const = 0;
3434

3535
// Destructor
3636
virtual ~message_base() = 0; // pure virtual

include/network/message/wrappers/headers.ipp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
#include <network/message/wrappers/headers.hpp>
1111
#include <network/message/message_base.hpp>
12-
#include <boost/function.hpp>
12+
#include <functional>
1313

1414
namespace network {
1515

include/network/protocol/http/client.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
#include <network/version.hpp>
1111
#include <network/protocol/http/client/options.hpp>
1212

13-
#include <boost/asio/io_service.hpp>
13+
#include <asio/io_service.hpp>
1414
#include <network/protocol/http/client/facade.hpp>
1515
#include <network/protocol/http/client/macros.hpp>
1616
#include <network/protocol/http/request.hpp>

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

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,9 @@
77
#ifndef NETWORK_PROTOCOL_HTTP_CLIENT_BASE_HPP_20111008
88
#define NETWORK_PROTOCOL_HTTP_CLIENT_BASE_HPP_20111008
99

10-
#include <boost/function.hpp>
10+
#include <functional>
1111
#include <boost/range/iterator_range.hpp>
1212

13-
namespace boost { namespace asio {
14-
class io_service;
15-
} // namespace asio
16-
} // namespace boost
17-
1813
namespace network {
1914
namespace http {
2015

@@ -28,7 +23,7 @@ class client_options;
2823

2924
struct client_base {
3025
typedef
31-
boost::function<void(boost::iterator_range<char const *> const &, boost::system::error_code const &)>
26+
std::function<void(boost::iterator_range<char const *> const &, asio::error_code const &)>
3227
body_callback_function_type;
3328

3429
client_base();

include/network/protocol/http/client/base.ipp

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

10+
#include <thread>
11+
#include <functional>
1012
#include <network/protocol/http/client/base.hpp>
1113
#include <network/protocol/http/client/options.hpp>
12-
#include <boost/asio/io_service.hpp>
13-
#include <boost/asio/strand.hpp>
14-
#include <boost/thread/thread.hpp>
15-
#include <boost/bind.hpp>
14+
#include <asio/io_service.hpp>
15+
#include <asio/strand.hpp>
1616
#include <network/protocol/http/client/connection_manager.hpp>
1717
#include <network/protocol/http/client/simple_connection_manager.hpp>
1818
#include <network/protocol/http/request.hpp>
@@ -22,7 +22,7 @@ namespace network { namespace http {
2222

2323
struct client_base_pimpl {
2424
typedef
25-
boost::function<void(boost::iterator_range<char const *> const &, boost::system::error_code const &)>
25+
std::function<void(boost::iterator_range<char const *> const &, asio::error_code const &)>
2626
body_callback_function_type;
2727
client_base_pimpl(client_options const &options);
2828
response const request_skeleton(request const & request_,
@@ -34,9 +34,9 @@ struct client_base_pimpl {
3434
~client_base_pimpl();
3535
private:
3636
client_options options_;
37-
boost::asio::io_service * service_ptr;
38-
boost::shared_ptr<boost::asio::io_service::work> sentinel_;
39-
boost::shared_ptr<boost::thread> lifetime_thread_;
37+
asio::io_service * service_ptr;
38+
boost::shared_ptr<asio::io_service::work> sentinel_;
39+
boost::shared_ptr<std::thread> lifetime_thread_;
4040
boost::shared_ptr<connection_manager> connection_manager_;
4141
bool owned_service_;
4242
};
@@ -78,20 +78,17 @@ client_base_pimpl::client_base_pimpl(client_options const &options)
7878
NETWORK_MESSAGE("client_base_pimpl::client_base_pimpl(client_options const &)");
7979
if (service_ptr == 0) {
8080
NETWORK_MESSAGE("creating owned io_service.");
81-
service_ptr = new(std::nothrow) boost::asio::io_service;
81+
service_ptr = new(std::nothrow) asio::io_service;
8282
owned_service_ = true;
8383
}
8484
if (!connection_manager_.get()) {
8585
NETWORK_MESSAGE("creating owned simple_connection_manager");
8686
connection_manager_.reset(
8787
new (std::nothrow) simple_connection_manager(options));
8888
}
89-
sentinel_.reset(new (std::nothrow) boost::asio::io_service::work(*service_ptr));
90-
lifetime_thread_.reset(new (std::nothrow) boost::thread(
91-
boost::bind(
92-
&boost::asio::io_service::run,
93-
service_ptr
94-
)));
89+
sentinel_.reset(new (std::nothrow) asio::io_service::work(*service_ptr));
90+
auto local_ptr = service_ptr;
91+
lifetime_thread_.reset(new (std::nothrow) std::thread([local_ptr]() { local_ptr->run(); }));
9592
if (!lifetime_thread_.get())
9693
BOOST_THROW_EXCEPTION(std::runtime_error("Cannot allocate client lifetime thread; not enough memory."));
9794
}

0 commit comments

Comments
 (0)