[FFmpeg-devel] [PATCH v2] http connect: retry few times before reporting about error
Artjom Vejsel
akawolf0 at gmail.com
Mon Sep 17 19:46:21 EEST 2018
Signed-off-by: Artjom Vejsel <akawolf0 at gmail.com>
---
libavformat/http.c | 22 +++++++++++++++-------
1 file changed, 15 insertions(+), 7 deletions(-)
diff --git a/libavformat/http.c b/libavformat/http.c
index 4fdb2f13f2..d3558f522e 100644
--- a/libavformat/http.c
+++ b/libavformat/http.c
@@ -252,7 +252,7 @@ static int http_open_cnx(URLContext *h, AVDictionary **options)
{
HTTPAuthType cur_auth_type, cur_proxy_auth_type;
HTTPContext *s = h->priv_data;
- int location_changed, attempts = 0, redirects = 0;
+ int location_changed, auth_attempts = 0, open_attempts = 1, redirects = 0;
redo:
av_dict_copy(options, s->chained_options, 0);
@@ -260,13 +260,21 @@ redo:
cur_proxy_auth_type = s->auth_state.auth_type;
location_changed = http_open_cnx_internal(h, options);
- if (location_changed < 0)
- goto fail;
+ if (location_changed < 0) {
+ if (open_attempts < 4) {
+ av_log(h, AV_LOG_WARNING, "Couldn't get HTTP resource, retrying...\n");
+ if (s->hd)
+ ffurl_closep(&s->hd);
+ open_attempts++;
+ goto redo;
+ } else
+ goto fail;
+ }
- attempts++;
+ auth_attempts++;
if (s->http_code == 401) {
if ((cur_auth_type == HTTP_AUTH_NONE || s->auth_state.stale) &&
- s->auth_state.auth_type != HTTP_AUTH_NONE && attempts < 4) {
+ s->auth_state.auth_type != HTTP_AUTH_NONE && auth_attempts < 4) {
ffurl_closep(&s->hd);
goto redo;
} else
@@ -274,7 +282,7 @@ redo:
}
if (s->http_code == 407) {
if ((cur_proxy_auth_type == HTTP_AUTH_NONE || s->proxy_auth_state.stale) &&
- s->proxy_auth_state.auth_type != HTTP_AUTH_NONE && attempts < 4) {
+ s->proxy_auth_state.auth_type != HTTP_AUTH_NONE && auth_attempts < 4) {
ffurl_closep(&s->hd);
goto redo;
} else
@@ -290,7 +298,7 @@ redo:
/* Restart the authentication process with the new target, which
* might use a different auth mechanism. */
memset(&s->auth_state, 0, sizeof(s->auth_state));
- attempts = 0;
+ auth_attempts = 0;
location_changed = 0;
goto redo;
}
--
2.18.0
More information about the ffmpeg-devel
mailing list