diff mbox

[FFmpeg-devel] tcp: properly return EOF

Message ID 20171230164416.7638-1-nfxjfg@googlemail.com
State Accepted
Commit 0e1f771d2200d14d298df09c91e14f51e418fd3a
Headers show

Commit Message

wm4 Dec. 30, 2017, 4:44 p.m. UTC
There is no POSIX error code for EOF - recv() signals EOF by simply
returning 0. But libavformat recently changed its conventionts and
requires an explicit AVERROR_EOF, or it might get into an endless retry
loop, consuming 100% CPU while doing nothing.
---
 libavformat/tcp.c | 2 ++
 1 file changed, 2 insertions(+)

Comments

Ronald S. Bultje Dec. 30, 2017, 5:09 p.m. UTC | #1
Hi,

On Sat, Dec 30, 2017 at 11:44 AM, wm4 <nfxjfg@googlemail.com> wrote:

> There is no POSIX error code for EOF - recv() signals EOF by simply
> returning 0. But libavformat recently changed its conventionts and
> requires an explicit AVERROR_EOF, or it might get into an endless retry
> loop, consuming 100% CPU while doing nothing.
> ---
>  libavformat/tcp.c | 2 ++
>  1 file changed, 2 insertions(+)
>
> diff --git a/libavformat/tcp.c b/libavformat/tcp.c
> index fef0729da6..8773493df1 100644
> --- a/libavformat/tcp.c
> +++ b/libavformat/tcp.c
> @@ -225,6 +225,8 @@ static int tcp_read(URLContext *h, uint8_t *buf, int
> size)
>              return ret;
>      }
>      ret = recv(s->fd, buf, size, 0);
> +    if (ret == 0)
> +        return AVERROR_EOF;
>      return ret < 0 ? ff_neterrno() : ret;
>  }


OK.

Ronald
Aaron Levinson Dec. 30, 2017, 9:22 p.m. UTC | #2
On 12/30/2017 8:44 AM, wm4 wrote:
> There is no POSIX error code for EOF - recv() signals EOF by simply
> returning 0. But libavformat recently changed its conventionts and

"conventionts" -> "conventions"

> requires an explicit AVERROR_EOF, or it might get into an endless retry
> loop, consuming 100% CPU while doing nothing.
> ---
>   libavformat/tcp.c | 2 ++
>   1 file changed, 2 insertions(+)
> 
> diff --git a/libavformat/tcp.c b/libavformat/tcp.c
> index fef0729da6..8773493df1 100644
> --- a/libavformat/tcp.c
> +++ b/libavformat/tcp.c
> @@ -225,6 +225,8 @@ static int tcp_read(URLContext *h, uint8_t *buf, int size)
>               return ret;
>       }
>       ret = recv(s->fd, buf, size, 0);
> +    if (ret == 0)
> +        return AVERROR_EOF;
>       return ret < 0 ? ff_neterrno() : ret;
>   }
>   
> 

LGTM
wm4 Dec. 31, 2017, 3:18 p.m. UTC | #3
On Sat, 30 Dec 2017 13:22:37 -0800
Aaron Levinson <alevinsn_dev@levland.net> wrote:

> On 12/30/2017 8:44 AM, wm4 wrote:
> > There is no POSIX error code for EOF - recv() signals EOF by simply
> > returning 0. But libavformat recently changed its conventionts and  
> 
> "conventionts" -> "conventions"
> 
> > requires an explicit AVERROR_EOF, or it might get into an endless retry
> > loop, consuming 100% CPU while doing nothing.
> > ---
> >   libavformat/tcp.c | 2 ++
> >   1 file changed, 2 insertions(+)
> > 
> > diff --git a/libavformat/tcp.c b/libavformat/tcp.c
> > index fef0729da6..8773493df1 100644
> > --- a/libavformat/tcp.c
> > +++ b/libavformat/tcp.c
> > @@ -225,6 +225,8 @@ static int tcp_read(URLContext *h, uint8_t *buf, int size)
> >               return ret;
> >       }
> >       ret = recv(s->fd, buf, size, 0);
> > +    if (ret == 0)
> > +        return AVERROR_EOF;
> >       return ret < 0 ? ff_neterrno() : ret;
> >   }
> >   
> >   
> 
> LGTM

Pushed, with the typo fixed.
diff mbox

Patch

diff --git a/libavformat/tcp.c b/libavformat/tcp.c
index fef0729da6..8773493df1 100644
--- a/libavformat/tcp.c
+++ b/libavformat/tcp.c
@@ -225,6 +225,8 @@  static int tcp_read(URLContext *h, uint8_t *buf, int size)
             return ret;
     }
     ret = recv(s->fd, buf, size, 0);
+    if (ret == 0)
+        return AVERROR_EOF;
     return ret < 0 ? ff_neterrno() : ret;
 }