diff mbox

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

Message ID 1522212741-15365-1-git-send-email-vdixit@akamai.com
State Superseded
Headers show

Commit Message

Dixit, Vishwanath March 28, 2018, 4:52 a.m. UTC
From: Vishwanath Dixit <vdixit@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(+)

Comments

Steven Liu March 28, 2018, 5:30 a.m. UTC | #1
> On 28 Mar 2018, at 12:52, vdixit@akamai.com wrote:
> 
> From: Vishwanath Dixit <vdixit@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));
ffurl_read have a int return value.

407 int ffurl_read(URLContext *h, unsigned char *buf, int size)
408 {
409     if (!(h->flags & AVIO_FLAG_READ))
410         return AVERROR(EIO);
411     return retry_transfer_wrapper(h, buf, size, 1, h->prot->url_read);
412 }


> +            s->hd->flags &= ~AVIO_FLAG_NONBLOCK;
> +        }
>         s->end_chunked_post = 1;
>     }
> 
> -- 
> 1.9.1
> 
> _______________________________________________
> ffmpeg-devel mailing list
> ffmpeg-devel@ffmpeg.org
> http://ffmpeg.org/mailman/listinfo/ffmpeg-devel

Thanks
Steven
Dixit, Vishwanath April 4, 2018, 11:11 a.m. UTC | #2
On 3/28/18 11:00 AM, Steven Liu wrote:
>

>

>> On 28 Mar 2018, at 12:52, vdixit@akamai.com wrote:

>>

>> From: Vishwanath Dixit <vdixit@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));

> ffurl_read have a int return value.

>

> 407 int ffurl_read(URLContext *h, unsigned char *buf, int size)

> 408 {

> 409     if (!(h->flags & AVIO_FLAG_READ))

> 410         return AVERROR(EIO);

> 411     return retry_transfer_wrapper(h, buf, size, 1, h->prot->url_read);

> 412 }

>

>

Thanks for the review comment. I have handled the return status of ffurl_read and have submitted a revised patch https://patchwork.ffmpeg.org/patch/8325/ 


>> +            s->hd->flags &= ~AVIO_FLAG_NONBLOCK;

>> +        }

>>         s->end_chunked_post = 1;

>>     }

>>

>> -- 

>> 1.9.1

>>

>> _______________________________________________

>> ffmpeg-devel mailing list

>> ffmpeg-devel@ffmpeg.org

>> http://ffmpeg.org/mailman/listinfo/ffmpeg-devel

>

> Thanks

> Steven

>

>

>

>

>
diff mbox

Patch

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;
     }