diff --git a/include/ylt/standalone/cinatra/coro_http_client.hpp b/include/ylt/standalone/cinatra/coro_http_client.hpp index 71dd95196..52876fadc 100644 --- a/include/ylt/standalone/cinatra/coro_http_client.hpp +++ b/include/ylt/standalone/cinatra/coro_http_client.hpp @@ -625,10 +625,10 @@ class coro_http_client : public std::enable_shared_from_this { struct timer_guard { timer_guard(coro_http_client *self, std::chrono::steady_clock::duration duration, std::string msg) - : self(self) { + : self(self), dur_(duration) { self->socket_->is_timeout_ = false; - if (self->enable_timeout_ && duration.count() >= 0) { + if (duration.count() >= 0) { self->timeout(self->timer_, duration, std::move(msg)) .start([](auto &&) { }); @@ -636,12 +636,13 @@ class coro_http_client : public std::enable_shared_from_this { return; } ~timer_guard() { - if (self->enable_timeout_ && self->socket_->is_timeout_ == false) { + if (dur_.count() > 0 && self->socket_->is_timeout_ == false) { std::error_code ignore_ec; self->timer_.cancel(ignore_ec); } } coro_http_client *self; + std::chrono::steady_clock::duration dur_; }; async_simple::coro::Lazy async_download(std::string uri, @@ -1457,12 +1458,10 @@ class coro_http_client : public std::enable_shared_from_this { } void set_conn_timeout(std::chrono::steady_clock::duration timeout_duration) { - enable_timeout_ = true; conn_timeout_duration_ = timeout_duration; } void set_req_timeout(std::chrono::steady_clock::duration timeout_duration) { - enable_timeout_ = true; req_timeout_duration_ = timeout_duration; }