From patchwork Fri Mar 1 09:39:14 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?b?bG16ZW5nKOabvuS7pOaYjik=?= X-Patchwork-Id: 12177 Return-Path: X-Original-To: patchwork@ffaux-bg.ffmpeg.org Delivered-To: patchwork@ffaux-bg.ffmpeg.org Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org [79.124.17.100]) by ffaux.localdomain (Postfix) with ESMTP id 086EF4471BA for ; Fri, 1 Mar 2019 11:39:46 +0200 (EET) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id DA489680572; Fri, 1 Mar 2019 11:39:45 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail4.tencent.com (unknown [183.57.53.109]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id AFADC680572 for ; Fri, 1 Mar 2019 11:39:38 +0200 (EET) Received: from EXHUB-SZMAIL04.tencent.com (unknown [10.14.6.35]) by mail4.tencent.com (Postfix) with ESMTP id 734D950894 for ; Fri, 1 Mar 2019 17:39:15 +0800 (CST) Received: from EXMBX-SZMail009.tencent.com ([fe80::f43d:9a3b:8faf:8d34]) by EXHUB-SZMAIL04.tencent.com ([::1]) with mapi id 14.03.0415.000; Fri, 1 Mar 2019 17:39:14 +0800 From: =?gb2312?B?bG16ZW5nKNT4we7D9yk=?= To: ffmpeg-devel Thread-Topic: avformat/http: reconnect when connect reset by peer Thread-Index: AdTQD8ei3s/Xo9uvToGHIib7ia6KmA== Date: Fri, 1 Mar 2019 09:39:14 +0000 Message-ID: Accept-Language: zh-CN, en-US Content-Language: zh-CN X-MS-Has-Attach: X-MS-TNEF-Correlator: x-originating-ip: [10.27.13.57] MIME-Version: 1.0 X-Content-Filtered-By: Mailman/MimeDel 2.1.20 Subject: [FFmpeg-devel] avformat/http: reconnect when connect reset by peer X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: FFmpeg development discussions and patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: FFmpeg development discussions and patches Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" diff --git a/libavformat/http.c b/libavformat/http.c old mode 100644 new mode 100755 index ed0eb1c..400df94 --- a/libavformat/http.c +++ b/libavformat/http.c @@ -253,6 +253,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 retry = 0; redo: av_dict_copy(options, s->chained_options, 0); @@ -260,9 +261,21 @@ redo: cur_proxy_auth_type = s->auth_state.auth_type; location_changed = http_open_cnx_internal(h, options); - if (location_changed < 0) + if (location_changed < 0) { + if (s->reconnect && retry++ < 3 && + ((location_changed == AVERROR(ECONNRESET)) || (location_changed == AVERROR(EPIPE)) || + (location_changed == AVERROR(ENETRESET)) || (location_changed == AVERROR(ECONNREFUSED)) || + (location_changed == AVERROR(ETIMEDOUT)))) { + if (ff_network_sleep_interruptible(1000U*1000, &h->interrupt_callback) != AVERROR(ETIMEDOUT)) { + goto fail; + } + if (s->hd) { + ffurl_closep(&s->hd); + } + goto redo; + } goto fail; - + } attempts++; if (s->http_code == 401) { if ((cur_auth_type == HTTP_AUTH_NONE || s->auth_state.stale) &&