Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit4ea2034

Browse files
committed
Partial implementation of http::response.
After chasing down invalid memory access errors that shouldn't be thereI've made sure that we're turning on -Wall and -Werror for most (if notall) the code in cpp-netlib built with CMAKE. If there's an easier wayto do this, it should be done. My CMake-foo is not strong enough to makeit happen except by doing copy-paste.In other news this is the beginnings of the http::response type that'ssupporting value semantics. There's still a number of stubbed outfunctions regarding headers, which hopefully once implemented will allowfor moving forward to actually starting to debug the clientimplementation.
1 parent8ae025d commit4ea2034

File tree

8 files changed

+244
-66
lines changed

8 files changed

+244
-66
lines changed

‎boost/network/protocol/http/request/request.ipp‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,7 @@ request::request(request const &other)
146146

147147
request& request::operator=(request rhs) {
148148
rhs.swap(*this);
149+
return *this;
149150
}
150151

151152
boolrequest::equals(requestconst &other)const {

‎boost/network/protocol/http/request/request_base.ipp‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ size_t request_storage_base_pimpl::read(char *destination, size_t offset, size_t
139139
// or we're
140140
size_t chunks_count = chunks_.size();
141141
size_t read_count =0;
142-
while (size >0 && chunk_index <chunks_.size()) {
142+
while (size >0 && chunk_index <chunks_count) {
143143
size_t bytes_to_read =std::min(chunks_[chunk_index].second, size);
144144
std::memcpy(destination + read_count,
145145
chunks_[chunk_index].first + offset,

‎boost/network/protocol/http/response/response.hpp‎

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ struct response : response_base {
1919
response(responseconst &);
2020
response&operator=(response);
2121
voidswap(response &);
22+
boolequals(responseconst &)const;
2223

2324
// From message_base...
2425
// Mutators
@@ -68,13 +69,21 @@ struct response : response_base {
6869
voidset_destination_promise(promise<std::string>&);
6970
voidset_body_promise(promise<std::string>&);
7071

71-
scoped_ptr<response_pimpl>pimpl_;
72+
response_pimpl *pimpl_;
7273
};
7374

7475
inlinevoidswap(response &l, response &r) {
7576
l.swap(r);
7677
}
7778

79+
inlinebooloperator==(responseconst &l, responseconst &r) {
80+
return l.equals(r);
81+
}
82+
83+
inlinebooloperator!=(responseconst &l, responseconst &r) {
84+
return !l.equals(r);
85+
}
86+
7887
template<classDirective>
7988
response &operator<<(
8089
response & message,

‎boost/network/protocol/http/response/response.ipp‎

Lines changed: 112 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -15,45 +15,38 @@ namespace boost { namespace network { namespace http {
1515

1616
structresponse_pimpl {
1717
response_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+
returnnew (std::nothrow)response_pimpl(*this);
2821
}
2922

3023
voidset_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

3730
voidget_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

4538
voidset_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

5245
voidget_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

8275
voidset_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

8982
voidappend_body(std::stringconst & data) {/* FIXME: Do something!*/ }
9083

9184
voidget_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

10396
voidset_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

110103
voidget_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

118111
voidset_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

125118
voidget_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

133126
voidset_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

140133
voidget_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+
boolequals(response_pimplconst &other) {
177+
if (source_future_.get_state() != future_state::uninitialized) {
178+
if (other.source_future_.get_state() == future_state::uninitialized)
179+
returnfalse;
180+
if (source_future_.get() != other.source_future_.get())
181+
returnfalse;
182+
}else {
183+
if (other.source_future_.get_state() != future_state::uninitialized)
184+
returnfalse;
185+
}
186+
if (destination_future_.get_state() != future_state::uninitialized) {
187+
if (other.destination_future_.get_state() == future_state::uninitialized)
188+
returnfalse;
189+
if (destination_future_.get() != other.destination_future_.get())
190+
returnfalse;
191+
}else {
192+
if (other.destination_future_.get_state() != future_state::uninitialized)
193+
returnfalse;
194+
}
195+
if (headers_future_.get_state() != future_state::uninitialized) {
196+
if (other.headers_future_.get_state() == future_state::uninitialized)
197+
returnfalse;
198+
if (headers_future_.get() != other.headers_future_.get())
199+
returnfalse;
200+
}else {
201+
if (other.headers_future_.get_state() != future_state::uninitialized)
202+
returnfalse;
203+
}
204+
if (status_future_.get_state() != future_state::uninitialized) {
205+
if (other.status_future_.get_state() == future_state::uninitialized)
206+
returnfalse;
207+
if (status_future_.get() != other.status_future_.get())
208+
returnfalse;
209+
}else {
210+
if (other.status_future_.get_state() != future_state::uninitialized)
211+
returnfalse;
212+
}
213+
if (status_message_future_.get_state() != future_state::uninitialized) {
214+
if (other.status_message_future_.get_state() == future_state::uninitialized)
215+
returnfalse;
216+
if (status_message_future_.get() != other.status_message_future_.get())
217+
returnfalse;
218+
}else {
219+
if (other.status_message_future_.get_state() != future_state::uninitialized)
220+
returnfalse;
221+
}
222+
if (version_future_.get_state() != future_state::uninitialized) {
223+
if (other.version_future_.get_state() == future_state::uninitialized)
224+
returnfalse;
225+
if (version_future_.get() != other.version_future_.get())
226+
returnfalse;
227+
}else {
228+
if (other.version_future_.get_state() != future_state::uninitialized)
229+
returnfalse;
230+
}
231+
if (body_future_.get_state() != future_state::uninitialized) {
232+
if (other.body_future_.get_state() == future_state::uninitialized)
233+
returnfalse;
234+
if (body_future_.get() != other.body_future_.get())
235+
returnfalse;
236+
}else {
237+
if (other.body_future_.get_state() != future_state::uninitialized)
238+
returnfalse;
239+
}
240+
returntrue;
241+
}
242+
183243
private:
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+
mutableshared_future<std::string> source_future_;
245+
mutableshared_future<std::string> destination_future_;
246+
mutableshared_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

194264
response::response()
@@ -205,7 +275,11 @@ response& response::operator=(response rhs) {
205275
}
206276

207277
voidresponse::swap(response &other) {
208-
other.pimpl_.swap(pimpl_);
278+
std::swap(this->pimpl_, other.pimpl_);
279+
}
280+
281+
boolresponse::equals(responseconst &other)const {
282+
return other.pimpl_->equals(*pimpl_);
209283
}
210284

211285
voidresponse::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

296372
voidresponse::set_version_promise(promise<std::string> &promise) {
297373
return pimpl_->set_version_promise(promise);

‎libs/network/example/CMakeLists.txt‎

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,6 @@ if (UNIX)
1919
add_executable(fileserver http/fileserver.cpp)
2020
endif (UNIX)
2121
add_executable(uri uri.cpp)
22-
add_dependencies(http_client cppnetlib-uri cppnetlib-client-connections)
23-
add_dependencies(simple_wget cppnetlib-uri cppnetlib-client-connections)
24-
add_dependencies(atom_reader cppnetlib-uri cppnetlib-client-connections)
25-
add_dependencies(rss_reader cppnetlib-uri cppnetlib-client-connections)
26-
add_dependencies(twitter_search cppnetlib-uri cppnetlib-client-connections)
27-
add_dependencies(uri cppnetlib-uri)
2822
set(BOOST_CLIENT_LIBS
2923
${Boost_PROGRAM_OPTIONS_LIBRARY}
3024
${Boost_THREAD_LIBRARY}
@@ -42,31 +36,37 @@ target_link_libraries(http_client
4236
${BOOST_CLIENT_LIBS}
4337
${CMAKE_THREAD_LIBS_INIT}
4438
cppnetlib-uri
45-
cppnetlib-client-connections)
39+
cppnetlib-http-client-connections)
4640

4741
target_link_libraries(simple_wget
4842
${BOOST_CLIENT_LIBS}
4943
${CMAKE_THREAD_LIBS_INIT}
5044
cppnetlib-uri
51-
cppnetlib-client-connections)
45+
cppnetlib-http-client-connections)
5246

5347
target_link_libraries(atom_reader
5448
${BOOST_CLIENT_LIBS}
5549
${CMAKE_THREAD_LIBS_INIT}
5650
cppnetlib-uri
57-
cppnetlib-client-connections)
51+
cppnetlib-message
52+
cppnetlib-message-directives
53+
cppnetlib-message-wrappers
54+
cppnetlib-http-message
55+
cppnetlib-constants
56+
cppnetlib-http-client
57+
cppnetlib-http-client-connections)
5858

5959
target_link_libraries(rss_reader
6060
${BOOST_CLIENT_LIBS}
6161
${CMAKE_THREAD_LIBS_INIT}
6262
cppnetlib-uri
63-
cppnetlib-client-connections)
63+
cppnetlib-http-client-connections)
6464

6565
target_link_libraries(twitter_search
6666
${BOOST_CLIENT_LIBS}
6767
${CMAKE_THREAD_LIBS_INIT}
6868
cppnetlib-uri
69-
cppnetlib-client-connections)
69+
cppnetlib-http-client-connections)
7070

7171
target_link_libraries(hello_world_server
7272
${BOOST_SERVER_LIBS}
@@ -76,7 +76,7 @@ target_link_libraries(hello_world_client
7676
${BOOST_CLIENT_LIBS}
7777
${CMAKE_THREAD_LIBS_INIT}
7878
cppnetlib-uri
79-
cppnetlib-client-connections)
79+
cppnetlib-http-client-connections)
8080

8181
if (OPENSSL_FOUND)
8282
target_link_libraries(http_client${OPENSSL_LIBRARIES})

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp