Skip to content

Commit

Permalink
[coro_http_client]improve timeout (#885)
Browse files Browse the repository at this point in the history
improve timeout
  • Loading branch information
qicosmos authored Jan 23, 2025
1 parent c4fc58e commit d46f1c0
Showing 1 changed file with 4 additions and 5 deletions.
9 changes: 4 additions & 5 deletions include/ylt/standalone/cinatra/coro_http_client.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -625,23 +625,24 @@ class coro_http_client : public std::enable_shared_from_this<coro_http_client> {
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 &&) {
});
}
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<resp_data> async_download(std::string uri,
Expand Down Expand Up @@ -1457,12 +1458,10 @@ class coro_http_client : public std::enable_shared_from_this<coro_http_client> {
}

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;
}

Expand Down

0 comments on commit d46f1c0

Please sign in to comment.