cURL / Mailing Lists / curl-library / Single Mail

curl-library

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

From: Constantine Sapuntzakis <csapuntz_at_gmail.com>
Date: Fri, 25 Sep 2009 15:37:59 -0700

> Hey, this is nice. Much cleaner and nicer than my implementation (mainly

Thanks! Attached a new version that should address your comments.

>
> - curl_thread_t_null should be used in curl_thread_join for windows,
>  instead of a literal NULL

Fixed. Also setting *hnd instead of hnd

> - The definition of *tsd in gethostbyname_complete looks truly evil.
>  I think that's worth splitting out. (Also getaddrinfo_complete)

Wrapped.

> - You've reverted to itoa() in getaddrinfo_thread. Please use snprintf
>  with NI_MAXSERV - this is more portable. itoa() doesn't exist in
>  POSIX.
>
>   char service[NI_MAXSERV];
>   snprintf(service, sizeof(service), "%d", tsd->port);

Fixed

> - The "shouldn't be reached" bit in Curl_is_resolved should probably be
>  a DEBUGASSERT as well.

Fixed

> Do we have any sense of what we're going to do about the dummy_sock
> stuff? Is there a better way?

So, on UNIX, you can create a nonblocking socketpair and then write a byte
to it at the end of the resolver threads to wake up the main thread.

On Windows, no socketpairs, select doesn't work on pipes. One would have to use
an Event, but select doesn't work on events. So easiest thing to do is
just to poll.

Easiest thing to do overall is to keep the Windows and POSIX
implementations similar
- polling. select with no sockets ok on Unix, so I #ifdef _WIN32 the
dummy socket
creation in the latest patch attached.

Eventually, we may want to support registering a callback that gets
run an the end of the resolve thread, so
Win32 programmers who want to go the extra distance can wakeup the
main thread when resolve is done
instead of polling.

Patch also fixed up error handling in init_resolve_thread.

BTW, if we move the thread library out of hostthre.c, we can register
openssl thread handlers and make the curl DNS cache thread safe by
default on POSIX platforms and Win32. That's a lot of Makefile work
though. Maybe in a later patch.

-Costa

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

Received on 2009-09-26