Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Slightly faster code, slightly clearer intent
Browse files Browse the repository at this point in the history
chusitoo committed Jan 11, 2025
1 parent 904929a commit 1f609ea
Showing 1 changed file with 6 additions and 7 deletions.
13 changes: 6 additions & 7 deletions ext/src/http/client/curl/http_client_curl.cc
Original file line number Diff line number Diff line change
@@ -489,7 +489,7 @@ bool HttpClient::MaybeSpawnBackgroundThread()

if (operation->IsRetryable())
{
self->pending_to_retry_sessions_.push_front(hold_session);
self->pending_to_retry_sessions_.push_back(hold_session);
}
}
}
@@ -797,26 +797,25 @@ bool HttpClient::doRetrySessions()
auto has_data = false;

// Assumptions:
// - This is a FIFO list so older sessions, pushed at the front, always end up at the tail
// - This is a FIFO list so older sessions, pushed at the back, always end up at the front
// - Locking not required because only the background thread would be pushing to this container
// - Retry policy is not changed once HTTP client is initialized, so same settings for everyone
// - Iterating backwards should result in removing items with minimal or no compacting required
for (auto retry_it = pending_to_retry_sessions_.crbegin();
retry_it != pending_to_retry_sessions_.crend();)
for (auto retry_it = pending_to_retry_sessions_.cbegin();
retry_it != pending_to_retry_sessions_.cend();)
{
const auto session = *retry_it;
const auto operation = session ? session->GetOperation().get() : nullptr;

if (!operation)
{
retry_it = decltype(retry_it){pending_to_retry_sessions_.erase(std::next(retry_it).base())};
retry_it = pending_to_retry_sessions_.erase(retry_it);
}
else if (operation->NextRetryTime() < now)
{
auto easy_handle = operation->GetCurlEasyHandle();
curl_multi_remove_handle(multi_handle_, easy_handle);
curl_multi_add_handle(multi_handle_, easy_handle);
retry_it = decltype(retry_it){pending_to_retry_sessions_.erase(std::next(retry_it).base())};
retry_it = pending_to_retry_sessions_.erase(retry_it);
has_data = true;
}
else

0 comments on commit 1f609ea

Please sign in to comment.