Yang Tse wrote: > Mason wrote: > >> Yang Tse wrote: >> >>> Do you have a system on which current git version detection of >>> getaddrinfo() thread-safeness is wrong? >> >> It doesn't work with lwip, where, in the typical configuration, >> >> 1) gethostbyname is not thread-safe >> 2) getaddrinfo is thread-safe (AFAICT) >> 3) netdb.h declares extern int h_errno; (as permitted by POSIX) > > Given that current LWIP git version [1] lwip_getaddrinfo() > implementation is using atoi() and that lwip_getaddrinfo() header does > not state that it is thread safe, and given that [1] > lwip_gethostbyname_r() header comment states that "Thread-safe variant > of lwip_gethostbyname: instead of using a static buffer, this function > takes buffer and errno pointers as arguments and uses these for the > result." I can only conclude that: > > lwip_getaddrinfo() is not thread-safe and that lwip_gethostbyname_r() > is thtread-safe.
I do not follow your assertion that "lwip_getaddrinfo is not thread-safe because it uses atoi". POSIX provides an exhaustive list of "not thread-safe" functions. (The exact wording is: "All functions defined by this volume of IEEE Std 1003.1-2001 [sic] shall be thread-safe, except that the following functions need not be thread-safe.") cf. http://pubs.opengroup.org/onlinepubs/009695399/functions/xsh_chap02_09.html Neither atoi nor strtol are mentioned in the list, therefore atoi and strtol must be thread-safe on POSIX-compliant implementations (otherwise it's an implementation bug, which may happen). Are you saying atoi is not thread-safe because it might call isspace, which might be affected by setlocale? >> I'll take a look at the getaddrinfo code in FreeBSD 4 to understand >> why libcurl declare this implementation not thread-safe. Do you know, >> off-hand? > > Implementation of getaddrinfo() in FreeBSD 5.4 and older versions is > not thread-safe [2]. FreeBSD 5.5 and newer versions have a thread-safe > getaddrinfo(). Relevant bug report (for my own reference) http://www.freebsd.org/cgi/query-pr.cgi?pr=60477 > Up to now lwip_gethostbyname_r() is the right choice and not defining > HAVE_GETADDRINFO_THREADSAFE the proper result for the getaddrinfo() > thread-safeness check when using LWIP. IIUC, libcurl prefers a thread-safe getaddrinfo over gethostbyname_r, right? > If in any future things change we'll adapt as required when the moment > arrives. Roger that. > [1] > http://git.savannah.gnu.org/gitweb/?p=lwip.git;a=blob;f=src/api/netdb.c;h=6a4bac561ce65ee0f599608705cdaae5174ef93e;hb=HEAD > [2] > http://www.freebsd.org/cgi/man.cgi?query=getaddrinfo&sektion=3&manpath=FreeBSD+5.4-RELEASE -- Regards. ------------------------------------------------------------------- List admin: http://cool.haxx.se/list/listinfo/curl-library Etiquette: http://curl.haxx.se/mail/etiquette.html
