9
9
// (See accompanying file LICENSE_1_0.txt or copy at
10
10
// http://www.boost.org/LICENSE_1_0.txt)
11
11
12
- #include < cstdint>
13
12
#include < boost/optional.hpp>
13
+ #include < cstdint>
14
14
15
15
// FIXME move this out to a trait
16
- #include < set>
17
16
#include < boost/network/detail/wrapper_base.hpp>
18
17
#include < boost/thread/future.hpp>
18
+ #include < set>
19
19
20
20
namespace boost {
21
21
namespace network {
@@ -26,12 +26,11 @@ namespace impl {
26
26
template <class Tag >
27
27
struct ready_wrapper ;
28
28
29
- } // namespace impl
30
- /* impl */
29
+ } // namespace impl
30
+ /* impl */
31
31
32
32
template <class Tag >
33
33
struct async_message {
34
-
35
34
typedef typename string<Tag>::type string_type;
36
35
typedef typename headers_container<Tag>::type headers_container_type;
37
36
typedef typename headers_container_type::value_type header_type;
@@ -54,63 +53,95 @@ struct async_message {
54
53
headers_(other.headers_),
55
54
body_(other.body_) {}
56
55
57
- string_type const status_message () const { return status_message_.get (); }
56
+ string_type status_message () const {
57
+ status_message_.wait ();
58
+ if (status_message_.has_exception ())
59
+ boost::rethrow_exception (status_message_.get_exception_ptr ());
60
+ return status_message_.get ();
61
+ }
58
62
59
63
void status_message (boost::shared_future<string_type> const & future) const {
60
64
status_message_ = future;
61
65
}
62
66
63
- string_type const version () const { return version_.get (); }
67
+ string_type version () const {
68
+ version_.wait ();
69
+ if (version_.has_exception ())
70
+ boost::rethrow_exception (version_.get_exception_ptr ());
71
+ return version_.get ();
72
+ }
64
73
65
74
void version (boost::shared_future<string_type> const & future) const {
66
75
version_ = future;
67
76
}
68
77
69
- std::uint16_t status () const { return status_.get (); }
78
+ std::uint16_t status () const {
79
+ status_.wait ();
80
+ if (status_.has_exception ())
81
+ boost::rethrow_exception (status_.get_exception_ptr ());
82
+ return status_.get ();
83
+ }
70
84
71
85
void status (boost::shared_future<uint16_t > const & future) const {
72
86
status_ = future;
73
87
}
74
88
75
- string_type const source () const { return source_.get (); }
89
+ string_type source () const {
90
+ source_.wait ();
91
+ if (source_.has_exception ())
92
+ boost::rethrow_exception (source_.get_exception_ptr ());
93
+ return source_.get ();
94
+ }
76
95
77
96
void source (boost::shared_future<string_type> const & future) const {
78
97
source_ = future;
79
98
}
80
99
81
- string_type const destination () const { return destination_.get (); }
100
+ string_type destination () const {
101
+ destination_.wait ();
102
+ if (destination_.has_exception ())
103
+ boost::rethrow_exception (source_.get_exception_ptr ());
104
+ return destination_.get ();
105
+ }
82
106
83
107
void destination (boost::shared_future<string_type> const & future) const {
84
108
destination_ = future;
85
109
}
86
110
87
111
headers_container_type const & headers () const {
88
112
if (retrieved_headers_) return *retrieved_headers_;
113
+ if (headers_.has_exception ())
114
+ boost::rethrow_exception (headers_.get_exception_ptr ());
89
115
headers_container_type raw_headers = headers_.get ();
90
116
raw_headers.insert (added_headers.begin (), added_headers.end ());
91
- for (string_type const & key : removed_headers) {
117
+ for (string_type const & key : removed_headers) {
92
118
raw_headers.erase (key);
93
119
}
94
120
retrieved_headers_ = raw_headers;
95
121
return *retrieved_headers_;
96
122
}
97
123
98
- void headers (boost::shared_future<headers_container_type> const & future)
99
- const {
124
+ void headers (
125
+ boost::shared_future<headers_container_type> const & future) const {
100
126
headers_ = future;
101
127
}
102
128
103
- void add_header (typename headers_container_type::value_type const & pair_)
104
- const {
129
+ void add_header (
130
+ typename headers_container_type::value_type const & pair_) const {
105
131
added_headers.insert (added_headers.end (), pair_);
106
132
}
107
133
108
- void remove_header (typename headers_container_type::key_type const & key_)
109
- const {
134
+ void remove_header (
135
+ typename headers_container_type::key_type const & key_) const {
110
136
removed_headers.insert (key_);
111
137
}
112
138
113
- string_type const body () const { return body_.get (); }
139
+ string_type body () const {
140
+ body_.wait ();
141
+ if (body_.has_exception ())
142
+ boost::rethrow_exception (body_.get_exception_ptr ());
143
+ return body_.get ();
144
+ }
114
145
115
146
void body (boost::shared_future<string_type> const & future) const {
116
147
body_ = future;
0 commit comments