diff options
author | Vishwanath Dixit <vdixit@akamai.com> | 2018-04-04 16:38:18 +0530 |
---|---|---|
committer | Karthick Jeyapal <kjeyapal@akamai.com> | 2018-04-20 11:31:21 +0530 |
commit | 30940be3593aee6144a9d238f25eef1aa4575c41 (patch) | |
tree | bf1e4c088fca29ad6257a13f1faf8d7aa6d8ca85 /libavformat/http.c | |
parent | 002e45b40760b15319a3f2ea3d2c78bd9cc72d38 (diff) |
avformat/http: flushing tcp receive buffer when it is write only mode
In write only mode, the TCP receive buffer's data keeps growing with
http response messages and the buffer 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 live streaming use
cases. To overcome this issue, the logic here reads the buffer data
when a file transfer is completed, so that any accumulated data in
the recieve buffer gets flushed out.
Diffstat (limited to 'libavformat/http.c')
-rw-r--r-- | libavformat/http.c | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/libavformat/http.c b/libavformat/http.c index d76a58bbbb..aa6348f28b 100644 --- a/libavformat/http.c +++ b/libavformat/http.c @@ -1623,6 +1623,18 @@ 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]; + int read_ret; + s->hd->flags |= AVIO_FLAG_NONBLOCK; + read_ret = ffurl_read(s->hd, buf, sizeof(buf)); + s->hd->flags &= ~AVIO_FLAG_NONBLOCK; + if (read_ret < 0 && read_ret != AVERROR(EAGAIN)) { + av_log(h, AV_LOG_ERROR, "URL read error: %d\n", read_ret); + ret = read_ret; + } + } s->end_chunked_post = 1; } |