Reputation: 2921
I am using CURL library for POST, GET, download and upload data. For some reason if request fails then we planned to retry the request again. we planned to retry for 5 times, even then fails then we stop and display failure message to user. For this we are running this in loop with delay of 10 second.
My question.
1) Is my approach to this is correct.
2) what is the best practice.
UPDATE:
int _tmain(int argc, _TCHAR* argv[])
{
CURL *curl;
CURLcode res;
int nRetryCount = 0;
do
{
curl_global_init(CURL_GLOBAL_DEFAULT);
curl = curl_easy_init();
if(curl)
{
curl_easy_setopt(curl, CURLOPT_URL, "http://www.google.com/");
res = curl_easy_perform(curl);
curl_easy_cleanup(curl);
if(CURLE_OK == res)
{
break;
}
nRetryCount++;
if (nRetryCount < 5)
{
//wait for 10 sec.
Sleep(10000);
}
}
} while (nRetryCount < 5);
curl_global_cleanup();
return 0;
}
Upvotes: 1
Views: 3389
Reputation: 7723
You've better to check http-status-code.
curl_easy_getinfo(curl, CURLINFO_HTTP_CODE, &http_status);
if (http_status == ...) {
break;
}
Upvotes: 1