@@ -15,45 +15,38 @@ namespace boost { namespace network { namespace http {
1515
1616struct response_pimpl {
1717response_pimpl () {}
18+
1819 response_pimpl *clone () {
19- response_pimpl * new_pimpl =new (std::nothrow) response_pimpl;
20- new_pimpl->source_future_ = source_future_;
21- new_pimpl->destination_future_ = destination_future_;
22- new_pimpl->headers_future_ = headers_future_;
23- new_pimpl->status_future_ = status_future_;
24- new_pimpl->status_message_future_ = status_message_future_;
25- new_pimpl->version_future_ = version_future_;
26- new_pimpl->body_future_ = body_future_;
27- return new_pimpl;
20+ return new (std::nothrow)response_pimpl (*this );
2821 }
2922
3023void set_destination (std::stringconst &destination) {
3124 promise<std::string> destination_promise;
25+ destination_promise.set_value (destination);
3226 unique_future<std::string> tmp_future = destination_promise.get_future ();
3327 destination_future_ =move (tmp_future);
34- destination_promise.set_value (destination);
3528 }
3629
3730void get_destination (std::string &destination) {
38- if (! destination_future_) {
31+ if (destination_future_. get_state () == future_state::uninitialized ) {
3932 destination =" " ;
4033 }else {
41- destination = destination_future_-> get ();
34+ destination = destination_future_. get ();
4235 }
4336 }
4437
4538void set_source (std::stringconst &source) {
4639 promise<std::string> source_promise;
40+ source_promise.set_value (source);
4741 unique_future<std::string> tmp_future = source_promise.get_future ();
4842 source_future_ =move (tmp_future);
49- source_promise.set_value (source);
5043 }
5144
5245void get_source (std::string &source) {
53- if (! source_future_) {
46+ if (source_future_. get_state () == future_state::uninitialized ) {
5447 source =" " ;
5548 }else {
56- source = source_future_-> get ();
49+ source = source_future_. get ();
5750 }
5851 }
5952
@@ -81,18 +74,18 @@ struct response_pimpl {
8174
8275void set_body (std::stringconst &body) {
8376 promise<std::string> body_promise;
77+ body_promise.set_value (body);
8478 unique_future<std::string> tmp_future = body_promise.get_future ();
8579 body_future_ =move (tmp_future);
86- body_promise.set_value (body);
8780 }
8881
8982void append_body (std::stringconst & data) {/* FIXME: Do something!*/ }
9083
9184void get_body (std::string &body) {
92- if (! body_future_) {
85+ if (body_future_. get_state () == future_state::uninitialized ) {
9386 body =" " ;
9487 }else {
95- body = body_future_-> get ();
88+ body = body_future_. get ();
9689 }
9790 }
9891
@@ -102,46 +95,46 @@ struct response_pimpl {
10295
10396void set_status (boost::uint16_t status) {
10497 promise<boost::uint16_t > status_promise;
98+ status_promise.set_value (status);
10599 unique_future<boost::uint16_t > tmp_future = status_promise.get_future ();
106100 status_future_ =move (tmp_future);
107- status_promise.set_value (status);
108101 }
109102
110103void get_status (boost::uint16_t &status) {
111- if (! status_future_) {
104+ if (status_future_. get_state () == future_state::uninitialized ) {
112105 status =0u ;
113106 }else {
114- status = status_future_-> get ();
107+ status = status_future_. get ();
115108 }
116109 }
117110
118111void set_status_message (std::stringconst &status_message) {
119112 promise<std::string> status_message_promise_;
113+ status_message_promise_.set_value (status_message);
120114 unique_future<std::string> tmp_future = status_message_promise_.get_future ();
121115 status_message_future_ =move (tmp_future);
122- status_message_promise_.set_value (status_message);
123116 }
124117
125118void get_status_message (std::string &status_message) {
126- if (! status_message_future_) {
119+ if (status_message_future_. get_state () == future_state::uninitialized ) {
127120 status_message =" " ;
128121 }else {
129- status_message = status_message_future_-> get ();
122+ status_message = status_message_future_. get ();
130123 }
131124 }
132125
133126void set_version (std::stringconst &version) {
134127 promise<std::string> version_promise;
128+ version_promise.set_value (version);
135129 unique_future<std::string> tmp_future = version_promise.get_future ();
136130 version_future_ =move (tmp_future);
137- version_promise.set_value (version);
138131 }
139132
140133void get_version (std::string &version) {
141- if (! version_future_) {
134+ if (version_future_. get_state () == future_state::uninitialized ) {
142135 version =" " ;
143136 }else {
144- version = version_future_-> get ();
137+ version = version_future_. get ();
145138 }
146139 }
147140
@@ -180,15 +173,92 @@ struct response_pimpl {
180173 body_future_ =move (tmp_future);
181174 }
182175
176+ bool equals (response_pimplconst &other) {
177+ if (source_future_.get_state () != future_state::uninitialized) {
178+ if (other.source_future_ .get_state () == future_state::uninitialized)
179+ return false ;
180+ if (source_future_.get () != other.source_future_ .get ())
181+ return false ;
182+ }else {
183+ if (other.source_future_ .get_state () != future_state::uninitialized)
184+ return false ;
185+ }
186+ if (destination_future_.get_state () != future_state::uninitialized) {
187+ if (other.destination_future_ .get_state () == future_state::uninitialized)
188+ return false ;
189+ if (destination_future_.get () != other.destination_future_ .get ())
190+ return false ;
191+ }else {
192+ if (other.destination_future_ .get_state () != future_state::uninitialized)
193+ return false ;
194+ }
195+ if (headers_future_.get_state () != future_state::uninitialized) {
196+ if (other.headers_future_ .get_state () == future_state::uninitialized)
197+ return false ;
198+ if (headers_future_.get () != other.headers_future_ .get ())
199+ return false ;
200+ }else {
201+ if (other.headers_future_ .get_state () != future_state::uninitialized)
202+ return false ;
203+ }
204+ if (status_future_.get_state () != future_state::uninitialized) {
205+ if (other.status_future_ .get_state () == future_state::uninitialized)
206+ return false ;
207+ if (status_future_.get () != other.status_future_ .get ())
208+ return false ;
209+ }else {
210+ if (other.status_future_ .get_state () != future_state::uninitialized)
211+ return false ;
212+ }
213+ if (status_message_future_.get_state () != future_state::uninitialized) {
214+ if (other.status_message_future_ .get_state () == future_state::uninitialized)
215+ return false ;
216+ if (status_message_future_.get () != other.status_message_future_ .get ())
217+ return false ;
218+ }else {
219+ if (other.status_message_future_ .get_state () != future_state::uninitialized)
220+ return false ;
221+ }
222+ if (version_future_.get_state () != future_state::uninitialized) {
223+ if (other.version_future_ .get_state () == future_state::uninitialized)
224+ return false ;
225+ if (version_future_.get () != other.version_future_ .get ())
226+ return false ;
227+ }else {
228+ if (other.version_future_ .get_state () != future_state::uninitialized)
229+ return false ;
230+ }
231+ if (body_future_.get_state () != future_state::uninitialized) {
232+ if (other.body_future_ .get_state () == future_state::uninitialized)
233+ return false ;
234+ if (body_future_.get () != other.body_future_ .get ())
235+ return false ;
236+ }else {
237+ if (other.body_future_ .get_state () != future_state::uninitialized)
238+ return false ;
239+ }
240+ return true ;
241+ }
242+
183243private:
184- optional< shared_future<std::string> > source_future_;
185- optional< shared_future<std::string> > destination_future_;
186- optional< shared_future<std::multimap<std::string, std::string> > >
244+ mutable shared_future<std::string> source_future_;
245+ mutable shared_future<std::string> destination_future_;
246+ mutable shared_future<std::multimap<std::string, std::string> >
187247 headers_future_;
188- optional<shared_future<boost::uint16_t > > status_future_;
189- optional<shared_future<std::string> > status_message_future_;
190- optional<shared_future<std::string> > version_future_;
191- optional<shared_future<std::string> > body_future_;
248+ mutable shared_future<boost::uint16_t > status_future_;
249+ mutable shared_future<std::string> status_message_future_;
250+ mutable shared_future<std::string> version_future_;
251+ mutable shared_future<std::string> body_future_;
252+
253+ response_pimpl (response_pimplconst &other)
254+ : source_future_(other.source_future_)
255+ , destination_future_(other.destination_future_)
256+ , headers_future_(other.headers_future_)
257+ , status_future_(other.status_future_)
258+ , status_message_future_(other.status_message_future_)
259+ , version_future_(other.version_future_)
260+ , body_future_(other.body_future_)
261+ {}
192262};
193263
194264response::response ()
@@ -205,7 +275,11 @@ response& response::operator=(response rhs) {
205275}
206276
207277void response::swap (response &other) {
208- other.pimpl_ .swap (pimpl_);
278+ std::swap (this ->pimpl_ , other.pimpl_ );
279+ }
280+
281+ bool response::equals (responseconst &other)const {
282+ return other.pimpl_ ->equals (*pimpl_);
209283}
210284
211285void response::set_destination (std::stringconst &destination) {
@@ -291,7 +365,9 @@ void response::get_version(std::string &version) const {
291365 pimpl_->get_version (version);
292366}
293367
294- response::~response () {}
368+ response::~response () {
369+ delete pimpl_;
370+ }
295371
296372void response::set_version_promise (promise<std::string> &promise) {
297373return pimpl_->set_version_promise (promise);