From ff4f15214100d209f39e4ed85f47e572c8fe9289 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. --- src/player.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) (limited to 'src/player.c') diff --git a/src/player.c b/src/player.c index 977007d..df962fa 100644 --- a/src/player.c +++ b/src/player.c @@ -174,8 +174,16 @@ static bool openStream (player_t * const player) { player->fctx->interrupt_callback.callback = intCb; player->fctx->interrupt_callback.opaque = player; + /* in microseconds */ + unsigned long int timeout = player->settings->timeout*1000000; + char timeoutStr[16]; + ret = snprintf (timeoutStr, sizeof (timeoutStr), "%lu", timeout); + assert (ret < sizeof (timeoutStr)); + AVDictionary *options = NULL; + av_dict_set (&options, "timeout", timeoutStr, 0); + assert (player->url != NULL); - if ((ret = avformat_open_input (&player->fctx, player->url, NULL, NULL)) < 0) { + if ((ret = avformat_open_input (&player->fctx, player->url, NULL, &options)) < 0) { softfail ("Unable to open audio file"); } -- cgit v1.2.3