diff options
author | Lars-Dominik Braun <lars@6xq.net> | 2018-04-07 20:17:23 +0200 |
---|---|---|
committer | Lars-Dominik Braun <lars@6xq.net> | 2018-04-07 20:18:47 +0200 |
commit | ff4f15214100d209f39e4ed85f47e572c8fe9289 (patch) | |
tree | 1cea789efe2396b1855f5f65fbb79244cb0cf8f1 /src/ui.c | |
parent | 3c4d8f65896253a82e19adcbe2808a863a99f74f (diff) | |
download | pianobar-ff4f15214100d209f39e4ed85f47e572c8fe9289.tar.gz pianobar-ff4f15214100d209f39e4ed85f47e572c8fe9289.tar.bz2 pianobar-ff4f15214100d209f39e4ed85f47e572c8fe9289.zip |
Add network timeouts and retries
All network operations can time out now. API requests are retried up to
three times (default). Replaces setting max_player_errors with
max_retries, which is used for player and API. Adds timeout setting.
Partially reverts 436a1d4012553a2f33d0e3a5180b3b5ae0378bdd and fixes
(at least) issue #657.
Thanks to @exarkun for testing.
Diffstat (limited to 'src/ui.c')
-rw-r--r-- | src/ui.c | 17 |
1 files changed, 16 insertions, 1 deletions
@@ -205,6 +205,7 @@ static CURLcode BarPianoHttpRequest (CURL * const http, setAndCheck (CURLOPT_PROGRESSDATA, &lint); setAndCheck (CURLOPT_NOPROGRESS, 0); setAndCheck (CURLOPT_POST, 1); + setAndCheck (CURLOPT_TIMEOUT, settings->timeout); if (settings->caBundle != NULL) { setAndCheck (CURLOPT_CAINFO, settings->caBundle); } @@ -241,7 +242,21 @@ static CURLcode BarPianoHttpRequest (CURL * const http, list = curl_slist_append (list, "Content-Type: text/plain"); setAndCheck (CURLOPT_HTTPHEADER, list); - httpret = curl_easy_perform (http); + unsigned int retry = 0; + do { + httpret = curl_easy_perform (http); + ++retry; + if (httpret == CURLE_OPERATION_TIMEDOUT) { + free (buffer.data); + buffer.data = NULL; + buffer.pos = 0; + if (retry > settings->maxRetry) { + break; + } + } else { + break; + } + } while (true); curl_slist_free_all (list); |