[FFmpeg-devel] [patch] error codes for http/tcp

Ronald S. Bultje rsbultje
Sat Jun 23 16:42:52 CEST 2007


Hi,

On 6/23/07, Michael Niedermayer <michaelni at gmx.at> wrote:
>
> On Fri, Jun 22, 2007 at 08:18:46AM -0400, Ronald S. Bultje wrote:
> > Index: ffmpeg-mpe/libavformat/tcp.c
> > ===================================================================
> > --- ffmpeg-mpe.orig/libavformat/tcp.c 2007-03-22 21:28:04.000000000-0400
> > +++ ffmpeg-mpe/libavformat/tcp.c      2007-03-22 21:29:17.000000000-0400
> > @@ -65,17 +65,26 @@
> >          return AVERROR(ENOMEM);
> >      h->priv_data = s;
> >
> > -    if (port <= 0 || port >= 65536)
> > +    if (port <= 0 || port >= 65536) {
> > +        ret = AVERROR(EINVAL);
> >          goto fail;
> > +    }
> >
> >      dest_addr.sin_family = AF_INET;
> >      dest_addr.sin_port = htons(port);
> > -    if (resolve_host(&dest_addr.sin_addr, hostname) < 0)
> > -        goto fail;
> > -
> > +    if (resolve_host(&dest_addr.sin_addr, hostname) < 0) {
> > +        switch (h_errno) {
>
> this is not thread safe (resolve_host() is implemented by gethostbyname()
> which is thread unsafe and the tread safe gethostbyname_r() does not set
> h_errno)


According to [1], some OSes use thread-local memory. I honestly have no idea
what Linux does (OS X has no *_r() GNU extensions as far as I can see).
Anyway, patch attached (I think this is the best you can get, so it won't be
threadsafe on all platforms, but what can you do...).

I modified resolve_host() to allow for returning h_errno as in
gethostbyname_r() and changed tcp.c for the change in the function
declaration (I'll actually use it in my errno-patch which I'll re-send after
this is applied). Is this a public API change? I can put an #ifdef version<x
around it as is done in other places.

Ronald

[1] http://osdir.com/ml/org.netlabs.libc.user/2005-12/msg00024.html
-------------- next part --------------
A non-text attachment was scrubbed...
Name: gethostbyname-r.patch
Type: application/octet-stream
Size: 2624 bytes
Desc: not available
URL: <http://lists.mplayerhq.hu/pipermail/ffmpeg-devel/attachments/20070623/5c942e42/attachment.obj>



More information about the ffmpeg-devel mailing list