From f43a0894cb1386bbb5c0c1f068a4f60192070658 Mon Sep 17 00:00:00 2001 From: Lars-Dominik Braun Date: Sat, 30 Sep 2017 17:06:41 +0200 Subject: Add tired rating to song Now we can show a tired icon in the history. Closes #637. --- src/settings.h | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'src/settings.h') diff --git a/src/settings.h b/src/settings.h index 0edb544..8ec69ac 100644 --- a/src/settings.h +++ b/src/settings.h @@ -98,8 +98,7 @@ typedef struct { char *bindTo; char *autostartStation; char *eventCmd; - char *loveIcon; - char *banIcon; + char *loveIcon, *banIcon, *tiredIcon; char *atIcon; char *npSongFormat; char *npStationFormat; -- cgit v1.2.3 From a9d5d2c3eb9d29d54509936b9e45f8eb034c033f Mon Sep 17 00:00:00 2001 From: Lars-Dominik Braun Date: Sat, 7 Apr 2018 20:17:23 +0200 Subject: 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. --- contrib/pianobar.1 | 8 ++++++-- src/http/http.c | 16 ++++++++-------- src/http/http.h | 2 +- src/main.c | 11 ++++++----- src/main.h | 2 +- src/settings.c | 9 ++++++--- src/settings.h | 2 +- 7 files changed, 29 insertions(+), 21 deletions(-) (limited to 'src/settings.h') diff --git a/contrib/pianobar.1 b/contrib/pianobar.1 index 9600859..9219a99 100644 --- a/contrib/pianobar.1 +++ b/contrib/pianobar.1 @@ -335,8 +335,8 @@ Keep a history of the last n songs (5, by default). You can rate these songs. Icon for loved songs. .TP -.B max_player_errors = 5 -Amount of song download errors in a row after pianobar stops playback. +.B max_retry = 3 +Max failures for several actions before giving up. .TP .B partner_password = AC7IBG09A3DTSYM4R41UJWL07VLN8JI7 @@ -371,6 +371,10 @@ Sort station list by name or type (is quickmix) and name. name_az for example sorts by name from a to z, quickmix_01_name_za by type (quickmix at the bottom) and name from z to a. +.TP +.B timeout = 30 +Network operation timeout. + .TP .B tired_icon = zZ Icon for temporarily suspended songs. diff --git a/src/http/http.c b/src/http/http.c index 4576d04..9457fab 100644 --- a/src/http/http.c +++ b/src/http/http.c @@ -41,7 +41,7 @@ struct _http_t { static char* HttpToString(const wchar_t* wideString, int size); static wchar_t* HttpToWideString(const char* string, int size); -static bool HttpCreateConnection (http_t http); +static bool HttpCreateConnection (http_t http, unsigned int timeOut); static void HttpCloseConnection (http_t http); static void HttpSetLastError (http_t http, const char* message); static void HttpSetLastErrorW (http_t http, const wchar_t* message); @@ -75,7 +75,7 @@ static wchar_t* HttpToWideString(const char* string, int size) { } -static bool HttpCreateConnection (http_t http) { +static bool HttpCreateConnection (http_t http, unsigned int timeOut) { INTERNET_PORT defaultPort = INTERNET_DEFAULT_PORT; HttpCloseConnection (http); @@ -89,10 +89,10 @@ static bool HttpCreateConnection (http_t http) { WINHTTP_SAFE(http->session != NULL); WinHttpSetTimeouts(http->session, - 60 * 1000, // DNS time-out - 60 * 1000, // connect time-out - 30 * 1000, // send time-out - 30 * 1000); // receive time-out + timeOut * 1000, // DNS time-out + timeOut * 1000, // connect time-out + timeOut * 1000, // send time-out + timeOut * 1000); // receive time-out http->connection = WinHttpConnect( http->session, @@ -187,7 +187,7 @@ static char* HttpFormatWinHttpError (DWORD errorCode) { return HttpFormatWinApiError(errorCode, NULL); } -bool HttpInit(http_t* http, const char* endpoint, const char* securePort) { +bool HttpInit(http_t* http, const char* endpoint, const char* securePort, unsigned int timeOut) { http_t out = malloc(sizeof(struct _http_t)); if (!out) return false; @@ -196,7 +196,7 @@ bool HttpInit(http_t* http, const char* endpoint, const char* securePort) { out->endpoint = HttpToWideString(endpoint, -1); out->securePort = HttpToWideString(securePort, -1); - if (!HttpCreateConnection (out)) { + if (!HttpCreateConnection (out, timeOut)) { HttpDestroy (out); return false; } diff --git a/src/http/http.h b/src/http/http.h index 5ea617f..415b0d0 100644 --- a/src/http/http.h +++ b/src/http/http.h @@ -32,7 +32,7 @@ THE SOFTWARE. typedef struct _http_t *http_t; -bool HttpInit (http_t*, const char*, const char*); +bool HttpInit (http_t*, const char*, const char*, unsigned int); void HttpDestroy (http_t); bool HttpSetAutoProxy (http_t, const char*); diff --git a/src/main.c b/src/main.c index 4f4214a..a75388e 100644 --- a/src/main.c +++ b/src/main.c @@ -248,9 +248,9 @@ static void BarMainStartPlayback(BarApp_t *app) PIANO_RET_OK); if (!BarPlayer2Play(app->player)) - ++app->playerErrors; + ++app->retries; else - app->playerErrors = 0; + app->retries = 0; } } @@ -265,11 +265,11 @@ static void BarMainPlayerCleanup(BarApp_t *app) BarConsoleSetTitle(TITLE); - if (app->playerErrors >= app->settings.maxPlayerErrors) + if (app->retries >= app->settings.maxRetry) { /* don't continue playback if thread reports too many error */ app->nextStation = NULL; - app->playerErrors = 0; + app->retries = 0; } } @@ -411,7 +411,8 @@ int main(int argc, char **argv) app.settings.keys[BAR_KS_HELP]); } - HttpInit(&app.http2, app.settings.rpcHost, app.settings.rpcTlsPort); + HttpInit(&app.http2, app.settings.rpcHost, app.settings.rpcTlsPort, + app.settings.timeout); if (app.settings.controlProxy) HttpSetProxy(app.http2, app.settings.controlProxy); diff --git a/src/main.h b/src/main.h index 192ffdb..047f637 100644 --- a/src/main.h +++ b/src/main.h @@ -46,6 +46,6 @@ typedef struct { PianoStation_t *curStation, *nextStation; char doQuit; BarReadline_t rl; - unsigned int playerErrors; + unsigned int retries; } BarApp_t; diff --git a/src/settings.c b/src/settings.c index 553c86e..c8a413e 100644 --- a/src/settings.c +++ b/src/settings.c @@ -173,8 +173,9 @@ void BarSettingsRead (BarSettings_t *settings) { settings->autoselect = true; settings->history = 5; settings->volume = 0; + settings->timeout = 30; /* seconds */ settings->gainMul = 1.0; - settings->maxPlayerErrors = 5; + settings->maxRetry = 3; settings->sortOrder = BAR_SORT_NAME_AZ; settings->loveIcon = strdup (" <3"); settings->banIcon = strdup (" eventCmd = BarSettingsExpandTilde (val, userhome); } else if (streq ("history", key)) { settings->history = atoi (val); - } else if (streq ("max_player_errors", key)) { - settings->maxPlayerErrors = atoi (val); + } else if (streq ("max_retry", key)) { + settings->maxRetry = atoi (val); + } else if (streq ("timeout", key)) { + settings->timeout = atoi (val); } else if (streq ("sort", key)) { size_t i; static const char *mapping[] = {"name_az", diff --git a/src/settings.h b/src/settings.h index 8ec69ac..719c39b 100644 --- a/src/settings.h +++ b/src/settings.h @@ -86,7 +86,7 @@ typedef struct { typedef struct { bool autoselect; - unsigned int history, maxPlayerErrors; + unsigned int history, maxRetry, timeout; int volume; float gainMul; BarStationSorting_t sortOrder; -- cgit v1.2.3