Skip to content

Commit d46f1c0

Browse files
authored
[coro_http_client]improve timeout (#885)
improve timeout
1 parent c4fc58e commit d46f1c0

File tree

1 file changed

+4
-5
lines changed

1 file changed

+4
-5
lines changed

include/ylt/standalone/cinatra/coro_http_client.hpp

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -625,23 +625,24 @@ class coro_http_client : public std::enable_shared_from_this<coro_http_client> {
625625
struct timer_guard {
626626
timer_guard(coro_http_client *self,
627627
std::chrono::steady_clock::duration duration, std::string msg)
628-
: self(self) {
628+
: self(self), dur_(duration) {
629629
self->socket_->is_timeout_ = false;
630630

631-
if (self->enable_timeout_ && duration.count() >= 0) {
631+
if (duration.count() >= 0) {
632632
self->timeout(self->timer_, duration, std::move(msg))
633633
.start([](auto &&) {
634634
});
635635
}
636636
return;
637637
}
638638
~timer_guard() {
639-
if (self->enable_timeout_ && self->socket_->is_timeout_ == false) {
639+
if (dur_.count() > 0 && self->socket_->is_timeout_ == false) {
640640
std::error_code ignore_ec;
641641
self->timer_.cancel(ignore_ec);
642642
}
643643
}
644644
coro_http_client *self;
645+
std::chrono::steady_clock::duration dur_;
645646
};
646647

647648
async_simple::coro::Lazy<resp_data> async_download(std::string uri,
@@ -1457,12 +1458,10 @@ class coro_http_client : public std::enable_shared_from_this<coro_http_client> {
14571458
}
14581459

14591460
void set_conn_timeout(std::chrono::steady_clock::duration timeout_duration) {
1460-
enable_timeout_ = true;
14611461
conn_timeout_duration_ = timeout_duration;
14621462
}
14631463

14641464
void set_req_timeout(std::chrono::steady_clock::duration timeout_duration) {
1465-
enable_timeout_ = true;
14661465
req_timeout_duration_ = timeout_duration;
14671466
}
14681467

0 commit comments

Comments
 (0)