cURL / Mailing Lists / curl-library / Single Mail

curl-library

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

From: Joshua Kwan <jkwan_at_vmware.com>
Date: Thu, 24 Sep 2009 13:36:34 -0700

Hey all,

A bit of background on this diff. Until recently the app that I am
working on used cURL compiled with c-ares on Mac OS X. However, c-ares
on POSIX considers /etc/resolv.conf the canonical source of DNS
information. However, the way Mac OS X's native DNS lookup calls handle
it is much more complicated in the case of having multiple active
network interfaces (in my case, a normal Internet connection and a VPN
tunnel on top of it.)

In these cases it was found that apps like Safari would be able to
resolve a name on the VPN, whereas c-ares could not. Certain console
apps worked fine as well and we discovered that these applications
used getaddrinfo() for DNS resolution. Hacking the open source bits of
OS X's resolver and C libraries revealed that getaddrinfo() on OS X
wraps the "canonical" DNS logic provided by their private APIs in a BSD
compatible shim.

So we chose to drop c-ares on Mac OS X and instead do what is done for
Windows in hostthre.c: do a threaded getaddrinfo() resolve. To this end,
I genericized the code in hostthre.c to be compilable on both Windows
and Mac, by using macros to abstract away the competing threading
idioms. (Despite certain wrinkles, they are actually quite similar.)

The code now compiles and works properly on OS X and reasonably modern
Linuxes with pthreads. Additionally, I've reworked the configure script
so that it will choose threaded resolve when pthreads are available but
c-ares is not. I've also regression tested the whole thing on Windows XP
and above.

Now I know we've been talking about fixing things in hostthre.c with
regards to race conditions and timeouts; I would be fully amenable to
revising the patch to take into account whatever is finally decided on
that front. Alternatively, we can leave hostthre.c in its current state
and create a copy (e.g. hostpthr.c) that is used for POSIX thread
implementations only.

Let the discussion begin!

-- 
Joshua Kwan


-------------------------------------------------------------------
List admin: http://cool.haxx.se/list/listinfo/curl-library
Etiquette: http://curl.haxx.se/mail/etiquette.html

Received on 2009-09-24