diff mbox series

[FFmpeg-devel,02/15] avformat/http: Return EIO for prematurely broken connection

Message ID 3cb72806477423ee777acce039d19255e2152a32.camel@haerdin.se
State New
Headers show
Series Spotify patchset | expand

Checks

Context Check Description
andriy/configure_x86 warning Failed to apply patch
yinshiyou/configure_loongarch64 warning Failed to apply patch

Commit Message

Tomas Härdin Oct. 29, 2024, 2:45 p.m. UTC
Use of stdbool.h might cause issues on some platforms. Otherwise looks
reasonable to me.

Spotify comments
----------------
Might not be a priority anymore when we’re using a caching http proxy
to hide some network problems.

/Tomas
diff mbox series

Patch

From d42ebdc41d02ade1921b91f278e90a15ce33a32f Mon Sep 17 00:00:00 2001
From: Ulrik <ulrikm@spotify.com>
Date: Mon, 27 Jul 2020 11:46:56 +0200
Subject: [PATCH 02/15] avformat/http: Return EIO for prematurely broken
 connection

Currently, a prematurely broken connection normally leads to the same
EOF, as a completed successful transfer. However, enabling reconnect
changes this logic, and leads to the return of EIO.

This patch unifies that logic, leading to the return of EIO for premature
disconnect, regardless of setting of "reconnect".
---
 libavformat/http.c | 13 ++++++++++---
 1 file changed, 10 insertions(+), 3 deletions(-)

diff --git a/libavformat/http.c b/libavformat/http.c
index ec60bc0b17..65ea5d993c 100644
--- a/libavformat/http.c
+++ b/libavformat/http.c
@@ -19,6 +19,8 @@ 
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  */
 
+#include <stdbool.h>
+
 #include "config.h"
 #include "config_components.h"
 
@@ -1747,6 +1749,7 @@  static int http_read_stream(URLContext *h, uint8_t *buf, int size)
     read_ret = http_buf_read(h, buf, size);
     while (read_ret < 0) {
         uint64_t target = h->is_streamed ? 0 : s->off;
+        bool is_premature = s->filesize > 0 && s->off < s->filesize;
 
         if (read_ret == AVERROR_EXIT)
             break;
@@ -1754,9 +1757,13 @@  static int http_read_stream(URLContext *h, uint8_t *buf, int size)
         if (h->is_streamed && !s->reconnect_streamed)
             break;
 
-        if (!(s->reconnect && s->filesize > 0 && s->off < s->filesize) &&
-            !(s->reconnect_at_eof && read_ret == AVERROR_EOF))
-            break;
+        if (!(s->reconnect && is_premature) &&
+            !(s->reconnect_at_eof && read_ret == AVERROR_EOF)) {
+            if (is_premature)
+                return AVERROR(EIO);
+            else
+                break;
+        }
 
         if (reconnect_delay > s->reconnect_delay_max || (s->reconnect_max_retries >= 0 && conn_attempts > s->reconnect_max_retries) ||
             reconnect_delay_total > s->reconnect_delay_total_max)
-- 
2.39.2