cURL
Haxx ad
libcurl

Shopping cart software, Online file storage, Online photo storage, Hosted shopping cart, Contact management software, Email marketing software, Project management software, Issue tracking software, Online notepad, Web publishing software

curl's project page on SourceForge.net

Sponsors:
Haxx

cURL > Mailing List > Monthly Index > Single Mail

curl-library Archives

Re: [PATCH, RFC] Make hostthre.c work on POSIX

From: Jamie Lokier <jamie_at_shareable.org>
Date: Fri, 13 Nov 2009 02:24:15 +0000

Yang Tse wrote:
> 2009/11/12, Constantine Sapuntzakis wrote:
>
> > > The same way as other functions check for specific function
> > > capabilities, the getaddrinfo function check now will also attempt to
> > > find out if it happens to be threadsafe.
> >
> > Looking at your recent checkin... getaddrinfo is also probably thread
> > safe if gethostbyname_r exists.
> > I think it would be most straightforward HAVE_GETADDRINFO_THREADSAFE
> > be defined to 1 then too.
>
> Nope, better not go that route. Each system libraries have their own
> quirks, and the configure script should not make any assumtions that
> jump across functions existance and capabilities. This configure
> script runs on all sorts of systems new and ancient.
>
> Take for example systems that expose all four getaddrinfo,
> gethostbyname, getaddrinfo_r and gethostbyname_r, when this happens
> the non *_r functions might not be threadsafe while the *_r ones are
> granted to be so.

There is no need for getaddrinfo_r, because getaddrinfo is *already*
defined as a thread-safe, reentrant interface.

From a thread-safety point of view, getaddrinfo is like
gethostbyname_r, not like gethostbyname.

The only problem with getaddrinfo is that some people implemented it
as a wrapper around gethostbyname, or around other DNS functions,
without using a lock to make that thread safe. (And some people did
use a lock, which makes it thread safe but not concurrent. Oh well!)

They did that because getaddrinfo is another standard interface, worth
providing.

As far as I know, nobody has ever implemented gethostbyname_r as a
stupid thread-unsafe wrapper around gethostbyname. After all, what
would be the point in that?

That's why the presence of gethostbyname_r could be a clue that the
resolver implementation is thread safe, or can be used that way, and
so getaddrinfo is likely to be thread safe to. Even if getaddrinfo is
a wrapper, it is likely to be wrapping around gethostbyname_r in that
case.

I don't know if presence of gethostbyname_r really means getaddrinfo
is thread-safe, but it's a good idea.

In my own code I'm currently assuming getaddrinfo is thread-safe on
unknown platforms (because it is part of it's specification), which
means I have a special check only BSDs, where version checks are
needed. I'm tempted to find out of the BSDs switched to thread-safe
getaddrinfo at the same time as providing gethostbyname_r, in which
case I'd change the test to look for that.

-- Jamie
-------------------------------------------------------------------
List admin: http://cool.haxx.se/list/listinfo/curl-library
Etiquette: http://curl.haxx.se/mail/etiquette.html
Received on 2009-11-13

These mail archives are generated by hypermail.

donate! Page updated November 16, 2009.
web site info

File upload with ASP.NET