Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[coro_http_client]improve timeout #885

Merged
merged 1 commit into from
Jan 23, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading