Skip to content
This repository was archived by the owner on Dec 29, 2022. It is now read-only.

Commit e4790ef

Browse files
committed
Improvements of async connection timeout
1 parent 65bf2b2 commit e4790ef

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
void handle_timeout(boost::system::error_code const &ec) {
124125
if (!ec) delegate_->disconnect();
126+
is_timedout_ = true;
125127
}
126128

127129
void handle_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_code const& ec) {
155-
if (!ec) {
157+
if (is_timedout_) {
158+
set_errors(asio::error::timed_out);
159+
} else if (!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_code const& 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_error error(ec);
411+
boost::system::system_error error(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)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy