summaryrefslogtreecommitdiff
path: root/src/http
diff options
context:
space:
mode:
authorLars-Dominik Braun <lars@6xq.net>2018-04-07 20:17:23 +0200
committerMichał Cichoń <michcic@gmail.com>2018-10-30 13:08:55 +0100
commita9d5d2c3eb9d29d54509936b9e45f8eb034c033f (patch)
treec8473f5ef1a0f62c77df537cc1bf6d628b894d92 /src/http
parentaed0f7555f7c684c0ef46304ecb5218c75b605cd (diff)
downloadpianobar-windows-a9d5d2c3eb9d29d54509936b9e45f8eb034c033f.tar.gz
pianobar-windows-a9d5d2c3eb9d29d54509936b9e45f8eb034c033f.tar.bz2
pianobar-windows-a9d5d2c3eb9d29d54509936b9e45f8eb034c033f.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/http')
-rw-r--r--src/http/http.c16
-rw-r--r--src/http/http.h2
2 files changed, 9 insertions, 9 deletions
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*);