Skip to content

Commit 663277e

Browse files
committed
replace std::promise/std::shared_future with boost equivalents
boost::shared_future has a richer api, notably it has the `is_ready()` method required by the `ready()` wrapper
1 parent 5237c2f commit 663277e

File tree

13 files changed

+52
-50
lines changed

13 files changed

+52
-50
lines changed

CMakeLists.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ add_definitions(-DBOOST_TEST_DYN_LINK)
4545
# Always use multi-threaded Boost libraries.
4646
set(Boost_USE_MULTI_THREADED ON)
4747

48-
find_package(Boost 1.58.0 REQUIRED COMPONENTS system)
48+
find_package(Boost 1.58.0 REQUIRED COMPONENTS system thread)
4949

5050
if (CPP-NETLIB_ENABLE_HTTPS)
5151
if (APPLE)

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@
66
// (See accompanying file LICENSE_1_0.txt or copy at
77
// http://www.boost.org/LICENSE_1_0.txt)
88

9-
#include <future>
109
#include <boost/network/traits/string.hpp>
1110
#include <boost/network/support/is_async.hpp>
1211
#include <boost/network/support/is_sync.hpp>
12+
#include <boost/thread/future.hpp>
1313
#include <boost/type_traits/is_same.hpp>
1414
#include <boost/mpl/if.hpp>
1515
#include <boost/mpl/or.hpp>
@@ -20,7 +20,7 @@ namespace detail {
2020

2121
template <class Tag>
2222
struct string_value
23-
: mpl::if_<is_async<Tag>, std::shared_future<typename string<Tag>::type>,
23+
: mpl::if_<is_async<Tag>, boost::shared_future<typename string<Tag>::type>,
2424
typename mpl::if_<
2525
mpl::or_<is_sync<Tag>, is_same<Tag, tags::default_string>,
2626
is_same<Tag, tags::default_wstring> >,

boost/network/message/modifiers/clear_headers.hpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,11 @@
66
// (See accompanying file LICENSE_1_0.txt or copy at
77
// http://www.boost.org/LICENSE_1_0.txt)
88

9-
#include <future>
109
#include <boost/mpl/and.hpp>
1110
#include <boost/mpl/not.hpp>
1211
#include <boost/network/support/is_async.hpp>
1312
#include <boost/network/support/is_pod.hpp>
13+
#include <boost/thread/future.hpp>
1414
#include <boost/utility/enable_if.hpp>
1515

1616
namespace boost {
@@ -34,8 +34,8 @@ template <class Message, class Tag>
3434
inline typename enable_if<mpl::and_<mpl::not_<is_pod<Tag> >, is_async<Tag> >,
3535
void>::type
3636
clear_headers(Message const &message, Tag const &) {
37-
std::promise<typename Message::headers_container_type> header_promise;
38-
std::shared_future<typename Message::headers_container_type> headers_future(
37+
boost::promise<typename Message::headers_container_type> header_promise;
38+
boost::shared_future<typename Message::headers_container_type> headers_future(
3939
header_promise.get_future());
4040
message.headers(headers_future);
4141
header_promise.set_value(typename Message::headers_container_type());

boost/network/message/traits/body.hpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,12 @@
88
// (See accompanying file LICENSE_1_0.txt or copy at
99
// http://www.boost.org/LICENSE_1_0.txt)
1010

11-
#include <future>
1211
#include <boost/mpl/if.hpp>
1312
#include <boost/network/support/is_async.hpp>
1413
#include <boost/network/support/is_sync.hpp>
1514
#include <boost/network/tags.hpp>
1615
#include <boost/network/traits/string.hpp>
16+
#include <boost/thread/future.hpp>
1717
#include <boost/type_traits/is_same.hpp>
1818

1919
namespace boost {
@@ -27,7 +27,7 @@ template <class Message>
2727
struct body
2828
: mpl::if_<
2929
is_async<typename Message::tag>,
30-
std::shared_future<typename string<typename Message::tag>::type>,
30+
boost::shared_future<typename string<typename Message::tag>::type>,
3131
typename mpl::if_<
3232
mpl::or_<is_sync<typename Message::tag>,
3333
is_same<typename Message::tag,

boost/network/message/traits/destination.hpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,12 @@
77
// (See accompanying file LICENSE_1_0.txt or copy at
88
// http://www.boost.org/LICENSE_1_0.txt)
99

10-
#include <future>
1110
#include <boost/mpl/if.hpp>
1211
#include <boost/network/support/is_async.hpp>
1312
#include <boost/network/support/is_sync.hpp>
1413
#include <boost/network/tags.hpp>
1514
#include <boost/network/traits/string.hpp>
15+
#include <boost/thread/future.hpp>
1616
#include <boost/type_traits/is_same.hpp>
1717

1818
namespace boost {
@@ -26,7 +26,7 @@ struct unsupported_tag;
2626
template <class Message>
2727
struct destination
2828
: mpl::if_<is_async<typename Message::tag>,
29-
std::shared_future<typename string<typename Message::tag>::type>,
29+
boost::shared_future<typename string<typename Message::tag>::type>,
3030
typename mpl::if_<
3131
mpl::or_<is_sync<typename Message::tag>,
3232
is_same<typename Message::tag,

boost/network/message/traits/headers.hpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,14 @@
77
// (See accompanying file LICENSE_1_0.txt or copy at
88
// http://www.boost.org/LICENSE_1_0.txt)
99

10-
#include <future>
1110
#include <boost/mpl/if.hpp>
1211
#include <boost/mpl/or.hpp>
1312
#include <boost/network/message/directives.hpp>
1413
#include <boost/network/message/transformers.hpp>
1514
#include <boost/network/message/wrappers.hpp>
1615
#include <boost/network/support/is_async.hpp>
1716
#include <boost/network/support/is_sync.hpp>
17+
#include <boost/thread/future.hpp>
1818

1919
namespace boost {
2020
namespace network {
@@ -28,7 +28,7 @@ template <class Message>
2828
struct header_key
2929
: mpl::if_<
3030
is_async<typename Message::tag>,
31-
std::shared_future<typename string<typename Message::tag>::type>,
31+
boost::shared_future<typename string<typename Message::tag>::type>,
3232
typename mpl::if_<
3333
mpl::or_<is_sync<typename Message::tag>,
3434
is_same<typename Message::tag, tags::default_string>,
@@ -40,7 +40,7 @@ template <class Message>
4040
struct header_value
4141
: mpl::if_<
4242
is_async<typename Message::tag>,
43-
std::shared_future<typename string<typename Message::tag>::type>,
43+
boost::shared_future<typename string<typename Message::tag>::type>,
4444
typename mpl::if_<
4545
mpl::or_<is_sync<typename Message::tag>,
4646
is_same<typename Message::tag, tags::default_string>,

boost/network/message/traits/source.hpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,12 @@
66
// (See accompanying file LICENSE_1_0.txt or copy at
77
// http://www.boost.org/LICENSE_1_0.txt)
88

9-
#include <future>
109
#include <boost/mpl/if.hpp>
1110
#include <boost/network/support/is_async.hpp>
1211
#include <boost/network/support/is_sync.hpp>
1312
#include <boost/network/tags.hpp>
1413
#include <boost/network/traits/string.hpp>
14+
#include <boost/thread/future.hpp>
1515
#include <boost/type_traits/is_same.hpp>
1616

1717
namespace boost {
@@ -24,7 +24,7 @@ struct unsupported_tag;
2424
template <class Message>
2525
struct source
2626
: mpl::if_<is_async<typename Message::tag>,
27-
std::shared_future<typename string<typename Message::tag>::type>,
27+
boost::shared_future<typename string<typename Message::tag>::type>,
2828
typename mpl::if_<
2929
mpl::or_<is_sync<typename Message::tag>,
3030
is_same<typename Message::tag,

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

+15-14
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
#include <boost/network/protocol/http/parser/incremental.hpp>
1818
#include <boost/network/protocol/http/request_parser.hpp>
1919
#include <boost/network/traits/string.hpp>
20+
#include <boost/thread/future.hpp>
2021

2122
namespace boost {
2223
namespace network {
@@ -57,30 +58,30 @@ struct http_async_protocol_handler {
5758
// TODO(dberris): review parameter necessity.
5859
(void)get_body;
5960

60-
std::shared_future<string_type> source_future(
61+
boost::shared_future<string_type> source_future(
6162
source_promise.get_future());
6263
source(response_, source_future);
6364

64-
std::shared_future<string_type> destination_future(
65+
boost::shared_future<string_type> destination_future(
6566
destination_promise.get_future());
6667
destination(response_, destination_future);
6768

68-
std::shared_future<typename headers_container<Tag>::type> headers_future(
69+
boost::shared_future<typename headers_container<Tag>::type> headers_future(
6970
headers_promise.get_future());
7071
headers(response_, headers_future);
7172

72-
std::shared_future<string_type> body_future(body_promise.get_future());
73+
boost::shared_future<string_type> body_future(body_promise.get_future());
7374
body(response_, body_future);
7475

75-
std::shared_future<string_type> version_future(
76+
boost::shared_future<string_type> version_future(
7677
version_promise.get_future());
7778
version(response_, version_future);
7879

79-
std::shared_future<std::uint16_t> status_future(
80+
boost::shared_future<std::uint16_t> status_future(
8081
status_promise.get_future());
8182
status(response_, status_future);
8283

83-
std::shared_future<string_type> status_message_future(
84+
boost::shared_future<string_type> status_message_future(
8485
status_message_promise.get_future());
8586
status_message(response_, status_message_future);
8687
}
@@ -339,13 +340,13 @@ struct http_async_protocol_handler {
339340
typedef std::array<typename char_<Tag>::type, 1024> buffer_type;
340341

341342
response_parser_type response_parser_;
342-
std::promise<string_type> version_promise;
343-
std::promise<std::uint16_t> status_promise;
344-
std::promise<string_type> status_message_promise;
345-
std::promise<typename headers_container<Tag>::type> headers_promise;
346-
std::promise<string_type> source_promise;
347-
std::promise<string_type> destination_promise;
348-
std::promise<string_type> body_promise;
343+
boost::promise<string_type> version_promise;
344+
boost::promise<std::uint16_t> status_promise;
345+
boost::promise<string_type> status_message_promise;
346+
boost::promise<typename headers_container<Tag>::type> headers_promise;
347+
boost::promise<string_type> source_promise;
348+
boost::promise<string_type> destination_promise;
349+
boost::promise<string_type> body_promise;
349350
buffer_type part;
350351
typename buffer_type::const_iterator part_begin;
351352
string_type partial_parsed;

boost/network/protocol/http/message/async_message.hpp

+12-12
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,13 @@
99
// (See accompanying file LICENSE_1_0.txt or copy at
1010
// http://www.boost.org/LICENSE_1_0.txt)
1111

12-
#include <future>
1312
#include <cstdint>
1413
#include <boost/optional.hpp>
1514

1615
// FIXME move this out to a trait
1716
#include <set>
1817
#include <boost/network/detail/wrapper_base.hpp>
18+
#include <boost/thread/future.hpp>
1919

2020
namespace boost {
2121
namespace network {
@@ -56,31 +56,31 @@ struct async_message {
5656

5757
string_type const status_message() const { return status_message_.get(); }
5858

59-
void status_message(std::shared_future<string_type> const& future) const {
59+
void status_message(boost::shared_future<string_type> const& future) const {
6060
status_message_ = future;
6161
}
6262

6363
string_type const version() const { return version_.get(); }
6464

65-
void version(std::shared_future<string_type> const& future) const {
65+
void version(boost::shared_future<string_type> const& future) const {
6666
version_ = future;
6767
}
6868

6969
std::uint16_t status() const { return status_.get(); }
7070

71-
void status(std::shared_future<uint16_t> const& future) const {
71+
void status(boost::shared_future<uint16_t> const& future) const {
7272
status_ = future;
7373
}
7474

7575
string_type const source() const { return source_.get(); }
7676

77-
void source(std::shared_future<string_type> const& future) const {
77+
void source(boost::shared_future<string_type> const& future) const {
7878
source_ = future;
7979
}
8080

8181
string_type const destination() const { return destination_.get(); }
8282

83-
void destination(std::shared_future<string_type> const& future) const {
83+
void destination(boost::shared_future<string_type> const& future) const {
8484
destination_ = future;
8585
}
8686

@@ -95,7 +95,7 @@ struct async_message {
9595
return *retrieved_headers_;
9696
}
9797

98-
void headers(std::shared_future<headers_container_type> const& future)
98+
void headers(boost::shared_future<headers_container_type> const& future)
9999
const {
100100
headers_ = future;
101101
}
@@ -112,7 +112,7 @@ struct async_message {
112112

113113
string_type const body() const { return body_.get(); }
114114

115-
void body(std::shared_future<string_type> const& future) const {
115+
void body(boost::shared_future<string_type> const& future) const {
116116
body_ = future;
117117
}
118118

@@ -132,13 +132,13 @@ struct async_message {
132132
}
133133

134134
private:
135-
mutable std::shared_future<string_type> status_message_, version_, source_,
135+
mutable boost::shared_future<string_type> status_message_, version_, source_,
136136
destination_;
137-
mutable std::shared_future<std::uint16_t> status_;
138-
mutable std::shared_future<headers_container_type> headers_;
137+
mutable boost::shared_future<std::uint16_t> status_;
138+
mutable boost::shared_future<headers_container_type> headers_;
139139
mutable headers_container_type added_headers;
140140
mutable std::set<string_type> removed_headers;
141-
mutable std::shared_future<string_type> body_;
141+
mutable boost::shared_future<string_type> body_;
142142
mutable boost::optional<headers_container_type> retrieved_headers_;
143143

144144
friend struct boost::network::http::impl::ready_wrapper<Tag>;

boost/network/protocol/http/message/directives/status.hpp

+4-4
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,11 @@
77
// (See accompanying file LICENSE_1_0.txt or copy at
88
// http://www.boost.org/LICENSE_1_0.txt)
99

10-
#include <future>
1110
#include <cstdint>
1211
#include <boost/mpl/if.hpp>
1312
#include <boost/network/support/is_async.hpp>
1413
#include <boost/network/tags.hpp>
14+
#include <boost/thread/future.hpp>
1515
#include <boost/variant/apply_visitor.hpp>
1616
#include <boost/variant/static_visitor.hpp>
1717
#include <boost/variant/variant.hpp>
@@ -25,18 +25,18 @@ struct basic_response;
2525

2626
struct status_directive {
2727

28-
boost::variant<std::uint16_t, std::shared_future<std::uint16_t> >
28+
boost::variant<std::uint16_t, boost::shared_future<std::uint16_t> >
2929
status_;
3030

3131
explicit status_directive(std::uint16_t status) : status_(status) {}
3232

33-
explicit status_directive(std::shared_future<std::uint16_t> const &status)
33+
explicit status_directive(boost::shared_future<std::uint16_t> const &status)
3434
: status_(status) {}
3535

3636
status_directive(status_directive const &other) : status_(other.status_) {}
3737

3838
template <class Tag>
39-
struct value : mpl::if_<is_async<Tag>, std::shared_future<std::uint16_t>,
39+
struct value : mpl::if_<is_async<Tag>, boost::shared_future<std::uint16_t>,
4040
std::uint16_t> {};
4141

4242
template <class Tag>

boost/network/protocol/http/message/traits/status.hpp

+2-1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
#include <cstdint>
1010
#include <boost/network/support/is_async.hpp>
1111
#include <boost/network/tags.hpp>
12+
#include <boost/thread/future.hpp>
1213

1314
namespace boost {
1415
namespace network {
@@ -23,7 +24,7 @@ template <class Message>
2324
struct status
2425
: mpl::if_<
2526
is_async<typename Message::tag>,
26-
std::shared_future<std::uint16_t>,
27+
boost::shared_future<std::uint16_t>,
2728
typename mpl::if_<is_sync<typename Message::tag>, std::uint16_t,
2829
unsupported_tag<typename Message::tag> >::type> {};
2930

boost/network/protocol/http/message/traits/status_message.hpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,11 @@
66
// (See accompanying file LICENSE_1_0.txt or copy at
77
// http://www.boost.org/LICENSE_1_0.txt)
88

9-
#include <future>
109
#include <boost/mpl/if.hpp>
1110
#include <boost/network/support/is_async.hpp>
1211
#include <boost/network/tags.hpp>
1312
#include <boost/network/traits/string.hpp>
13+
#include <boost/thread/future.hpp>
1414

1515
namespace boost {
1616
namespace network {
@@ -25,7 +25,7 @@ template <class Message>
2525
struct status_message
2626
: mpl::if_<
2727
is_async<typename Message::tag>,
28-
std::shared_future<typename string<typename Message::tag>::type>,
28+
boost::shared_future<typename string<typename Message::tag>::type>,
2929
typename mpl::if_<
3030
mpl::or_<is_sync<typename Message::tag>,
3131
is_same<typename Message::tag, boost::network::tags::default_string>,

0 commit comments

Comments
 (0)