Skip to content

Commit

Permalink
【CURL】Optimize requests to use caches and TCP keep alive.
Browse files Browse the repository at this point in the history
  • Loading branch information
skylersaleh committed Aug 17, 2024
1 parent 5987e95 commit c310753
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions src/https.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,9 @@ struct thread_pool {

private:
void main_loop() {
CURL* curl = curl_easy_init();
curl_easy_setopt(curl, CURLOPT_TCP_KEEPALIVE, 1L);
curl_easy_setopt(curl, CURLOPT_TCP_NODELAY, 1L);
while (!terminate_all) {
job j;
{
Expand All @@ -60,11 +63,12 @@ struct thread_pool {
j = jobs.front();
jobs.pop();
}
handle_job(j);
handle_job(j,curl);
}
curl_easy_cleanup(curl);
}

void handle_job(job& j);
void handle_job(job& j, CURL* curl);

std::atomic_bool terminate_all = { false };

Expand Down Expand Up @@ -188,9 +192,8 @@ CURLcode sslctx_function(CURL *curl, void *sslctx, void *parm)
return rv;
}

void thread_pool::handle_job(job& j)
void thread_pool::handle_job(job& j, CURL * curl)
{
CURL* curl = curl_easy_init();
if (!curl)
{
printf("[cloud] failed to initialize curl\n");
Expand Down Expand Up @@ -259,7 +262,6 @@ void thread_pool::handle_job(job& j)
}

curl_slist_free_all(chunk);
curl_easy_cleanup(curl);
}
#endif

Expand Down

0 comments on commit c310753

Please sign in to comment.