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

Commitb741b4f

Browse files
committed
Addressing short read bugs, general cleanup.
1 parent2047a63 commitb741b4f

File tree

16 files changed

+400
-246
lines changed

16 files changed

+400
-246
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ namespace boost { namespace network { namespace http {
6666
BOOST_PARAMETER_CONSTRUCTOR(
6767
basic_client, (base_facade_type), tag,
6868
(optional
69-
(in_out(io_service), (boost::asio::io_service))
69+
(in_out(io_service), (boost::asio::io_service&))
7070
(follow_redirects, (bool))
7171
(cache_resolved, (bool))
7272
(openssl_certificate, (string_type))

‎boost/network/protocol/http/client/async_impl.hpp‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ namespace boost { namespace network { namespace http {
1818

1919
namespaceimpl {
2020
template<classTag,unsigned version_major,unsigned version_minor>
21-
structasync_client :
21+
structasync_client :
2222
connection_policy<Tag,version_major,version_minor>::type
2323
{
2424
typedef
@@ -31,7 +31,7 @@ namespace boost { namespace network { namespace http {
3131
typename string<Tag>::type
3232
string_type;
3333

34-
typedef
34+
typedef
3535
function<void(boost::iterator_range<charconst *>const &, system::error_codeconst &)>
3636
body_callback_function_type;
3737

@@ -75,11 +75,11 @@ namespace boost { namespace network { namespace http {
7575
}
7676

7777
basic_response<Tag>constrequest_skeleton(
78-
basic_request<Tag>const & request_,
79-
string_typeconst & method,
78+
basic_request<Tag>const & request_,
79+
string_typeconst & method,
8080
bool get_body,
8181
body_callback_function_type callback
82-
)
82+
)
8383
{
8484
typename connection_base::connection_ptr connection_;
8585
connection_ =connection_base::get_connection(resolver_, request_, certificate_filename_, verify_path_);

‎boost/network/protocol/http/client/connection/async_normal.hpp‎

Lines changed: 45 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -51,12 +51,12 @@ namespace boost { namespace network { namespace http { namespace impl {
5151

5252
http_async_connection(
5353
resolver_type & resolver,
54-
resolve_function resolve,
55-
bool follow_redirect
56-
) :
54+
resolve_function resolve,
55+
bool follow_redirect
56+
) :
5757
follow_redirect_(follow_redirect),
5858
resolver_(resolver),
59-
resolve_(resolve),
59+
resolve_(resolve),
6060
request_strand_(resolver.get_io_service())
6161
{}
6262

@@ -68,7 +68,7 @@ namespace boost { namespace network { namespace http { namespace impl {
6868
std::ostreambuf_iterator<typename char_<Tag>::type>(&command_streambuf));
6969
this->method = method;
7070
boost::uint16_t port_ =port(request);
71-
resolve_(resolver_,host(request),
71+
resolve_(resolver_,host(request),
7272
port_,
7373
request_strand_.wrap(
7474
boost::bind(
@@ -83,6 +83,17 @@ namespace boost { namespace network { namespace http { namespace impl {
8383

8484
http_async_connection(http_async_connectionconst &);// = delete
8585

86+
voidset_errors(boost::system::error_codeconst & ec) {
87+
boost::system::system_errorerror(ec);
88+
this->version_promise.set_exception(boost::copy_exception(error));
89+
this->status_promise.set_exception(boost::copy_exception(error));
90+
this->status_message_promise.set_exception(boost::copy_exception(error));
91+
this->headers_promise.set_exception(boost::copy_exception(error));
92+
this->source_promise.set_exception(boost::copy_exception(error));
93+
this->destination_promise.set_exception(boost::copy_exception(error));
94+
this->body_promise.set_exception(boost::copy_exception(error));
95+
}
96+
8697
voidhandle_resolved(boost::uint16_t port,bool get_body, body_callback_function_type callback, boost::system::error_codeconst & ec, resolver_iterator_pair endpoint_range) {
8798
resolver_iterator iter =boost::begin(endpoint_range);
8899
if (!ec && !boost::empty(endpoint_range)) {
@@ -103,14 +114,7 @@ namespace boost { namespace network { namespace http { namespace impl {
103114
boost::asio::placeholders::error
104115
)));
105116
}else {
106-
boost::system::system_errorerror(ec ? ec : boost::asio::error::host_not_found);
107-
this->version_promise.set_exception(boost::copy_exception(error));
108-
this->status_promise.set_exception(boost::copy_exception(error));
109-
this->status_message_promise.set_exception(boost::copy_exception(error));
110-
this->headers_promise.set_exception(boost::copy_exception(error));
111-
this->source_promise.set_exception(boost::copy_exception(error));
112-
this->destination_promise.set_exception(boost::copy_exception(error));
113-
this->body_promise.set_exception(boost::copy_exception(error));
117+
set_errors(ec ? ec : boost::asio::error::host_not_found);
114118
}
115119
}
116120

@@ -123,7 +127,7 @@ namespace boost { namespace network { namespace http { namespace impl {
123127
boost::bind(
124128
&http_async_connection<Tag,version_major,version_minor>::handle_sent_request,
125129
http_async_connection<Tag,version_major,version_minor>::shared_from_this(),
126-
get_body, callback,
130+
get_body, callback,
127131
boost::asio::placeholders::error,
128132
boost::asio::placeholders::bytes_transferred
129133
)));
@@ -146,16 +150,7 @@ namespace boost { namespace network { namespace http { namespace impl {
146150
boost::asio::placeholders::error
147151
)));
148152
}else {
149-
boost::system::system_errorerror(
150-
ec ? ec : boost::asio::error::host_not_found
151-
);
152-
this->version_promise.set_exception(boost::copy_exception(error));
153-
this->status_promise.set_exception(boost::copy_exception(error));
154-
this->status_message_promise.set_exception(boost::copy_exception(error));
155-
this->headers_promise.set_exception(boost::copy_exception(error));
156-
this->source_promise.set_exception(boost::copy_exception(error));
157-
this->destination_promise.set_exception(boost::copy_exception(error));
158-
this->body_promise.set_exception(boost::copy_exception(error));
153+
set_errors(ec ? ec : boost::asio::error::host_not_found);
159154
}
160155
}
161156
}
@@ -173,36 +168,34 @@ namespace boost { namespace network { namespace http { namespace impl {
173168
&http_async_connection<Tag,version_major,version_minor>::handle_received_data,
174169
http_async_connection<Tag,version_major,version_minor>::shared_from_this(),
175170
version, get_body, callback,
176-
boost::asio::placeholders::error,
171+
boost::asio::placeholders::error,
177172
boost::asio::placeholders::bytes_transferred)));
178173
}else {
179-
boost::system::system_errorerror(ec);
180-
this->version_promise.set_exception(boost::copy_exception(error));
181-
this->status_promise.set_exception(boost::copy_exception(error));
182-
this->status_message_promise.set_exception(boost::copy_exception(error));
183-
this->headers_promise.set_exception(boost::copy_exception(error));
184-
this->source_promise.set_exception(boost::copy_exception(error));
185-
this->destination_promise.set_exception(boost::copy_exception(error));
186-
this->body_promise.set_exception(boost::copy_exception(error));
174+
set_errors(ec);
187175
}
188176
}
189177

190178
voidhandle_received_data(state_t state,bool get_body, body_callback_function_type callback, boost::system::error_codeconst & ec, std::size_t bytes_transferred) {
191179
if (!ec || ec == boost::asio::error::eof) {
180+
// Sanity check
181+
if (ec == boost::asio::error::eof && state < headers) {
182+
return;
183+
}
192184
logic::tribool parsed_ok;
193185
size_t remainder;
194186
switch(state) {
195187
case version:
196-
parsed_ok =
188+
parsed_ok =
197189
this->parse_version(*socket_,
198190
request_strand_.wrap(
199191
boost::bind(
200192
&http_async_connection<Tag,version_major,version_minor>::handle_received_data,
201193
http_async_connection<Tag,version_major,version_minor>::shared_from_this(),
202-
status, get_body, callback,
194+
version, get_body, callback,
203195
boost::asio::placeholders::error, boost::asio::placeholders::bytes_transferred
204196
)
205-
)
197+
),
198+
bytes_transferred
206199
);
207200
if (parsed_ok !=true)return;
208201
case status:
@@ -212,10 +205,11 @@ namespace boost { namespace network { namespace http { namespace impl {
212205
boost::bind(
213206
&http_async_connection<Tag,version_major,version_minor>::handle_received_data,
214207
http_async_connection<Tag,version_major,version_minor>::shared_from_this(),
215-
status_message, get_body, callback,
208+
status, get_body, callback,
216209
boost::asio::placeholders::error, boost::asio::placeholders::bytes_transferred
217210
)
218-
)
211+
),
212+
bytes_transferred
219213
);
220214
if (parsed_ok !=true)return;
221215
case status_message:
@@ -225,10 +219,11 @@ namespace boost { namespace network { namespace http { namespace impl {
225219
boost::bind(
226220
&http_async_connection<Tag,version_major,version_minor>::handle_received_data,
227221
http_async_connection<Tag,version_major,version_minor>::shared_from_this(),
228-
headers, get_body, callback,
222+
status_message, get_body, callback,
229223
boost::asio::placeholders::error, boost::asio::placeholders::bytes_transferred
230224
)
231-
)
225+
),
226+
bytes_transferred
232227
);
233228
if (parsed_ok !=true)return;
234229
case headers:
@@ -241,7 +236,8 @@ namespace boost { namespace network { namespace http { namespace impl {
241236
headers, get_body, callback,
242237
boost::asio::placeholders::error, boost::asio::placeholders::bytes_transferred
243238
)
244-
)
239+
),
240+
bytes_transferred
245241
);
246242
if (parsed_ok !=true)return;
247243
if (!get_body) {
@@ -253,8 +249,9 @@ namespace boost { namespace network { namespace http { namespace impl {
253249
std::advance(begin, remainder);
254250
typename protocol_base::buffer_type::const_iterator end = begin;
255251
std::advance(end,this->part.size() - remainder);
252+
this->body_promise.set_value("");
256253
callback(make_iterator_range(begin, end), ec);
257-
socket_->async_read_some(
254+
socket_->async_read_some(
258255
boost::asio::mutable_buffers_1(this->part.c_array(),this->part.size()),
259256
request_strand_.wrap(
260257
boost::bind(
@@ -264,7 +261,6 @@ namespace boost { namespace network { namespace http { namespace impl {
264261
boost::asio::placeholders::error, boost::asio::placeholders::bytes_transferred)
265262
)
266263
);
267-
this->body_promise.set_value("");
268264
}else {
269265
this->parse_body(
270266
*socket_,
@@ -278,7 +274,7 @@ namespace boost { namespace network { namespace http { namespace impl {
278274
),
279275
remainder);
280276
}
281-
break;
277+
return;
282278
case body:
283279
if (ec == boost::asio::error::eof) {
284280
if (callback) {
@@ -304,7 +300,7 @@ namespace boost { namespace network { namespace http { namespace impl {
304300
typename protocol_base::buffer_type::const_iterator begin =this->part.begin(), end = begin;
305301
std::advance(end, bytes_transferred);
306302
callback(make_iterator_range(begin, end), ec);
307-
socket_->async_read_some(
303+
socket_->async_read_some(
308304
boost::asio::mutable_buffers_1(this->part.c_array(),this->part.size()),
309305
request_strand_.wrap(
310306
boost::bind(
@@ -328,7 +324,7 @@ namespace boost { namespace network { namespace http { namespace impl {
328324
bytes_transferred);
329325
}
330326
}
331-
break;
327+
return;
332328
default:
333329
BOOST_ASSERT(false &&"Bug, report this to the developers!");
334330
}
@@ -337,13 +333,13 @@ namespace boost { namespace network { namespace http { namespace impl {
337333
this->source_promise.set_exception(boost::copy_exception(error));
338334
this->destination_promise.set_exception(boost::copy_exception(error));
339335
switch (state) {
340-
case version:
336+
case version:
341337
this->version_promise.set_exception(boost::copy_exception(error));
342-
case status:
338+
case status:
343339
this->status_promise.set_exception(boost::copy_exception(error));
344340
case status_message:
345341
this->status_message_promise.set_exception(boost::copy_exception(error));
346-
case headers:
342+
case headers:
347343
this->headers_promise.set_exception(boost::copy_exception(error));
348344
case body:
349345
this->body_promise.set_exception(boost::copy_exception(error));

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp