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

Commit66fa71c

Browse files
author
Grzegorz Baran
committed
Fix for: Body callback function is not called when some errors occur (timeout etc.)#640
1 parent30a0609 commit66fa71c

File tree

1 file changed

+13
-11
lines changed

1 file changed

+13
-11
lines changed

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

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ struct http_async_connection
118118
}
119119

120120
private:
121-
voidset_errors(std::error_codeconst& ec) {
121+
voidset_errors(std::error_codeconst& ec, body_callback_function_type callback) {
122122
std::system_errorerror(ec);
123123
this->version_promise.set_exception(std::make_exception_ptr(error));
124124
this->status_promise.set_exception(std::make_exception_ptr(error));
@@ -127,6 +127,8 @@ struct http_async_connection
127127
this->source_promise.set_exception(std::make_exception_ptr(error));
128128
this->destination_promise.set_exception(std::make_exception_ptr(error));
129129
this->body_promise.set_exception(std::make_exception_ptr(error));
130+
if ( callback )
131+
callback( boost::iterator_range<constchar*>(), ec );
130132
this->timer_.cancel();
131133
}
132134

@@ -155,9 +157,7 @@ struct http_async_connection
155157
generator,std::make_pair(++iter_copy,resolver_iterator()), ec);
156158
}));
157159
}else {
158-
set_errors(ec ? ec : ::asio::error::host_not_found);
159-
boost::iterator_range<constchar*> range;
160-
if (callback)callback(range, ec);
160+
set_errors((ec ? ec : ::asio::error::host_not_found), callback);
161161
}
162162
}
163163

@@ -168,7 +168,7 @@ struct http_async_connection
168168
resolver_iterator_pair endpoint_range,
169169
std::error_codeconst& ec) {
170170
if (is_timedout_) {
171-
set_errors(::asio::error::timed_out);
171+
set_errors(::asio::error::timed_out, callback);
172172
}elseif (!ec) {
173173
BOOST_ASSERT(delegate_.get() !=0);
174174
auto self =this->shared_from_this();
@@ -193,9 +193,7 @@ struct http_async_connection
193193
ec);
194194
}));
195195
}else {
196-
set_errors(ec ? ec : ::asio::error::host_not_found);
197-
boost::iterator_range<constchar*> range;
198-
if (callback)callback(range, ec);
196+
set_errors((ec ? ec : ::asio::error::host_not_found), callback);
199197
}
200198
}
201199
}
@@ -239,7 +237,7 @@ struct http_async_connection
239237
ec, bytes_transferred);
240238
}));
241239
}else {
242-
set_errors(is_timedout_ ? ::asio::error::timed_out : ec);
240+
set_errors((is_timedout_ ? ::asio::error::timed_out : ec), callback);
243241
}
244242
}
245243

@@ -322,6 +320,8 @@ struct http_async_connection
322320
// We short-circuit here because the user does not want to get the
323321
// body (in the case of a HEAD request).
324322
this->body_promise.set_value("");
323+
if ( callback )
324+
callback( boost::iterator_range<constchar*>(), ::asio::error::eof );
325325
this->destination_promise.set_value("");
326326
this->source_promise.set_value("");
327327
// this->part.assign('\0');
@@ -446,8 +446,8 @@ struct http_async_connection
446446
BOOST_ASSERT(false &&"Bug, report this to the developers!");
447447
}
448448
}else {
449-
std::system_errorerror(is_timedout_ ? ::asio::error::timed_out
450-
: ec);
449+
std::error_code report_code =is_timedout_ ? ::asio::error::timed_out : ec;
450+
std::system_errorerror(report_code);
451451
this->source_promise.set_exception(std::make_exception_ptr(error));
452452
this->destination_promise.set_exception(std::make_exception_ptr(error));
453453
switch (state) {
@@ -467,6 +467,8 @@ struct http_async_connection
467467
// so no exception should be set
468468
this->body_promise.set_exception(std::make_exception_ptr(error));
469469
}
470+
else
471+
callback( boost::iterator_range<constchar*>(), report_code );
470472
break;
471473
default:
472474
BOOST_ASSERT(false &&"Bug, report this to the developers!");

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp