[FFmpeg-devel] [PATCH 1/1] avformat/http: flushing tcp receive buffer when it is write only mode

vdixit at akamai.com vdixit at akamai.com
Wed Mar 28 07:52:21 EEST 2018


From: Vishwanath Dixit <vdixit at akamai.com>

In write only mode, the TCP receive buffer keeps growing and eventually
becomes full. This results in zero tcp window size, which in turn causes
unwanted issues, like, terminated tcp connection. The issue is apparent
when http persistent connection is enabled in hls/dash streaming use
cases. To overcome this issue, the logic here reads and discards the data
from the tcp socket.
---
 libavformat/http.c | 7 +++++++
 1 file changed, 7 insertions(+)

diff --git a/libavformat/http.c b/libavformat/http.c
index 983034f..e6d414b 100644
--- a/libavformat/http.c
+++ b/libavformat/http.c
@@ -1627,6 +1627,13 @@ static int http_shutdown(URLContext *h, int flags)
         ((flags & AVIO_FLAG_READ) && s->chunked_post && s->listen)) {
         ret = ffurl_write(s->hd, footer, sizeof(footer) - 1);
         ret = ret > 0 ? 0 : ret;
+        /* flush the receive buffer when it is write only mode */
+        if (!(flags & AVIO_FLAG_READ)) {
+            char buf[1024];
+            s->hd->flags |= AVIO_FLAG_NONBLOCK;
+            ffurl_read(s->hd, buf, sizeof(buf));
+            s->hd->flags &= ~AVIO_FLAG_NONBLOCK;
+        }
         s->end_chunked_post = 1;
     }
 
-- 
1.9.1



More information about the ffmpeg-devel mailing list