Thanks to visit codestin.com
Credit goes to github.com

Skip to content
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
25 changes: 24 additions & 1 deletion audioscrobbler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

#define APIKEY "a0ed2629d3d28606f67d7214c916788d"
#define SECRET "295f31c5d28215215b1503fb0327cc01"
#define CURL_MAX_RETRIES 3
#define CURL_RETRY_DELAY 3 // Seconds

CAudioScrobbler* AudioScrobbler = 0;

Expand Down Expand Up @@ -44,6 +46,7 @@ void CAudioScrobbler::OpenURL(std::string url, const char* postfields = 0, char*
curl_easy_setopt(_handle, CURLOPT_DNS_CACHE_TIMEOUT, 0);
curl_easy_setopt(_handle, CURLOPT_NOPROGRESS, 1);
curl_easy_setopt(_handle, CURLOPT_WRITEFUNCTION, writecb);
curl_easy_setopt(_handle, CURLOPT_TIMEOUT, 10);

if(postfields) {
curl_easy_setopt(_handle, CURLOPT_POST, 1);
Expand All @@ -55,7 +58,27 @@ void CAudioScrobbler::OpenURL(std::string url, const char* postfields = 0, char*
curl_easy_setopt(_handle, CURLOPT_ERRORBUFFER, errbuf);

curl_easy_setopt(_handle, CURLOPT_URL, url.c_str());
curl_easy_perform(_handle);
CURLcode res = curl_easy_perform(_handle);

// Sometimes last.fm likes to just timeout for no reason, leaving us hanging.
// If this happens, retry a few times with a small delay.
if (res != CURLE_OK) {
eprintf("libcurl: (%d)", res);
eprintf("%s", curl_easy_strerror(res));
eprintf("Will retry %d times with a %d second delay.", CURL_MAX_RETRIES, CURL_RETRY_DELAY);

int retries = 0;
do {
sleep(CURL_RETRY_DELAY);
retries++;
eprintf("Retry %d/%d", retries, CURL_MAX_RETRIES);

res = curl_easy_perform(_handle);
if (res != CURLE_OK) {
eprintf("Failed: %s", curl_easy_strerror(res));
}
} while (res != CURLE_OK && retries < CURL_MAX_RETRIES);
}
}


Expand Down