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

Commite4790ef

Browse files
committed
Improvements of async connection timeout
1 parent65bf2b2 commite4790ef

File tree

1 file changed

+11
-5
lines changed

1 file changed

+11
-5
lines changed

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

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ struct http_async_connection
7272
connection_delegate_ptr delegate)
7373
: timeout_(timeout),
7474
timer_(resolver.get_io_service()),
75+
is_timedout_(false),
7576
follow_redirect_(follow_redirect),
7677
resolver_(resolver),
7778
resolve_(resolve),
@@ -122,6 +123,7 @@ struct http_async_connection
122123

123124
voidhandle_timeout(boost::system::error_codeconst &ec) {
124125
if (!ec) delegate_->disconnect();
126+
is_timedout_ =true;
125127
}
126128

127129
voidhandle_resolved(boost::uint16_t port,bool get_body,
@@ -152,7 +154,9 @@ struct http_async_connection
152154
body_generator_function_type generator,
153155
resolver_iterator_pair endpoint_range,
154156
boost::system::error_codeconst& ec) {
155-
if (!ec) {
157+
if (is_timedout_) {
158+
set_errors(asio::error::timed_out);
159+
}elseif (!ec) {
156160
BOOST_ASSERT(delegate_.get() !=0);
157161
delegate_->write(
158162
command_streambuf,
@@ -191,7 +195,7 @@ struct http_async_connection
191195
body_generator_function_type generator,
192196
boost::system::error_codeconst& ec,
193197
std::size_t bytes_transferred) {
194-
if (!ec) {
198+
if (!is_timedout_ && !ec) {
195199
if (generator) {
196200
// Here we write some more data that the generator provides, before
197201
// we wait for data from the server.
@@ -219,7 +223,7 @@ struct http_async_connection
219223
version, get_body, callback, placeholders::error,
220224
placeholders::bytes_transferred)));
221225
}else {
222-
set_errors(ec);
226+
set_errors(is_timedout_ ? asio::error::timed_out :ec);
223227
}
224228
}
225229

@@ -235,7 +239,8 @@ struct http_async_connection
235239
#else
236240
false && short_read_error;
237241
#endif
238-
if (!ec || ec == boost::asio::error::eof || is_ssl_short_read_error) {
242+
if (!is_timedout_ &&
243+
(!ec || ec == boost::asio::error::eof || is_ssl_short_read_error)) {
239244
logic::tribool parsed_ok;
240245
size_t remainder;
241246
switch (state) {
@@ -403,7 +408,7 @@ struct http_async_connection
403408
BOOST_ASSERT(false &&"Bug, report this to the developers!");
404409
}
405410
}else {
406-
boost::system::system_errorerror(ec);
411+
boost::system::system_errorerror(is_timedout_ ? asio::error::timed_out :ec);
407412
this->source_promise.set_exception(boost::copy_exception(error));
408413
this->destination_promise.set_exception(boost::copy_exception(error));
409414
switch (state) {
@@ -454,6 +459,7 @@ struct http_async_connection
454459

455460
int timeout_;
456461
boost::asio::deadline_timer timer_;
462+
bool is_timedout_;
457463
bool follow_redirect_;
458464
resolver_type& resolver_;
459465
resolve_function resolve_;

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp