1
0
Fork 0
mirror of https://github.com/beefytech/Beef.git synced 2025-06-10 04:22:20 +02:00

Retry on unexpected http failures

This commit is contained in:
Brian Fiete 2021-02-15 09:56:51 -08:00
parent bb848624d1
commit f2516b7ab8

View file

@ -82,17 +82,14 @@ static size_t WriteMemoryCallback(void* contents, size_t size, size_t nmemb, voi
void NetRequest::Cleanup() void NetRequest::Cleanup()
{ {
if (mCURLMulti != NULL) if (mCURLMulti != NULL)
{
curl_multi_remove_handle(mCURLMulti, mCURL); curl_multi_remove_handle(mCURLMulti, mCURL);
}
if (mCURL != NULL) if (mCURL != NULL)
curl_easy_cleanup(mCURL); curl_easy_cleanup(mCURL);
if (mCURLMulti != NULL) if (mCURLMulti != NULL)
{
curl_multi_cleanup(mCURLMulti); curl_multi_cleanup(mCURLMulti);
}
mCURL = NULL;
mCURLMulti = NULL;
} }
void NetRequest::DoTransfer() void NetRequest::DoTransfer()
@ -105,66 +102,76 @@ void NetRequest::DoTransfer()
// return; // return;
// } // }
BfLogDbg("NetManager starting get on %s\n", mURL.c_str()); long response_code = 0;
mNetManager->mDebugManager->OutputRawMessage(StrFormat("msgLo Getting '%s'\n", mURL.c_str())); for (int pass = 0; pass < 3; pass++)
mOutTempPath = mOutPath + "__partial";
mCURLMulti = curl_multi_init();
mCURL = curl_easy_init();
if (mShowTracking)
{ {
mNetManager->mDebugManager->OutputRawMessage(StrFormat("symsrv Getting '%s'", mURL.c_str())); BfLogDbg("NetManager starting get on %s Pass:%d\n", mURL.c_str(), pass);
} mNetManager->mDebugManager->OutputRawMessage(StrFormat("msgLo Getting '%s'\n", mURL.c_str()));
//OutputDebugStrF("Getting '%s'\n", mURL.c_str()); mOutTempPath = mOutPath + "__partial";
curl_easy_setopt(mCURL, CURLOPT_URL, mURL.c_str()); mCURLMulti = curl_multi_init();
curl_easy_setopt(mCURL, CURLOPT_WRITEDATA, (void*)this);
curl_easy_setopt(mCURL, CURLOPT_WRITEFUNCTION, WriteMemoryCallback);
curl_easy_setopt(mCURL, CURLOPT_XFERINFODATA, (void*)this);
curl_easy_setopt(mCURL, CURLOPT_XFERINFOFUNCTION, TransferInfoCallback);
curl_easy_setopt(mCURL, CURLOPT_FOLLOWLOCATION, 1L);
curl_easy_setopt(mCURL, CURLOPT_NOPROGRESS, 0L);
curl_easy_setopt(mCURL, CURLOPT_IPRESOLVE, CURL_IPRESOLVE_V4); // Connects go slow without this
//auto result = curl_easy_perform(mCURL);
CURLMcode mcode = curl_multi_add_handle(mCURLMulti, mCURL); mCURL = curl_easy_init();
if (mcode != CURLM_OK)
{
mFailed = true;
return;
}
while (true) if (mShowTracking)
{ {
int activeCount = 0; mNetManager->mDebugManager->OutputRawMessage(StrFormat("symsrv Getting '%s'", mURL.c_str()));
curl_multi_perform(mCURLMulti, &activeCount); }
if (activeCount == 0)
break;
int waitRet = 0; //OutputDebugStrF("Getting '%s'\n", mURL.c_str());
curl_multi_wait(mCURLMulti, NULL, 0, 20, &waitRet);
if (mCancelling) curl_easy_setopt(mCURL, CURLOPT_URL, mURL.c_str());
curl_easy_setopt(mCURL, CURLOPT_WRITEDATA, (void*)this);
curl_easy_setopt(mCURL, CURLOPT_WRITEFUNCTION, WriteMemoryCallback);
curl_easy_setopt(mCURL, CURLOPT_XFERINFODATA, (void*)this);
curl_easy_setopt(mCURL, CURLOPT_XFERINFOFUNCTION, TransferInfoCallback);
curl_easy_setopt(mCURL, CURLOPT_FOLLOWLOCATION, 1L);
curl_easy_setopt(mCURL, CURLOPT_NOPROGRESS, 0L);
curl_easy_setopt(mCURL, CURLOPT_IPRESOLVE, CURL_IPRESOLVE_V4); // Connects go slow without this
//auto result = curl_easy_perform(mCURL);
CURLMcode mcode = curl_multi_add_handle(mCURLMulti, mCURL);
if (mcode != CURLM_OK)
{ {
mFailed = true; mFailed = true;
return; return;
} }
while (true)
{
int activeCount = 0;
curl_multi_perform(mCURLMulti, &activeCount);
if (activeCount == 0)
break;
int waitRet = 0;
curl_multi_wait(mCURLMulti, NULL, 0, 20, &waitRet);
if (mCancelling)
{
mFailed = true;
return;
}
}
// if (result != CURLE_OK)
// {
// mFailed = true;
// return;
// }
response_code = 0;
curl_easy_getinfo(mCURL, CURLINFO_RESPONSE_CODE, &response_code);
mNetManager->mDebugManager->OutputRawMessage(StrFormat("msgLo Result for '%s': %d\n", mURL.c_str(), response_code));
if ((response_code == 0) || (response_code == 200) || (response_code == 404))
break;
Cleanup();
// Try again!
} }
// if (result != CURLE_OK)
// {
// mFailed = true;
// return;
// }
long response_code = 0;
curl_easy_getinfo(mCURL, CURLINFO_RESPONSE_CODE, &response_code);
mNetManager->mDebugManager->OutputRawMessage(StrFormat("msgLo Result for '%s': %d\n", mURL.c_str(), response_code));
if (response_code == 200) if (response_code == 200)
{ {
curl_off_t downloadSize = 0; curl_off_t downloadSize = 0;