Remove !g_thread_supported() codepaths in gio
authorDan Winship <danw@gnome.org>
Wed, 31 Aug 2011 18:33:33 +0000 (14:33 -0400)
committerRyan Lortie <desrt@desrt.ca>
Fri, 9 Sep 2011 16:47:39 +0000 (12:47 -0400)
In particular, remove the libasyncns import, which was only used by
GUnixResolver, which is only used when threads are not available.
Likewise remove GWin32Resolver, and the hacky broken non-threaded
parts of GIOScheduler.

https://bugzilla.gnome.org/show_bug.cgi?id=616754

18 files changed:
configure.ac
gio/Makefile.am
gio/gcancellable.c
gio/gio.symbols
gio/gioscheduler.c
gio/gresolver.c
gio/gthreadedresolver.c
gio/gunixresolver.c [deleted file]
gio/gunixresolver.h [deleted file]
gio/gwin32resolver.c [deleted file]
gio/gwin32resolver.h [deleted file]
gio/libasyncns/Makefile.am [deleted file]
gio/libasyncns/README [deleted file]
gio/libasyncns/asyncns.c [deleted file]
gio/libasyncns/asyncns.h [deleted file]
gio/libasyncns/g-asyncns.h [deleted file]
gio/libasyncns/update.sh [deleted file]
gio/tests/resolver.c

index 3ca84d8..91428d6 100644 (file)
@@ -1065,11 +1065,7 @@ fi
 AC_CHECK_FUNCS(getprotobyname_r endservent)
 AC_CHECK_HEADERS([netdb.h wspiapi.h arpa/nameser_compat.h])
 
-# For gio/libasyncns
 if test $glib_native_win32 = no; then
-  AC_CHECK_FUNCS(strndup setresuid setreuid)
-  AC_CHECK_HEADERS(sys/prctl.h)
-
   # We can't just use AC_CHECK_FUNC/AC_CHECK_LIB here. Bug 586150
   NETWORK_LIBS=""
   AC_MSG_CHECKING([for res_query])
@@ -3842,7 +3838,6 @@ gio/gdbus-2.0/codegen/Makefile
 gio/gdbus-2.0/codegen/config.py
 gio/xdgmime/Makefile
 gio/inotify/Makefile
-gio/libasyncns/Makefile
 gio/fen/Makefile
 gio/fam/Makefile
 gio/win32/Makefile
index 42fac22..c6eba9d 100644 (file)
@@ -5,7 +5,7 @@ NULL =
 SUBDIRS = gdbus-2.0/codegen
 
 if OS_UNIX
-SUBDIRS += libasyncns xdgmime
+SUBDIRS += xdgmime
 endif
 
 if OS_WIN32_AND_DLL_COMPILATION
@@ -200,8 +200,8 @@ endif
 
 if OS_UNIX
 appinfo_sources += gdesktopappinfo.c
-platform_libadd += libasyncns/libasyncns.la xdgmime/libxdgmime.la
-platform_deps += libasyncns/libasyncns.la xdgmime/libxdgmime.la
+platform_libadd += xdgmime/libxdgmime.la $(RESOLVER_LIBADD)
+platform_deps += xdgmime/libxdgmime.la
 unix_sources = \
        gfiledescriptorbased.c  \
        gunixconnection.c       \
@@ -211,8 +211,6 @@ unix_sources = \
        gunixmount.c            \
        gunixmount.h            \
        gunixmounts.c           \
-       gunixresolver.c         \
-       gunixresolver.h         \
        gunixsocketaddress.c    \
        gunixvolume.c           \
        gunixvolume.h           \
@@ -241,8 +239,6 @@ endif
 win32_actual_sources = \
        gwin32mount.c \
        gwin32mount.h \
-       gwin32resolver.c \
-       gwin32resolver.h \
        gwin32volumemonitor.c \
        gwin32volumemonitor.h \
        gwin32inputstream.c \
index 6524934..15d6d0e 100644 (file)
@@ -79,7 +79,7 @@ g_cancellable_class_init (GCancellableClass *klass)
 
   g_type_class_add_private (klass, sizeof (GCancellablePrivate));
 
-  if (cancellable_cond == NULL && g_thread_supported ())
+  if (cancellable_cond == NULL)
     cancellable_cond = g_cond_new ();
   
   gobject_class->finalize = g_cancellable_finalize;
index 9451470..abe4b95 100644 (file)
@@ -875,12 +875,6 @@ g_resolver_lookup_service
 g_resolver_lookup_service_async
 g_resolver_lookup_service_finish
 g_threaded_resolver_get_type
-#ifdef G_OS_UNIX
-g_unix_resolver_get_type
-#endif
-#ifdef G_OS_WIN32
-g_win32_resolver_get_type
-#endif
 g_srv_target_get_type
 g_srv_target_new
 g_srv_target_copy
index 61e1afc..960f62c 100644 (file)
@@ -32,8 +32,7 @@
  * @include: gio/gio.h
  * 
  * Schedules asynchronous I/O operations. #GIOScheduler integrates 
- * into the main event loop (#GMainLoop) and may use threads if they 
- * are available.
+ * into the main event loop (#GMainLoop) and uses threads.
  * 
  * <para id="io-priority"><indexterm><primary>I/O priority</primary></indexterm>
  * Each I/O operation has a priority, and the scheduler uses the priorities
@@ -55,8 +54,6 @@ struct _GIOSchedulerJob {
   gint io_priority;
   GCancellable *cancellable;
   GMainContext *context;
-
-  guint idle_tag;
 };
 
 G_LOCK_DEFINE_STATIC(active_jobs);
@@ -188,23 +185,6 @@ io_job_thread (gpointer data,
   job_destroy (job);
 }
 
-static gboolean
-run_job_at_idle (gpointer data)
-{
-  GIOSchedulerJob *job = data;
-  gboolean result;
-
-  if (job->cancellable)
-    g_cancellable_push_current (job->cancellable);
-  
-  result = job->job_func (job, job->cancellable, job->data);
-  
-  if (job->cancellable)
-    g_cancellable_pop_current (job->cancellable);
-
-  return result;
-}
-
 /**
  * g_io_scheduler_push_job:
  * @job_func: a #GIOSchedulerJobFunc.
@@ -253,20 +233,8 @@ g_io_scheduler_push_job (GIOSchedulerJobFunc  job_func,
   job->active_link = active_jobs;
   G_UNLOCK (active_jobs);
 
-  if (g_thread_supported())
-    {
-      g_once (&once_init, init_scheduler, NULL);
-      g_thread_pool_push (job_thread_pool, job, NULL);
-    }
-  else
-    {
-      /* Threads not available, instead do the i/o sync inside a
-       * low prio idle handler
-       */
-      job->idle_tag = g_idle_add_full (io_priority,
-                                      run_job_at_idle,
-                                      job, job_destroy);
-    }
+  g_once (&once_init, init_scheduler, NULL);
+  g_thread_pool_push (job_thread_pool, job, NULL);
 }
 
 /**
@@ -370,17 +338,6 @@ g_io_scheduler_job_send_to_mainloop (GIOSchedulerJob *job,
   g_return_val_if_fail (job != NULL, FALSE);
   g_return_val_if_fail (func != NULL, FALSE);
 
-  if (job->idle_tag)
-    {
-      /* We just immediately re-enter in the case of idles (non-threads)
-       * Anything else would just deadlock. If you can't handle this, enable threads.
-       */
-      ret_val = func (user_data);
-      if (notify)
-       notify (user_data);
-      return ret_val;
-    }
-  
   proxy = g_new0 (MainLoopProxy, 1);
   proxy->func = func;
   proxy->data = user_data;
@@ -435,17 +392,6 @@ g_io_scheduler_job_send_to_mainloop_async (GIOSchedulerJob *job,
   g_return_if_fail (job != NULL);
   g_return_if_fail (func != NULL);
 
-  if (job->idle_tag)
-    {
-      /* We just immediately re-enter in the case of idles (non-threads)
-       * Anything else would just deadlock. If you can't handle this, enable threads.
-       */
-      func (user_data);
-      if (notify)
-       notify (user_data);
-      return;
-    }
-  
   proxy = g_new0 (MainLoopProxy, 1);
   proxy->func = func;
   proxy->data = user_data;
index d08b3b5..433b23d 100644 (file)
 #include "ginetsocketaddress.h"
 #include "gsimpleasyncresult.h"
 #include "gsrvtarget.h"
+#include "gthreadedresolver.h"
 
 #ifdef G_OS_UNIX
-#include "gunixresolver.h"
 #include <sys/stat.h>
 #endif
-#ifdef G_OS_WIN32
-#include "gwin32resolver.h"
-#endif
 
 #include <stdlib.h>
 
@@ -153,18 +150,7 @@ GResolver *
 g_resolver_get_default (void)
 {
   if (!default_resolver)
-    {
-      if (g_thread_supported ())
-        default_resolver = g_object_new (G_TYPE_THREADED_RESOLVER, NULL);
-      else
-        {
-#if defined(G_OS_UNIX)
-          default_resolver = g_object_new (G_TYPE_UNIX_RESOLVER, NULL);
-#elif defined(G_OS_WIN32)
-          default_resolver = g_object_new (G_TYPE_WIN32_RESOLVER, NULL);
-#endif
-        }
-    }
+    default_resolver = g_object_new (G_TYPE_THREADED_RESOLVER, NULL);
 
   return g_object_ref (default_resolver);
 }
index 4069048..7412bcd 100644 (file)
@@ -42,9 +42,8 @@ static void threaded_resolver_thread (gpointer thread_data, gpointer pool_data);
 static void
 g_threaded_resolver_init (GThreadedResolver *gtr)
 {
-  if (g_thread_supported ())
-    gtr->thread_pool = g_thread_pool_new (threaded_resolver_thread, gtr,
-                                          -1, FALSE, NULL);
+  gtr->thread_pool = g_thread_pool_new (threaded_resolver_thread, gtr,
+                                        -1, FALSE, NULL);
 }
 
 static void
@@ -186,8 +185,7 @@ g_threaded_resolver_request_new (GThreadedResolverResolveFunc  resolve_func,
   /* Initial refcount is 2; one for the caller and one for resolve_func */
   req->ref_count = 2;
 
-  if (g_thread_supported ())
-    req->mutex = g_mutex_new ();
+  req->mutex = g_mutex_new ();
   /* Initially locked; caller must unlock */
   g_mutex_lock (req->mutex);
 
diff --git a/gio/gunixresolver.c b/gio/gunixresolver.c
deleted file mode 100644 (file)
index 9f430ec..0000000
+++ /dev/null
@@ -1,516 +0,0 @@
-/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */
-
-/* GIO - GLib Input, Output and Streaming Library
- *
- * Copyright (C) 2008 Red Hat, Inc.
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General
- * Public License along with this library; if not, write to the
- * Free Software Foundation, Inc., 59 Temple Place, Suite 330,
- * Boston, MA 02111-1307, USA.
- */
-
-#include "config.h"
-#include <glib.h>
-#include "glibintl.h"
-
-#include <stdio.h>
-#include <string.h>
-
-#include "gunixresolver.h"
-#include "gnetworkingprivate.h"
-
-#include "gcancellable.h"
-#include "gsimpleasyncresult.h"
-#include "gsocketaddress.h"
-
-
-G_DEFINE_TYPE (GUnixResolver, g_unix_resolver, G_TYPE_THREADED_RESOLVER)
-
-static gboolean g_unix_resolver_watch (GIOChannel   *iochannel,
-                                       GIOCondition  condition,
-                                       gpointer      user_data);
-static void g_unix_resolver_reload (GResolver *resolver);
-
-static void
-g_unix_resolver_init (GUnixResolver *gur)
-{
-  g_unix_resolver_reload (G_RESOLVER (gur));
-}
-
-static void
-g_unix_resolver_finalize (GObject *object)
-{
-  GUnixResolver *gur = G_UNIX_RESOLVER (object);
-
-  if (gur->watch)
-    g_source_remove (gur->watch);
-  _g_asyncns_free (gur->asyncns);
-
-  G_OBJECT_CLASS (g_unix_resolver_parent_class)->finalize (object);
-}
-
-static void
-g_unix_resolver_reload (GResolver *resolver)
-{
-  GUnixResolver *gur = G_UNIX_RESOLVER (resolver);
-  gint fd;
-  GIOChannel *io;
-
-  if (gur->asyncns)
-    {
-      if (_g_asyncns_getnqueries (gur->asyncns) == 0)
-        {
-          g_source_remove (gur->watch);
-          _g_asyncns_free (gur->asyncns);
-        }
-      /* else, we will free it later from g_unix_resolver_watch */
-    }
-
-  /* FIXME: how many workers? */
-  gur->asyncns = _g_asyncns_new (2);
-
-  fd = _g_asyncns_fd (gur->asyncns);
-  io = g_io_channel_unix_new (fd);
-  gur->watch = g_io_add_watch (io, G_IO_IN | G_IO_HUP | G_IO_ERR,
-                               g_unix_resolver_watch, gur->asyncns);
-  g_io_channel_unref (io);
-}
-
-/* The various request possibilities:
- *
- * 1. Synchronous: handed off to the base class (GThreadedResolver);
- *    since it's never possible to cancel a synchronous request in a
- *    single-threaded program, the request is done in the calling
- *    thread.
- *
- * 2. Asynchronous: An appropriate _g_asyncns_query_t is created, and
- *    then a GUnixResolverRequest is created with that query and a
- *    GSimpleAsyncResult. Two sub-possibilities:
- *
- *      a. The resolution completes: g_unix_resolver_watch() sees that
- *         the request has completed, and calls
- *         g_unix_resolver_request_complete(), which detaches the
- *         "cancelled" signal handler (if it was present), queues the
- *         async_result to be completed, and then unrefs it.
- *
- *      b. The resolution is cancelled: request_cancelled() calls
- *         _g_asyncns_cancel() to cancel the resolution. Then it calls
- *         g_unix_resolver_request_complete(), which detaches the
- *         signal handler, and queues async_result to complete in an
- *         idle handler. Because the asyncns resolution was cancelled,
- *         g_unix_resolver_watch() will never be triggered for this
- *         req.
- *
- *    Since there's only a single thread, it's not possible for the
- *    request to both complete and be cancelled "at the same time",
- *    and each of the two possibilities takes steps to block the other
- *    from being able to happen later, so it's always safe to free req
- *    after the async_result completes.
- */
-
-typedef struct _GUnixResolverRequest GUnixResolverRequest;
-typedef void (*GUnixResolverFunc) (GUnixResolverRequest *);
-
-struct _GUnixResolverRequest {
-  GUnixResolver *gur;
-  _g_asyncns_t *asyncns;
-
-  _g_asyncns_query_t *qy;
-  union {
-    struct {
-      gchar *hostname;
-      GList *addresses;
-    } name;
-
-    struct {
-      GInetAddress *address;
-      gchar *hostname;
-    } address;
-
-    struct {
-      gchar *service;
-      GList *targets;
-    } service;
-  } u;
-  GUnixResolverFunc process_func, free_func;
-
-  GCancellable *cancellable;
-  GSimpleAsyncResult *async_result;
-
-};
-
-static void g_unix_resolver_request_free (GUnixResolverRequest *req);
-static void request_cancelled (GCancellable *cancellable,
-                               gpointer      user_data);
-
-static GUnixResolverRequest *
-g_unix_resolver_request_new (GUnixResolver         *gur,
-                             _g_asyncns_query_t    *qy,
-                             GUnixResolverFunc      process_func,
-                             GUnixResolverFunc      free_func,
-                             GCancellable          *cancellable,
-                             GSimpleAsyncResult    *async_result)
-{
-  GUnixResolverRequest *req;
-
-  req = g_slice_new0 (GUnixResolverRequest);
-  req->gur = g_object_ref (gur);
-  req->asyncns = gur->asyncns;
-  req->qy = qy;
-  req->process_func = process_func;
-  req->free_func = free_func;
-
-  if (cancellable)
-    {
-      req->cancellable = g_object_ref (cancellable);
-      g_signal_connect (cancellable, "cancelled",
-                        G_CALLBACK (request_cancelled), req);
-    }
-
-  req->async_result = g_object_ref (async_result);
-
-  g_simple_async_result_set_op_res_gpointer (req->async_result, req, (GDestroyNotify)g_unix_resolver_request_free);
-
-  return req;
-}
-
-static void
-g_unix_resolver_request_free (GUnixResolverRequest *req)
-{
-  req->free_func (req);
-
-  /* We don't have to free req->cancellable and req->async_result,
-   * since they must already have been freed if we're here.
-   */
-
-  /* Check if this was the last request remaining on an old asyncns. */
-  if (req->asyncns != req->gur->asyncns &&
-      _g_asyncns_getnqueries (req->asyncns) == 0)
-    _g_asyncns_free (req->asyncns);
-
-  g_object_unref (req->gur);
-  g_slice_free (GUnixResolverRequest, req);
-}
-
-static void
-g_unix_resolver_request_complete (GUnixResolverRequest *req)
-{
-  if (req->cancellable)
-    {
-      g_signal_handlers_disconnect_by_func (req->cancellable, request_cancelled, req);
-      g_object_unref (req->cancellable);
-      req->cancellable = NULL;
-    }
-
-  /* We always complete_in_idle, even if we were called from
-   * g_unix_resolver_watch(), since we might have been started under a
-   * non-default g_main_context_get_thread_default().
-   */
-  g_simple_async_result_complete_in_idle (req->async_result);
-  g_object_unref (req->async_result);
-}
-
-static void
-request_cancelled (GCancellable *cancellable,
-                   gpointer      user_data)
-{
-  GUnixResolverRequest *req = user_data;
-  GError *error = NULL;
-
-  _g_asyncns_cancel (req->asyncns, req->qy);
-  req->qy = NULL;
-
-  g_cancellable_set_error_if_cancelled (cancellable, &error);
-  g_simple_async_result_take_error (req->async_result, error);
-
-  g_unix_resolver_request_complete (req);
-}
-
-static gboolean
-g_unix_resolver_watch (GIOChannel   *iochannel,
-                       GIOCondition  condition,
-                       gpointer      user_data)
-{
-  _g_asyncns_t *asyncns = user_data;
-  _g_asyncns_query_t *qy;
-  GUnixResolverRequest *req;
-
-  if (condition & (G_IO_HUP | G_IO_ERR))
-    {
-      /* Will happen if we reload, and then eventually kill the old
-       * _g_asyncns_t when it's done processing requests.
-       */
-      return FALSE;
-    }
-
-  while (_g_asyncns_wait (asyncns, FALSE) == 0 &&
-         (qy = _g_asyncns_getnext (asyncns)) != NULL)
-    {
-      req = _g_asyncns_getuserdata (asyncns, qy);
-      req->process_func (req);
-      g_unix_resolver_request_complete (req);
-    }
-
-  return TRUE;
-}
-
-static GUnixResolverRequest *
-resolve_async (GUnixResolver         *gur,
-               _g_asyncns_query_t    *qy,
-               GUnixResolverFunc      process_func,
-               GUnixResolverFunc      free_func,
-               GCancellable          *cancellable,
-               GAsyncReadyCallback    callback,
-               gpointer               user_data,
-               gpointer               tag)
-{
-  GSimpleAsyncResult *result;
-  GUnixResolverRequest *req;
-
-  result = g_simple_async_result_new (G_OBJECT (gur), callback, user_data, tag);
-  req = g_unix_resolver_request_new (gur, qy, process_func, free_func,
-                                     cancellable, result);
-  g_object_unref (result);
-  _g_asyncns_setuserdata (gur->asyncns, qy, req);
-
-  return req;
-}
-
-static void
-lookup_by_name_process (GUnixResolverRequest *req)
-{
-  struct addrinfo *res;
-  gint retval;
-  GError *error = NULL;
-
-  retval = _g_asyncns_getaddrinfo_done (req->asyncns, req->qy, &res);
-  req->u.name.addresses =
-    _g_resolver_addresses_from_addrinfo (req->u.name.hostname,
-                                         res, retval, &error);
-  if (res)
-    freeaddrinfo (res);
-
-  if (error)
-    g_simple_async_result_take_error (req->async_result, error);
-}
-
-static void
-lookup_by_name_free (GUnixResolverRequest *req)
-{
-  g_free (req->u.name.hostname);
-  if (req->u.name.addresses)
-    g_resolver_free_addresses (req->u.name.addresses);
-}
-
-static void
-lookup_by_name_async (GResolver           *resolver,
-                      const gchar         *hostname,
-                      GCancellable        *cancellable,
-                      GAsyncReadyCallback  callback,
-                      gpointer             user_data)
-{
-  GUnixResolver *gur = G_UNIX_RESOLVER (resolver);
-  GUnixResolverRequest *req;
-  _g_asyncns_query_t *qy;
-
-  qy = _g_asyncns_getaddrinfo (gur->asyncns, hostname, NULL,
-                               &_g_resolver_addrinfo_hints);
-  req = resolve_async (gur, qy, lookup_by_name_process, lookup_by_name_free,
-                       cancellable, callback, user_data, lookup_by_name_async);
-  req->u.name.hostname = g_strdup (hostname);
-}
-
-static GList *
-lookup_by_name_finish (GResolver     *resolver,
-                       GAsyncResult  *result,
-                       GError       **error)
-{
-  GSimpleAsyncResult *simple;
-  GUnixResolverRequest *req;
-  GList *addresses;
-
-  g_return_val_if_fail (g_simple_async_result_is_valid (result, G_OBJECT (resolver), lookup_by_name_async), NULL);
-
-  simple = G_SIMPLE_ASYNC_RESULT (result);
-
-  if (g_simple_async_result_propagate_error (simple, error))
-    return NULL;
-
-  req = g_simple_async_result_get_op_res_gpointer (simple);
-  addresses = req->u.name.addresses;
-  req->u.name.addresses = NULL;
-
-  return addresses;
-}
-
-
-static void
-lookup_by_address_process (GUnixResolverRequest *req)
-{
-  gchar host[NI_MAXHOST];
-  gint retval;
-  GError *error = NULL;
-
-  retval = _g_asyncns_getnameinfo_done (req->asyncns, req->qy,
-                                        host, sizeof (host), NULL, 0);
-  req->u.address.hostname =
-    _g_resolver_name_from_nameinfo (req->u.address.address,
-                                    host, retval, &error);
-
-  if (error)
-    g_simple_async_result_take_error (req->async_result, error);
-}
-
-static void
-lookup_by_address_free (GUnixResolverRequest *req)
-{
-  g_object_unref (req->u.address.address);
-  if (req->u.address.hostname)
-    g_free (req->u.address.hostname);
-}
-
-static void
-lookup_by_address_async (GResolver           *resolver,
-                         GInetAddress        *address,
-                         GCancellable        *cancellable,
-                         GAsyncReadyCallback  callback,
-                         gpointer             user_data)
-{
-  GUnixResolver *gur = G_UNIX_RESOLVER (resolver);
-  GUnixResolverRequest *req;
-  _g_asyncns_query_t *qy;
-  struct sockaddr_storage sockaddr;
-  gsize sockaddr_size;
-
-  _g_resolver_address_to_sockaddr (address, &sockaddr, &sockaddr_size);
-  qy = _g_asyncns_getnameinfo (gur->asyncns,
-                               (struct sockaddr *)&sockaddr, sockaddr_size,
-                               NI_NAMEREQD, TRUE, FALSE);
-  req = resolve_async (gur, qy, lookup_by_address_process,
-                       lookup_by_address_free, cancellable,
-                       callback, user_data, lookup_by_address_async);
-  req->u.address.address = g_object_ref (address);
-}
-
-static gchar *
-lookup_by_address_finish (GResolver     *resolver,
-                          GAsyncResult  *result,
-                          GError       **error)
-{
-  GSimpleAsyncResult *simple;
-  GUnixResolverRequest *req;
-  gchar *name;
-
-  g_return_val_if_fail (g_simple_async_result_is_valid (result, G_OBJECT (resolver), lookup_by_address_async), NULL);
-
-  simple = G_SIMPLE_ASYNC_RESULT (result);
-
-  if (g_simple_async_result_propagate_error (simple, error))
-    return NULL;
-
-  req = g_simple_async_result_get_op_res_gpointer (simple);
-  name = req->u.address.hostname;
-  req->u.address.hostname = NULL;
-
-  return name;
-}
-
-
-static void
-lookup_service_process (GUnixResolverRequest *req)
-{
-  guchar *answer;
-  gint len, herr;
-  GError *error = NULL;
-
-  len = _g_asyncns_res_done (req->asyncns, req->qy, &answer);
-  if (len < 0)
-    herr = h_errno;
-  else
-    herr = 0;
-
-  req->u.service.targets =
-    _g_resolver_targets_from_res_query (req->u.service.service,
-                                        answer, len, herr, &error);
-  _g_asyncns_freeanswer (answer);
-
-  if (error)
-    g_simple_async_result_take_error (req->async_result, error);
-}
-
-static void
-lookup_service_free (GUnixResolverRequest *req)
-{
-  g_free (req->u.service.service);
-  if (req->u.service.targets)
-    g_resolver_free_targets (req->u.service.targets);
-}
-
-static void
-lookup_service_async (GResolver           *resolver,
-                      const char          *rrname,
-                     GCancellable        *cancellable,
-                      GAsyncReadyCallback  callback,
-                     gpointer             user_data)
-{
-  GUnixResolver *gur = G_UNIX_RESOLVER (resolver);
-  GUnixResolverRequest *req;
-  _g_asyncns_query_t *qy;
-
-  qy = _g_asyncns_res_query (gur->asyncns, rrname, C_IN, T_SRV);
-  req = resolve_async (gur, qy, lookup_service_process, lookup_service_free,
-                       cancellable, callback, user_data, lookup_service_async);
-  req->u.service.service = g_strdup (rrname);
-}
-
-static GList *
-lookup_service_finish (GResolver     *resolver,
-                       GAsyncResult  *result,
-                      GError       **error)
-{
-  GSimpleAsyncResult *simple;
-  GUnixResolverRequest *req;
-  GList *targets;
-
-  g_return_val_if_fail (g_simple_async_result_is_valid (result, G_OBJECT (resolver), lookup_service_async), NULL);
-
-  simple = G_SIMPLE_ASYNC_RESULT (result);
-
-  if (g_simple_async_result_propagate_error (simple, error))
-    return NULL;
-
-  req = g_simple_async_result_get_op_res_gpointer (simple);
-  targets = req->u.service.targets;
-  req->u.service.targets = NULL;
-
-  return targets;
-}
-
-
-static void
-g_unix_resolver_class_init (GUnixResolverClass *unix_class)
-{
-  GResolverClass *resolver_class = G_RESOLVER_CLASS (unix_class);
-  GObjectClass *object_class = G_OBJECT_CLASS (unix_class);
-
-  resolver_class->reload                   = g_unix_resolver_reload;
-  resolver_class->lookup_by_name_async     = lookup_by_name_async;
-  resolver_class->lookup_by_name_finish    = lookup_by_name_finish;
-  resolver_class->lookup_by_address_async  = lookup_by_address_async;
-  resolver_class->lookup_by_address_finish = lookup_by_address_finish;
-  resolver_class->lookup_service_async     = lookup_service_async;
-  resolver_class->lookup_service_finish    = lookup_service_finish;
-
-  object_class->finalize = g_unix_resolver_finalize;
-}
diff --git a/gio/gunixresolver.h b/gio/gunixresolver.h
deleted file mode 100644 (file)
index cf7765b..0000000
+++ /dev/null
@@ -1,53 +0,0 @@
-/* GIO - GLib Input, Output and Streaming Library
- *
- * Copyright (C) 2008 Red Hat, Inc.
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General
- * Public License along with this library; if not, write to the
- * Free Software Foundation, Inc., 59 Temple Place, Suite 330,
- * Boston, MA 02111-1307, USA.
- */
-
-#ifndef __G_UNIX_RESOLVER_H__
-#define __G_UNIX_RESOLVER_H__
-
-#include <gio/gthreadedresolver.h>
-#include "libasyncns/asyncns.h"
-
-G_BEGIN_DECLS
-
-#define G_TYPE_UNIX_RESOLVER         (g_unix_resolver_get_type ())
-#define G_UNIX_RESOLVER(o)           (G_TYPE_CHECK_INSTANCE_CAST ((o), G_TYPE_UNIX_RESOLVER, GUnixResolver))
-#define G_UNIX_RESOLVER_CLASS(k)     (G_TYPE_CHECK_CLASS_CAST((k), G_TYPE_UNIX_RESOLVER, GUnixResolverClass))
-#define G_IS_UNIX_RESOLVER(o)        (G_TYPE_CHECK_INSTANCE_TYPE ((o), G_TYPE_UNIX_RESOLVER))
-#define G_IS_UNIX_RESOLVER_CLASS(k)  (G_TYPE_CHECK_CLASS_TYPE ((k), G_TYPE_UNIX_RESOLVER))
-#define G_UNIX_RESOLVER_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), G_TYPE_UNIX_RESOLVER, GUnixResolverClass))
-
-typedef struct {
-  GThreadedResolver parent_instance;
-
-  _g_asyncns_t *asyncns;
-  guint watch;
-
-} GUnixResolver;
-
-typedef struct {
-  GThreadedResolverClass parent_class;
-
-} GUnixResolverClass;
-
-GType g_unix_resolver_get_type (void) G_GNUC_CONST;
-
-G_END_DECLS
-
-#endif /* __G_RESOLVER_H__ */
diff --git a/gio/gwin32resolver.c b/gio/gwin32resolver.c
deleted file mode 100644 (file)
index 1dd2aad..0000000
+++ /dev/null
@@ -1,483 +0,0 @@
-/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */
-
-/* GIO - GLib Input, Output and Streaming Library
- * 
- * Copyright (C) 2008 Red Hat, Inc.
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General
- * Public License along with this library; if not, write to the
- * Free Software Foundation, Inc., 59 Temple Place, Suite 330,
- * Boston, MA 02111-1307, USA.
- */
-
-#include "config.h"
-#include <glib.h>
-#include "glibintl.h"
-
-#include <stdio.h>
-#include <string.h>
-
-#include "gwin32resolver.h"
-#include "gnetworkingprivate.h"
-
-#include "gcancellable.h"
-#include "gsimpleasyncresult.h"
-#include "gsocketaddress.h"
-
-
-G_DEFINE_TYPE (GWin32Resolver, g_win32_resolver, G_TYPE_THREADED_RESOLVER)
-
-static void
-g_win32_resolver_init (GWin32Resolver *gwr)
-{
-}
-
-/* This is simpler than GThreadedResolver since we don't have to worry
- * about multiple application-level threads, but more complicated than
- * GUnixResolver, since we do have to deal with multiple threads of
- * our own.
- *
- * The various request possibilities:
- *
- * 1. Synchronous: handed off to the base class (GThreadedResolver);
- *    since it's never possible to cancel a synchronous request in a
- *    single-threaded program, the request is done in the calling
- *    thread.
- *
- * 2. Asynchronous: A GWin32ResolverRequest is created with
- *    appropriate query-specific information, a Windows event handle,
- *    and a GSimpleAsyncResult. This is then handed to the
- *    Windows-internal thread pool, which does the raw DNS query part
- *    of the operation (being careful to not call any glib methods
- *    that might fail when called from another thread when
- *    g_thread_init() has not been called). The main thread sets up a
- *    GSource to asynchronously poll the event handle. There are two
- *    sub-possibilities:
- *
- *      a. The resolution completes: the threadpool function calls
- *         SetEvent() on the event handle and then returns.
- *
- *      b. The resolution is cancelled: request_cancelled()
- *         disconnects the "cancelled" signal handler, and queues an
- *         idle handler to complete the async_result.
- *
- *    Since we can't free the request from the threadpool thread
- *    (because of glib locking issues), we *always* have to have it
- *    call SetEvent and trigger the callback to indicate that it is
- *    done. But this means that it's possible for the request to be
- *    cancelled (queuing an idle handler to return that result) and
- *    then have the resolution thread complete before the idle handler
- *    runs. So the event callback and the idle handler need to both
- *    watch out for this, making sure we don't complete the same
- *    result twice.
- */
-
-typedef struct GWin32ResolverRequest GWin32ResolverRequest;
-typedef void (*GWin32ResolverRequestFreeFunc) (GWin32ResolverRequest *);
-
-struct GWin32ResolverRequest {
-  GWin32ResolverRequestFreeFunc free_func;
-
-  GCancellable *cancellable;
-  GError *error;
-
-  HANDLE *event;
-  GSimpleAsyncResult *async_result;
-  gboolean complete;
-  GSource *cancelled_idle;
-
-  union {
-    struct {
-      gchar *name;
-      gint retval;
-      struct addrinfo *res;
-    } name;
-
-    struct {
-      GInetAddress *iaddr;
-      struct sockaddr_storage addr;
-      gsize addrlen;
-      gint retval;
-      gchar *namebuf;
-    } address;
-
-    struct {
-      gchar *rrname;
-      DNS_STATUS retval;
-      DNS_RECORD *results;
-    } service;
-  } u;
-
-};
-
-static GSource *g_win32_handle_source_add (HANDLE      handle,
-                                           GSourceFunc callback,
-                                           gpointer    user_data);
-
-static gboolean request_completed (gpointer      user_data);
-static void     request_cancelled (GCancellable *cancellable,
-                                   gpointer      user_data);
-
-GWin32ResolverRequest *
-g_win32_resolver_request_new (GResolver                     *resolver,
-                              GWin32ResolverRequestFreeFunc  free_func,
-                              GCancellable                  *cancellable,
-                              GAsyncReadyCallback            callback,
-                              gpointer                       user_data,
-                              gpointer                       tag)
-{
-  GWin32ResolverRequest *req;
-
-  req = g_slice_new0 (GWin32ResolverRequest);
-  req->free_func = free_func;
-
-  req->async_result = g_simple_async_result_new (G_OBJECT (resolver), callback,
-                                                 user_data, tag);
-  g_simple_async_result_set_op_res_gpointer (req->async_result, req, NULL);
-
-  req->event = CreateEvent (NULL, FALSE, FALSE, NULL);
-  g_win32_handle_source_add (req->event, request_completed, req);  
-
-  if (cancellable)
-    {
-      req->cancellable = g_object_ref (cancellable);
-      g_signal_connect (cancellable, "cancelled",
-                        G_CALLBACK (request_cancelled), req);
-    }
-
-  return req;
-}
-
-static gboolean
-request_completed (gpointer user_data)
-{
-  GWin32ResolverRequest *req = user_data;
-
-  /* Clean up cancellation-related stuff first */
-  if (req->cancelled_idle)
-    {
-      g_source_destroy (req->cancelled_idle);
-      g_source_unref (req->cancelled_idle);
-      req->cancelled_idle = NULL;
-    }
-  if (req->cancellable)
-    {
-      g_signal_handlers_disconnect_by_func (req->cancellable, request_cancelled, req);
-      g_object_unref (req->cancellable);
-    }
-
-  /* Now complete the result (assuming it wasn't already completed) */
-  if (req->async_result)
-    {
-      g_simple_async_result_complete (req->async_result);
-      g_object_unref (req->async_result);
-    }
-
-  /* And free req */
-  CloseHandle (req->event);
-  req->free_func (req);
-  g_slice_free (GWin32ResolverRequest, req);
-
-  return FALSE;
-}
-
-static gboolean
-request_cancelled_idle (gpointer user_data)
-{
-  GWin32ResolverRequest *req = user_data;
-  GError *error = NULL;
-
-  g_source_unref (req->cancelled_idle);
-  req->cancelled_idle = NULL;
-
-  g_cancellable_set_error_if_cancelled (req->cancellable, &error);
-  g_simple_async_result_set_from_error (req->async_result, error);
-  g_simple_async_result_complete (req->async_result);
-
-  g_object_unref (req->async_result);
-  req->async_result = NULL;
-
-  /* request_completed will eventually be called to free req */
-
-  return FALSE;
-}
-
-static void
-request_cancelled (GCancellable *cancellable,
-                   gpointer      user_data)
-{
-  GWin32ResolverRequest *req = user_data;
-
-  if (req->cancellable)
-    {
-      g_signal_handlers_disconnect_by_func (req->cancellable, request_cancelled, req);
-      g_object_unref (req->cancellable);
-      req->cancellable = NULL;
-    }
-
-  /* We need to wait until main-loop-time to actually complete the
-   * result; we don't use _complete_in_idle() here because we need to
-   * keep track of the source so we can potentially cancel it before
-   * it runs.
-   */
-  req->cancelled_idle = g_idle_source_new ();
-  g_source_set_callback (req->cancelled_idle,
-                         (GSourceFunc)request_cancelled_idle, req, NULL);
-  g_source_attach (req->cancelled_idle, g_main_context_get_thread_default ());
-}
-
-static DWORD WINAPI
-lookup_by_name_in_thread (LPVOID data)
-{
-  GWin32ResolverRequest *req = data;
-
-  req->u.name.retval = getaddrinfo (req->u.name.name, NULL,
-                                    &_g_resolver_addrinfo_hints,
-                                    &req->u.name.res);
-  SetEvent (req->event);
-  return 0;
-}
-
-static void
-free_lookup_by_name (GWin32ResolverRequest *req)
-{
-  g_free (req->u.name.name);
-  if (req->u.name.res)
-    freeaddrinfo (req->u.name.res);
-}
-
-static void
-lookup_by_name_async (GResolver           *resolver,
-                      const gchar         *hostname,
-                      GCancellable        *cancellable,
-                      GAsyncReadyCallback  callback,
-                      gpointer             user_data)
-{
-  GWin32ResolverRequest *req;
-
-  req = g_win32_resolver_request_new (resolver, free_lookup_by_name,
-                                      cancellable, callback, user_data,
-                                      lookup_by_name_async);
-  req->u.name.name = g_strdup (hostname);
-
-  QueueUserWorkItem (lookup_by_name_in_thread, req, 0);
-}
-
-static GList *
-lookup_by_name_finish (GResolver     *resolver,
-                       GAsyncResult  *result,
-                       GError       **error)
-{
-  GSimpleAsyncResult *simple;
-  GWin32ResolverRequest *req;
-
-  g_return_val_if_fail (g_simple_async_result_is_valid (result, G_OBJECT (resolver), lookup_by_name_async), NULL);
-  simple = G_SIMPLE_ASYNC_RESULT (result);
-
-  req = g_simple_async_result_get_op_res_gpointer (simple);
-  return _g_resolver_addresses_from_addrinfo (req->u.name.name, req->u.name.res,
-                                              req->u.name.retval, error);
-}
-
-
-static DWORD WINAPI
-lookup_by_addresses_in_thread (LPVOID data)
-{
-  GWin32ResolverRequest *req = data;
-
-  req->u.address.retval =
-    getnameinfo ((struct sockaddr *)&req->u.address.addr,
-                 req->u.address.addrlen,
-                 req->u.address.namebuf, NI_MAXHOST, NULL, 0, NI_NAMEREQD);
-  SetEvent (req->event);
-  return 0;
-}
-
-static void
-free_lookup_by_address (GWin32ResolverRequest *req)
-{
-  g_object_unref (req->u.address.iaddr);
-  g_free (req->u.address.namebuf);
-}
-
-static void
-lookup_by_address_async (GResolver           *resolver,
-                         GInetAddress        *address,
-                         GCancellable        *cancellable,
-                         GAsyncReadyCallback  callback,
-                         gpointer             user_data)
-{
-  GWin32ResolverRequest *req;
-
-  req = g_win32_resolver_request_new (resolver, free_lookup_by_address,
-                                      cancellable, callback, user_data,
-                                      lookup_by_address_async);
-
-  req->u.address.iaddr = g_object_ref (address);
-  _g_resolver_address_to_sockaddr (address, &req->u.address.addr,
-                                   &req->u.address.addrlen);
-  req->u.address.namebuf = g_malloc (NI_MAXHOST);
-
-  QueueUserWorkItem (lookup_by_addresses_in_thread, req, 0);
-}
-
-static char *
-lookup_by_address_finish (GResolver     *resolver,
-                          GAsyncResult  *result,
-                          GError       **error)
-{
-  GSimpleAsyncResult *simple;
-  GWin32ResolverRequest *req;
-
-  g_return_val_if_fail (g_simple_async_result_is_valid (result, G_OBJECT (resolver), lookup_by_address_async), NULL);
-  simple = G_SIMPLE_ASYNC_RESULT (result);
-
-  req = g_simple_async_result_get_op_res_gpointer (simple);
-  return _g_resolver_name_from_nameinfo (req->u.address.iaddr,
-                                         req->u.address.namebuf,
-                                         req->u.address.retval, error);
-}
-
-
-static DWORD WINAPI
-lookup_service_in_thread (LPVOID data)
-{
-  GWin32ResolverRequest *req = data;
-
-  req->u.service.retval =
-    DnsQuery_A (req->u.service.rrname, DNS_TYPE_SRV, DNS_QUERY_STANDARD,
-                NULL, &req->u.service.results, NULL);
-  SetEvent (req->event);
-  return 0;
-}
-
-static void
-free_lookup_service (GWin32ResolverRequest *req)
-{
-  g_free (req->u.service.rrname);
-  if (req->u.service.results)
-    DnsRecordListFree (req->u.service.results, DnsFreeRecordList);
-}
-
-static void
-lookup_service_async (GResolver           *resolver,
-                      const char          *rrname,
-                     GCancellable        *cancellable,
-                      GAsyncReadyCallback  callback,
-                     gpointer             user_data)
-{
-  GWin32ResolverRequest *req;
-
-  req = g_win32_resolver_request_new (resolver, free_lookup_service,
-                                      cancellable, callback, user_data,
-                                      lookup_service_async);
-  req->u.service.rrname = g_strdup (rrname);
-
-  QueueUserWorkItem (lookup_service_in_thread, req, 0);
-}
-
-static GList *
-lookup_service_finish (GResolver     *resolver,
-                       GAsyncResult  *result,
-                      GError       **error)
-{
-  GSimpleAsyncResult *simple;
-  GWin32ResolverRequest *req;
-
-  g_return_val_if_fail (g_simple_async_result_is_valid (result, G_OBJECT (resolver), lookup_service_async), NULL);
-  simple = G_SIMPLE_ASYNC_RESULT (result);
-
-  req = g_simple_async_result_get_op_res_gpointer (simple);
-  return _g_resolver_targets_from_DnsQuery (req->u.service.rrname,
-                                            req->u.service.retval,
-                                            req->u.service.results, error);
-}
-
-
-static void
-g_win32_resolver_class_init (GWin32ResolverClass *win32_class)
-{
-  GResolverClass *resolver_class = G_RESOLVER_CLASS (win32_class);
-
-  resolver_class->lookup_by_name_async     = lookup_by_name_async;
-  resolver_class->lookup_by_name_finish    = lookup_by_name_finish;
-  resolver_class->lookup_by_address_async  = lookup_by_address_async;
-  resolver_class->lookup_by_address_finish = lookup_by_address_finish;
-  resolver_class->lookup_service_async     = lookup_service_async;
-  resolver_class->lookup_service_finish    = lookup_service_finish;
-}
-
-
-/* Windows HANDLE GSource */
-
-typedef struct {
-  GSource source;
-  GPollFD pollfd;
-} GWin32HandleSource;
-
-static gboolean
-g_win32_handle_source_prepare (GSource *source,
-                               gint    *timeout)
-{
-  *timeout = -1;
-  return FALSE;
-}
-
-static gboolean
-g_win32_handle_source_check (GSource *source)
-{
-  GWin32HandleSource *hsource = (GWin32HandleSource *)source;
-
-  return hsource->pollfd.revents;
-}
-
-static gboolean
-g_win32_handle_source_dispatch (GSource     *source,
-                                GSourceFunc  callback,
-                                gpointer     user_data)
-{
-  return (*callback) (user_data);
-}
-
-static void
-g_win32_handle_source_finalize (GSource *source)
-{
-  ;
-}
-
-GSourceFuncs g_win32_handle_source_funcs = {
-  g_win32_handle_source_prepare,
-  g_win32_handle_source_check,
-  g_win32_handle_source_dispatch,
-  g_win32_handle_source_finalize
-};
-
-static GSource *
-g_win32_handle_source_add (HANDLE      handle,
-                           GSourceFunc callback,
-                           gpointer    user_data)
-{
-  GWin32HandleSource *hsource;
-  GSource *source;
-
-  source = g_source_new (&g_win32_handle_source_funcs, sizeof (GWin32HandleSource));
-  hsource = (GWin32HandleSource *)source;
-  hsource->pollfd.fd = (gint)handle;
-  hsource->pollfd.events = G_IO_IN;
-  hsource->pollfd.revents = 0;
-  g_source_add_poll (source, &hsource->pollfd);
-
-  g_source_set_callback (source, callback, user_data, NULL);
-  g_source_attach (source, g_main_context_get_thread_default ());
-  return source;
-}
diff --git a/gio/gwin32resolver.h b/gio/gwin32resolver.h
deleted file mode 100644 (file)
index 5cc6a2c..0000000
+++ /dev/null
@@ -1,49 +0,0 @@
-/* GIO - GLib Input, Output and Streaming Library
- *
- * Copyright (C) 2008 Red Hat, Inc.
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General
- * Public License along with this library; if not, write to the
- * Free Software Foundation, Inc., 59 Temple Place, Suite 330,
- * Boston, MA 02111-1307, USA.
- */
-
-#ifndef __G_WIN32_RESOLVER_H__
-#define __G_WIN32_RESOLVER_H__
-
-#include <gio/gthreadedresolver.h>
-
-G_BEGIN_DECLS
-
-#define G_TYPE_WIN32_RESOLVER         (g_win32_resolver_get_type ())
-#define G_WIN32_RESOLVER(o)           (G_TYPE_CHECK_INSTANCE_CAST ((o), G_TYPE_WIN32_RESOLVER, GWin32Resolver))
-#define G_WIN32_RESOLVER_CLASS(k)     (G_TYPE_CHECK_CLASS_CAST((k), G_TYPE_WIN32_RESOLVER, GWin32ResolverClass))
-#define G_IS_WIN32_RESOLVER(o)        (G_TYPE_CHECK_INSTANCE_TYPE ((o), G_TYPE_WIN32_RESOLVER))
-#define G_IS_WIN32_RESOLVER_CLASS(k)  (G_TYPE_CHECK_CLASS_TYPE ((k), G_TYPE_WIN32_RESOLVER))
-#define G_WIN32_RESOLVER_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), G_TYPE_WIN32_RESOLVER, GWin32ResolverClass))
-
-typedef struct {
-  GThreadedResolver parent_instance;
-
-} GWin32Resolver;
-
-typedef struct {
-  GThreadedResolverClass parent_class;
-
-} GWin32ResolverClass;
-
-GType g_win32_resolver_get_type (void) G_GNUC_CONST;
-
-G_END_DECLS
-
-#endif /* __G_RESOLVER_H__ */
diff --git a/gio/libasyncns/Makefile.am b/gio/libasyncns/Makefile.am
deleted file mode 100644 (file)
index bee767f..0000000
+++ /dev/null
@@ -1,15 +0,0 @@
-## Process this file with automake to produce Makefile.in
-include $(top_srcdir)/Makefile.decl
-
-INCLUDES = $(config_h_INCLUDES)
-
-noinst_LTLIBRARIES = libasyncns.la
-
-libasyncns_la_SOURCES = \
-       asyncns.c \
-       asyncns.h \
-       g-asyncns.h
-
-libasyncns_la_LIBADD = $(NETWORK_LIBS)
-
-EXTRA_DIST += README update.sh
diff --git a/gio/libasyncns/README b/gio/libasyncns/README
deleted file mode 100644 (file)
index b926291..0000000
+++ /dev/null
@@ -1,7 +0,0 @@
-The sources are derived from Lennart Poettering's libasyncns library:
-
- http://0pointer.de/lennart/projects/libasyncns/
-
-The 'update.sh' script in this directory, when pointed at
-the original sources updates the files in this directory
-to the new version
diff --git a/gio/libasyncns/asyncns.c b/gio/libasyncns/asyncns.c
deleted file mode 100644 (file)
index 155f491..0000000
+++ /dev/null
@@ -1,1533 +0,0 @@
-/***
-  This file is part of libasyncns.
-
-  Copyright 2005-2008 Lennart Poettering
-
-  libasyncns is free software; you can redistribute it and/or modify
-  it under the terms of the GNU Lesser General Public License as
-  published by the Free Software Foundation, either version 2.1 of the
-  License, or (at your option) any later version.
-
-  libasyncns is distributed in the hope that it will be useful, but
-  WITHOUT ANY WARRANTY; without even the implied warranty of
-  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-  Lesser General Public License for more details.
-
-  You should have received a copy of the GNU Lesser General Public
-  License along with libasyncns. If not, see
-  <http://www.gnu.org/licenses/>.
-***/
-
-#ifdef HAVE_CONFIG_H
-#include "g-asyncns.h"
-#endif
-
-/* #undef HAVE_PTHREAD */
-
-#include <assert.h>
-#include <fcntl.h>
-#include <signal.h>
-#include <unistd.h>
-
-#ifdef HAVE_SYS_SELECT_H
-#include <sys/select.h>
-#endif
-
-#include <stdio.h>
-#include <string.h>
-#include <stdlib.h>
-#include <errno.h>
-#include <sys/wait.h>
-#include <sys/types.h>
-#include <pwd.h>
-#include <netinet/in.h>
-#include <arpa/nameser.h>
-#include <resolv.h>
-#include <dirent.h>
-
-#ifdef HAVE_SYS_TIME_H
-#include <sys/time.h>
-#endif
-
-#include <sys/resource.h>
-#ifdef HAVE_STDINT_H
-#include <stdint.h>
-#endif
-#ifdef HAVE_INTTYPES_H
-#include <inttypes.h>
-#endif
-
-#ifdef HAVE_SYS_PRCTL_H
-#include <sys/prctl.h>
-#endif
-
-#if HAVE_PTHREAD
-#include <pthread.h>
-#endif
-
-#include "asyncns.h"
-
-#ifndef MSG_NOSIGNAL
-#define MSG_NOSIGNAL 0
-#endif
-
-#define MAX_WORKERS 16
-#define MAX_QUERIES 256
-#define BUFSIZE (10240)
-
-typedef enum {
-    REQUEST_ADDRINFO,
-    RESPONSE_ADDRINFO,
-    REQUEST_NAMEINFO,
-    RESPONSE_NAMEINFO,
-    REQUEST_RES_QUERY,
-    REQUEST_RES_SEARCH,
-    RESPONSE_RES,
-    REQUEST_TERMINATE,
-    RESPONSE_DIED
-} query_type_t;
-
-enum {
-    REQUEST_RECV_FD = 0,
-    REQUEST_SEND_FD = 1,
-    RESPONSE_RECV_FD = 2,
-    RESPONSE_SEND_FD = 3,
-    MESSAGE_FD_MAX = 4
-};
-
-struct asyncns {
-    int fds[4];
-
-#ifndef HAVE_PTHREAD
-    pid_t workers[MAX_WORKERS];
-#else
-    pthread_t workers[MAX_WORKERS];
-#endif
-    unsigned valid_workers;
-
-    unsigned current_id, current_index;
-    _g_asyncns_query_t* queries[MAX_QUERIES];
-
-    _g_asyncns_query_t *done_head, *done_tail;
-
-    int n_queries;
-    int dead;
-};
-
-struct _g_asyncns_query {
-    _g_asyncns_t *asyncns;
-    int done;
-    unsigned id;
-    query_type_t type;
-    _g_asyncns_query_t *done_next, *done_prev;
-    int ret;
-    int _errno;
-    int _h_errno;
-    struct addrinfo *addrinfo;
-    char *serv, *host;
-    void *userdata;
-};
-
-typedef struct rheader {
-    query_type_t type;
-    unsigned id;
-    size_t length;
-} rheader_t;
-
-typedef struct addrinfo_request {
-    struct rheader header;
-    int hints_is_null;
-    int ai_flags;
-    int ai_family;
-    int ai_socktype;
-    int ai_protocol;
-    size_t node_len, service_len;
-} addrinfo_request_t;
-
-typedef struct addrinfo_response {
-    struct rheader header;
-    int ret;
-    int _errno;
-    int _h_errno;
-    /* followed by addrinfo_serialization[] */
-} addrinfo_response_t;
-
-typedef struct addrinfo_serialization {
-    int ai_flags;
-    int ai_family;
-    int ai_socktype;
-    int ai_protocol;
-    size_t ai_addrlen;
-    size_t canonname_len;
-    /* Followed by ai_addr amd ai_canonname with variable lengths */
-} addrinfo_serialization_t;
-
-typedef struct nameinfo_request {
-    struct rheader header;
-    int flags;
-    socklen_t sockaddr_len;
-    int gethost, getserv;
-} nameinfo_request_t;
-
-typedef struct nameinfo_response {
-    struct rheader header;
-    size_t hostlen, servlen;
-    int ret;
-    int _errno;
-    int _h_errno;
-} nameinfo_response_t;
-
-typedef struct res_request {
-    struct rheader header;
-    int class;
-    int type;
-    size_t dname_len;
-} res_request_t;
-
-typedef struct res_response {
-    struct rheader header;
-    int ret;
-    int _errno;
-    int _h_errno;
-} res_response_t;
-
-typedef union packet {
-    rheader_t rheader;
-    addrinfo_request_t addrinfo_request;
-    addrinfo_response_t addrinfo_response;
-    nameinfo_request_t nameinfo_request;
-    nameinfo_response_t nameinfo_response;
-    res_request_t res_request;
-    res_response_t res_response;
-} packet_t;
-
-#ifndef HAVE_STRNDUP
-
-static char *strndup(const char *s, size_t l) {
-    size_t a;
-    char *n;
-
-    a = strlen(s);
-    if (a > l)
-        a = l;
-
-    if (!(n = malloc(a+1)))
-        return NULL;
-
-    memcpy(n, s, a);
-    n[a] = 0;
-
-    return n;
-}
-
-#endif
-
-#ifndef HAVE_PTHREAD
-
-static int close_allv(const int except_fds[]) {
-    struct rlimit rl;
-    int fd, maxfd;
-
-#ifdef __linux__
-
-    DIR *d;
-
-    assert(except_fds);
-
-    if ((d = opendir("/proc/self/fd"))) {
-
-        struct dirent *de;
-
-        while ((de = readdir(d))) {
-            int found;
-            long l;
-            char *e = NULL;
-            int i;
-
-            if (de->d_name[0] == '.')
-                continue;
-
-            errno = 0;
-            l = strtol(de->d_name, &e, 10);
-            if (errno != 0 || !e || *e) {
-                closedir(d);
-                errno = EINVAL;
-                return -1;
-            }
-
-            fd = (int) l;
-
-            if ((long) fd != l) {
-                closedir(d);
-                errno = EINVAL;
-                return -1;
-            }
-
-            if (fd < 3)
-                continue;
-
-            if (fd == dirfd(d))
-                continue;
-
-            found = 0;
-            for (i = 0; except_fds[i] >= 0; i++)
-                if (except_fds[i] == fd) {
-                    found = 1;
-                    break;
-                }
-
-            if (found)
-                continue;
-
-            if (close(fd) < 0) {
-                int saved_errno;
-
-                saved_errno = errno;
-                closedir(d);
-                errno = saved_errno;
-
-                return -1;
-            }
-        }
-
-        closedir(d);
-        return 0;
-    }
-
-#endif
-
-    if (getrlimit(RLIMIT_NOFILE, &rl) > 0)
-        maxfd = (int) rl.rlim_max;
-    else
-        maxfd = sysconf(_SC_OPEN_MAX);
-
-    for (fd = 3; fd < maxfd; fd++) {
-        int i, found;
-
-        found = 0;
-        for (i = 0; except_fds[i] >= 0; i++)
-            if (except_fds[i] == fd) {
-                found = 1;
-                continue;
-            }
-
-        if (found)
-            continue;
-
-        if (close(fd) < 0 && errno != EBADF)
-            return -1;
-    }
-
-    return 0;
-}
-
-static int reset_sigsv(const int except[]) {
-    int sig;
-    assert(except);
-
-    for (sig = 1; sig < NSIG; sig++) {
-        int reset = 1;
-
-        switch (sig) {
-            case SIGKILL:
-            case SIGSTOP:
-                reset = 0;
-                break;
-
-            default: {
-                int i;
-
-                for (i = 0; except[i] > 0; i++) {
-                    if (sig == except[i]) {
-                        reset = 0;
-                        break;
-                    }
-                }
-            }
-        }
-
-        if (reset) {
-            struct sigaction sa;
-
-            memset(&sa, 0, sizeof(sa));
-            sa.sa_handler = SIG_DFL;
-
-            /* On Linux the first two RT signals are reserved by
-             * glibc, and sigaction() will return EINVAL for them. */
-            if ((sigaction(sig, &sa, NULL) < 0))
-                if (errno != EINVAL)
-                    return -1;
-        }
-    }
-
-    return 0;
-}
-
-static int ignore_sigsv(const int ignore[]) {
-    int i;
-    assert(ignore);
-
-    for (i = 0; ignore[i] > 0; i++) {
-        struct sigaction sa;
-
-        memset(&sa, 0, sizeof(sa));
-        sa.sa_handler = SIG_IGN;
-
-        if ((sigaction(ignore[i], &sa, NULL) < 0))
-            return -1;
-    }
-
-    return 0;
-}
-
-#endif
-
-static int fd_nonblock(int fd) {
-    int i;
-    assert(fd >= 0);
-
-    if ((i = fcntl(fd, F_GETFL, 0)) < 0)
-        return -1;
-
-    if (i & O_NONBLOCK)
-        return 0;
-
-    return fcntl(fd, F_SETFL, i | O_NONBLOCK);
-}
-
-static int fd_cloexec(int fd) {
-    int v;
-    assert(fd >= 0);
-
-    if ((v = fcntl(fd, F_GETFD, 0)) < 0)
-        return -1;
-
-    if (v & FD_CLOEXEC)
-        return 0;
-
-    return fcntl(fd, F_SETFD, v | FD_CLOEXEC);
-}
-
-static int send_died(int out_fd) {
-    rheader_t rh;
-    assert(out_fd > 0);
-
-    memset(&rh, 0, sizeof(rh));
-    rh.type = RESPONSE_DIED;
-    rh.id = 0;
-    rh.length = sizeof(rh);
-
-    return send(out_fd, &rh, rh.length, MSG_NOSIGNAL);
-}
-
-static void *serialize_addrinfo(void *p, const struct addrinfo *ai, size_t *length, size_t maxlength) {
-    addrinfo_serialization_t s;
-    size_t cnl, l;
-    assert(p);
-    assert(ai);
-    assert(length);
-    assert(*length <= maxlength);
-
-    cnl = (ai->ai_canonname ? strlen(ai->ai_canonname)+1 : 0);
-    l = sizeof(addrinfo_serialization_t) + ai->ai_addrlen + cnl;
-
-    if (*length + l > maxlength)
-        return NULL;
-
-    s.ai_flags = ai->ai_flags;
-    s.ai_family = ai->ai_family;
-    s.ai_socktype = ai->ai_socktype;
-    s.ai_protocol = ai->ai_protocol;
-    s.ai_addrlen = ai->ai_addrlen;
-    s.canonname_len = cnl;
-
-    memcpy((uint8_t*) p, &s, sizeof(addrinfo_serialization_t));
-    memcpy((uint8_t*) p + sizeof(addrinfo_serialization_t), ai->ai_addr, ai->ai_addrlen);
-
-    if (ai->ai_canonname)
-        strcpy((char*) p + sizeof(addrinfo_serialization_t) + ai->ai_addrlen, ai->ai_canonname);
-
-    *length += l;
-    return (uint8_t*) p + l;
-}
-
-static int send_addrinfo_reply(int out_fd, unsigned id, int ret, struct addrinfo *ai, int _errno, int _h_errno) {
-    addrinfo_response_t data[BUFSIZE/sizeof(addrinfo_response_t) + 1];
-    addrinfo_response_t *resp = data;
-    assert(out_fd >= 0);
-
-    memset(data, 0, sizeof(data));
-    resp->header.type = RESPONSE_ADDRINFO;
-    resp->header.id = id;
-    resp->header.length = sizeof(addrinfo_response_t);
-    resp->ret = ret;
-    resp->_errno = _errno;
-    resp->_h_errno = _h_errno;
-
-    if (ret == 0 && ai) {
-        void *p = data + 1;
-        struct addrinfo *k;
-
-        for (k = ai; k; k = k->ai_next) {
-
-            if (!(p = serialize_addrinfo(p, k, &resp->header.length, (char*) data + BUFSIZE - (char*) p))) {
-                resp->ret = EAI_MEMORY;
-                break;
-            }
-        }
-    }
-
-    if (ai)
-        freeaddrinfo(ai);
-
-    return send(out_fd, resp, resp->header.length, MSG_NOSIGNAL);
-}
-
-static int send_nameinfo_reply(int out_fd, unsigned id, int ret, const char *host, const char *serv, int _errno, int _h_errno) {
-    nameinfo_response_t data[BUFSIZE/sizeof(nameinfo_response_t) + 1];
-    size_t hl, sl;
-    nameinfo_response_t *resp = data;
-
-    assert(out_fd >= 0);
-
-    sl = serv ? strlen(serv)+1 : 0;
-    hl = host ? strlen(host)+1 : 0;
-
-    memset(data, 0, sizeof(data));
-    resp->header.type = RESPONSE_NAMEINFO;
-    resp->header.id = id;
-    resp->header.length = sizeof(nameinfo_response_t) + hl + sl;
-    resp->ret = ret;
-    resp->_errno = _errno;
-    resp->_h_errno = _h_errno;
-    resp->hostlen = hl;
-    resp->servlen = sl;
-
-    assert(sizeof(data) >= resp->header.length);
-
-    if (host)
-        memcpy((uint8_t *)data + sizeof(nameinfo_response_t), host, hl);
-
-    if (serv)
-        memcpy((uint8_t *)data + sizeof(nameinfo_response_t) + hl, serv, sl);
-
-    return send(out_fd, resp, resp->header.length, MSG_NOSIGNAL);
-}
-
-static int send_res_reply(int out_fd, unsigned id, const unsigned char *answer, int ret, int _errno, int _h_errno) {
-    res_response_t data[BUFSIZE/sizeof(res_response_t) + 1];
-    res_response_t *resp = data;
-
-    assert(out_fd >= 0);
-
-    memset(data, 0, sizeof(data));
-    resp->header.type = RESPONSE_RES;
-    resp->header.id = id;
-    resp->header.length = sizeof(res_response_t) + (ret < 0 ? 0 : ret);
-    resp->ret = ret;
-    resp->_errno = _errno;
-    resp->_h_errno = _h_errno;
-
-    assert(sizeof(data) >= resp->header.length);
-
-    if (ret > 0)
-        memcpy((uint8_t *)data + sizeof(res_response_t), answer, ret);
-
-    return send(out_fd, resp, resp->header.length, MSG_NOSIGNAL);
-}
-
-static int handle_request(int out_fd, const packet_t *packet, size_t length) {
-    const rheader_t *req;
-    assert(out_fd >= 0);
-
-    req = &packet->rheader;
-    assert(req);
-    assert(length >= sizeof(rheader_t));
-    assert(length == req->length);
-
-    switch (req->type) {
-
-        case REQUEST_ADDRINFO: {
-            struct addrinfo ai, *result = NULL;
-            const addrinfo_request_t *ai_req = &packet->addrinfo_request;
-            const char *node, *service;
-            int ret;
-
-            assert(length >= sizeof(addrinfo_request_t));
-            assert(length == sizeof(addrinfo_request_t) + ai_req->node_len + ai_req->service_len);
-
-            memset(&ai, 0, sizeof(ai));
-            ai.ai_flags = ai_req->ai_flags;
-            ai.ai_family = ai_req->ai_family;
-            ai.ai_socktype = ai_req->ai_socktype;
-            ai.ai_protocol = ai_req->ai_protocol;
-
-            node = ai_req->node_len ? (const char*) ai_req + sizeof(addrinfo_request_t) : NULL;
-            service = ai_req->service_len ? (const char*) ai_req + sizeof(addrinfo_request_t) + ai_req->node_len : NULL;
-
-            ret = getaddrinfo(node, service,
-                              ai_req->hints_is_null ? NULL : &ai,
-                              &result);
-
-            /* send_addrinfo_reply() frees result */
-            return send_addrinfo_reply(out_fd, req->id, ret, result, errno, h_errno);
-        }
-
-        case REQUEST_NAMEINFO: {
-            int ret;
-            const nameinfo_request_t *ni_req = &packet->nameinfo_request;
-            char hostbuf[NI_MAXHOST], servbuf[NI_MAXSERV];
-            struct sockaddr_storage sa;
-
-            assert(length >= sizeof(nameinfo_request_t));
-            assert(length == sizeof(nameinfo_request_t) + ni_req->sockaddr_len);
-
-            memcpy(&sa, (const uint8_t *) ni_req + sizeof(nameinfo_request_t), ni_req->sockaddr_len);
-
-            ret = getnameinfo((struct sockaddr *)&sa, ni_req->sockaddr_len,
-                              ni_req->gethost ? hostbuf : NULL, ni_req->gethost ? sizeof(hostbuf) : 0,
-                              ni_req->getserv ? servbuf : NULL, ni_req->getserv ? sizeof(servbuf) : 0,
-                              ni_req->flags);
-
-            return send_nameinfo_reply(out_fd, req->id, ret,
-                                       ret == 0 && ni_req->gethost ? hostbuf : NULL,
-                                       ret == 0 && ni_req->getserv ? servbuf : NULL,
-                                       errno, h_errno);
-        }
-
-        case REQUEST_RES_QUERY:
-        case REQUEST_RES_SEARCH: {
-            int ret;
-            HEADER answer[BUFSIZE/sizeof(HEADER) + 1];
-            const res_request_t *res_req = &packet->res_request;
-            const char *dname;
-
-            assert(length >= sizeof(res_request_t));
-            assert(length == sizeof(res_request_t) + res_req->dname_len);
-
-            dname = (const char *) req + sizeof(res_request_t);
-
-            if (req->type == REQUEST_RES_QUERY)
-                ret = res_query(dname, res_req->class, res_req->type, (unsigned char *) answer, BUFSIZE);
-            else
-                ret = res_search(dname, res_req->class, res_req->type, (unsigned char *) answer, BUFSIZE);
-
-            return send_res_reply(out_fd, req->id, (unsigned char *) answer, ret, errno, h_errno);
-        }
-
-        case REQUEST_TERMINATE:
-            /* Quit */
-            return -1;
-
-        default:
-            ;
-    }
-
-    return 0;
-}
-
-#ifndef HAVE_PTHREAD
-
-static int process_worker(int in_fd, int out_fd) {
-    int have_death_sig = 0;
-    int good_fds[3];
-    int ret = 1;
-
-    const int ignore_sigs[] = {
-        SIGINT,
-        SIGHUP,
-        SIGPIPE,
-        SIGUSR1,
-        SIGUSR2,
-        -1
-    };
-
-    assert(in_fd > 2);
-    assert(out_fd > 2);
-
-    close(0);
-    close(1);
-    close(2);
-
-    if (open("/dev/null", O_RDONLY) != 0)
-        goto fail;
-
-    if (open("/dev/null", O_WRONLY) != 1)
-        goto fail;
-
-    if (open("/dev/null", O_WRONLY) != 2)
-        goto fail;
-
-    if (chdir("/") < 0)
-        goto fail;
-
-    if (geteuid() == 0) {
-        struct passwd *pw;
-        int r;
-
-        if ((pw = getpwnam("nobody"))) {
-#ifdef HAVE_SETRESUID
-            r = setresuid(pw->pw_uid, pw->pw_uid, pw->pw_uid);
-#elif HAVE_SETREUID
-            r = setreuid(pw->pw_uid, pw->pw_uid);
-#else
-            if ((r = setuid(pw->pw_uid)) >= 0)
-                r = seteuid(pw->pw_uid);
-#endif
-            if (r < 0)
-                goto fail;
-        }
-    }
-
-    if (reset_sigsv(ignore_sigs) < 0)
-        goto fail;
-
-    if (ignore_sigsv(ignore_sigs) < 0)
-        goto fail;
-
-    good_fds[0] = in_fd; good_fds[1] = out_fd; good_fds[2] = -1;
-    if (close_allv(good_fds) < 0)
-        goto fail;
-
-#ifdef PR_SET_PDEATHSIG
-    if (prctl(PR_SET_PDEATHSIG, SIGTERM) >= 0)
-        have_death_sig = 1;
-#endif
-
-    if (!have_death_sig)
-        fd_nonblock(in_fd);
-
-    while (getppid() > 1) { /* if the parent PID is 1 our parent process died. */
-        packet_t buf[BUFSIZE/sizeof(packet_t) + 1];
-        ssize_t length;
-
-        if (!have_death_sig) {
-            fd_set fds;
-            struct timeval tv = { 0, 500000 };
-
-            FD_ZERO(&fds);
-            FD_SET(in_fd, &fds);
-
-            if (select(in_fd+1, &fds, NULL, NULL, &tv) < 0)
-                break;
-
-            if (getppid() == 1)
-                break;
-        }
-
-        if ((length = recv(in_fd, buf, sizeof(buf), 0)) <= 0) {
-
-            if (length < 0 &&
-                (errno == EAGAIN || errno == EINTR))
-                continue;
-
-            break;
-        }
-
-        if (handle_request(out_fd, buf, (size_t) length) < 0)
-            break;
-    }
-
-    ret = 0;
-
-fail:
-    send_died(out_fd);
-
-    return ret;
-}
-
-#else
-
-static void* thread_worker(void *p) {
-    _g_asyncns_t *asyncns = p;
-    sigset_t fullset;
-
-    /* No signals in this thread please */
-    sigfillset(&fullset);
-    pthread_sigmask(SIG_BLOCK, &fullset, NULL);
-
-    while (!asyncns->dead) {
-        packet_t buf[BUFSIZE/sizeof(packet_t) + 1];
-        ssize_t length;
-
-        if ((length = recv(asyncns->fds[REQUEST_RECV_FD], buf, sizeof(buf), 0)) <= 0) {
-
-            if (length < 0 &&
-                (errno == EAGAIN || errno == EINTR))
-                continue;
-
-            break;
-        }
-
-        if (asyncns->dead)
-            break;
-
-        if (handle_request(asyncns->fds[RESPONSE_SEND_FD], buf, (size_t) length) < 0)
-            break;
-    }
-
-    send_died(asyncns->fds[RESPONSE_SEND_FD]);
-
-    return NULL;
-}
-
-#endif
-
-_g_asyncns_t* _g_asyncns_new(unsigned n_proc) {
-    _g_asyncns_t *asyncns = NULL;
-    int i;
-    assert(n_proc >= 1);
-
-    if (n_proc > MAX_WORKERS)
-        n_proc = MAX_WORKERS;
-
-    if (!(asyncns = malloc(sizeof(_g_asyncns_t)))) {
-        errno = ENOMEM;
-        goto fail;
-    }
-
-    asyncns->dead = 0;
-    asyncns->valid_workers = 0;
-
-    for (i = 0; i < MESSAGE_FD_MAX; i++)
-        asyncns->fds[i] = -1;
-
-    memset(asyncns->queries, 0, sizeof(asyncns->queries));
-
-    if (socketpair(PF_UNIX, SOCK_DGRAM, 0, asyncns->fds) < 0 ||
-        socketpair(PF_UNIX, SOCK_DGRAM, 0, asyncns->fds+2) < 0)
-        goto fail;
-
-    for (i = 0; i < MESSAGE_FD_MAX; i++)
-        fd_cloexec(asyncns->fds[i]);
-
-    for (asyncns->valid_workers = 0; asyncns->valid_workers < n_proc; asyncns->valid_workers++) {
-
-#ifndef HAVE_PTHREAD
-        if ((asyncns->workers[asyncns->valid_workers] = fork()) < 0)
-            goto fail;
-        else if (asyncns->workers[asyncns->valid_workers] == 0) {
-            int ret;
-
-            close(asyncns->fds[REQUEST_SEND_FD]);
-            close(asyncns->fds[RESPONSE_RECV_FD]);
-            ret = process_worker(asyncns->fds[REQUEST_RECV_FD], asyncns->fds[RESPONSE_SEND_FD]);
-            close(asyncns->fds[REQUEST_RECV_FD]);
-            close(asyncns->fds[RESPONSE_SEND_FD]);
-            _exit(ret);
-        }
-#else
-        int r;
-
-        if ((r = pthread_create(&asyncns->workers[asyncns->valid_workers], NULL, thread_worker, asyncns)) != 0) {
-            errno = r;
-            goto fail;
-        }
-#endif
-    }
-
-#ifndef HAVE_PTHREAD
-    close(asyncns->fds[REQUEST_RECV_FD]);
-    close(asyncns->fds[RESPONSE_SEND_FD]);
-    asyncns->fds[REQUEST_RECV_FD] = asyncns->fds[RESPONSE_SEND_FD] = -1;
-#endif
-
-    asyncns->current_index = asyncns->current_id = 0;
-    asyncns->done_head = asyncns->done_tail = NULL;
-    asyncns->n_queries = 0;
-
-    fd_nonblock(asyncns->fds[RESPONSE_RECV_FD]);
-
-    return asyncns;
-
-fail:
-    if (asyncns)
-        _g_asyncns_free(asyncns);
-
-    return NULL;
-}
-
-void _g_asyncns_free(_g_asyncns_t *asyncns) {
-    int i;
-    int saved_errno = errno;
-    unsigned p;
-
-    assert(asyncns);
-
-    asyncns->dead = 1;
-
-    if (asyncns->fds[REQUEST_SEND_FD] >= 0) {
-        rheader_t req;
-
-        memset(&req, 0, sizeof(req));
-        req.type = REQUEST_TERMINATE;
-        req.length = sizeof(req);
-        req.id = 0;
-
-        /* Send one termination packet for each worker */
-        for (p = 0; p < asyncns->valid_workers; p++)
-            send(asyncns->fds[REQUEST_SEND_FD], &req, req.length, MSG_NOSIGNAL);
-    }
-
-    /* Now terminate them and wait until they are gone. */
-    for (p = 0; p < asyncns->valid_workers; p++) {
-#ifndef HAVE_PTHREAD
-        kill(asyncns->workers[p], SIGTERM);
-        for (;;) {
-            if (waitpid(asyncns->workers[p], NULL, 0) >= 0 || errno != EINTR)
-                break;
-        }
-#else
-        for (;;) {
-            if (pthread_join(asyncns->workers[p], NULL) != EINTR)
-                break;
-        }
-#endif
-    }
-
-    /* Close all communication channels */
-    for (i = 0; i < MESSAGE_FD_MAX; i++)
-        if (asyncns->fds[i] >= 0)
-            close(asyncns->fds[i]);
-
-    for (p = 0; p < MAX_QUERIES; p++)
-        if (asyncns->queries[p])
-            _g_asyncns_cancel(asyncns, asyncns->queries[p]);
-
-    free(asyncns);
-
-    errno = saved_errno;
-}
-
-int _g_asyncns_fd(_g_asyncns_t *asyncns) {
-    assert(asyncns);
-
-    return asyncns->fds[RESPONSE_RECV_FD];
-}
-
-static _g_asyncns_query_t *lookup_query(_g_asyncns_t *asyncns, unsigned id) {
-    _g_asyncns_query_t *q;
-    assert(asyncns);
-
-    if ((q = asyncns->queries[id % MAX_QUERIES]))
-        if (q->id == id)
-            return q;
-
-    return NULL;
-}
-
-static void complete_query(_g_asyncns_t *asyncns, _g_asyncns_query_t *q) {
-    assert(asyncns);
-    assert(q);
-    assert(!q->done);
-
-    q->done = 1;
-
-    if ((q->done_prev = asyncns->done_tail))
-        asyncns->done_tail->done_next = q;
-    else
-        asyncns->done_head = q;
-
-    asyncns->done_tail = q;
-    q->done_next = NULL;
-}
-
-static const void *unserialize_addrinfo(const void *p, struct addrinfo **ret_ai, size_t *length) {
-    addrinfo_serialization_t s;
-    size_t l;
-    struct addrinfo *ai;
-    assert(p);
-    assert(ret_ai);
-    assert(length);
-
-    if (*length < sizeof(addrinfo_serialization_t))
-        return NULL;
-
-    memcpy(&s, p, sizeof(s));
-
-    l = sizeof(addrinfo_serialization_t) + s.ai_addrlen + s.canonname_len;
-    if (*length < l)
-        return NULL;
-
-    if (!(ai = malloc(sizeof(struct addrinfo))))
-        goto fail;
-
-    ai->ai_addr = NULL;
-    ai->ai_canonname = NULL;
-    ai->ai_next = NULL;
-
-    if (s.ai_addrlen && !(ai->ai_addr = malloc(s.ai_addrlen)))
-        goto fail;
-
-    if (s.canonname_len && !(ai->ai_canonname = malloc(s.canonname_len)))
-        goto fail;
-
-    ai->ai_flags = s.ai_flags;
-    ai->ai_family = s.ai_family;
-    ai->ai_socktype = s.ai_socktype;
-    ai->ai_protocol = s.ai_protocol;
-    ai->ai_addrlen = s.ai_addrlen;
-
-    if (ai->ai_addr)
-        memcpy(ai->ai_addr, (const uint8_t*) p + sizeof(addrinfo_serialization_t), s.ai_addrlen);
-
-    if (ai->ai_canonname)
-        memcpy(ai->ai_canonname, (const uint8_t*) p + sizeof(addrinfo_serialization_t) + s.ai_addrlen, s.canonname_len);
-
-    *length -= l;
-    *ret_ai = ai;
-
-    return (const uint8_t*) p + l;
-
-
-fail:
-    if (ai)
-        _g_asyncns_freeaddrinfo(ai);
-
-    return NULL;
-}
-
-static int handle_response(_g_asyncns_t *asyncns, const packet_t *packet, size_t length) {
-    const rheader_t *resp;
-    _g_asyncns_query_t *q;
-
-    assert(asyncns);
-
-    resp = &packet->rheader;
-    assert(resp);
-    assert(length >= sizeof(rheader_t));
-    assert(length == resp->length);
-
-    if (resp->type == RESPONSE_DIED) {
-        asyncns->dead = 1;
-        return 0;
-    }
-
-    if (!(q = lookup_query(asyncns, resp->id)))
-        return 0;
-
-    switch (resp->type) {
-        case RESPONSE_ADDRINFO: {
-            const addrinfo_response_t *ai_resp = &packet->addrinfo_response;
-            const void *p;
-            size_t l;
-            struct addrinfo *prev = NULL;
-
-            assert(length >= sizeof(addrinfo_response_t));
-            assert(q->type == REQUEST_ADDRINFO);
-
-            q->ret = ai_resp->ret;
-            q->_errno = ai_resp->_errno;
-            q->_h_errno = ai_resp->_h_errno;
-            l = length - sizeof(addrinfo_response_t);
-            p = (const uint8_t*) resp + sizeof(addrinfo_response_t);
-
-            while (l > 0 && p) {
-                struct addrinfo *ai = NULL;
-                p = unserialize_addrinfo(p, &ai, &l);
-
-                if (!p || !ai) {
-                    q->ret = EAI_MEMORY;
-                    break;
-                }
-
-                if (prev)
-                    prev->ai_next = ai;
-                else
-                    q->addrinfo = ai;
-
-                prev = ai;
-            }
-
-            complete_query(asyncns, q);
-            break;
-        }
-
-        case RESPONSE_NAMEINFO: {
-            const nameinfo_response_t *ni_resp = &packet->nameinfo_response;
-
-            assert(length >= sizeof(nameinfo_response_t));
-            assert(q->type == REQUEST_NAMEINFO);
-
-            q->ret = ni_resp->ret;
-            q->_errno = ni_resp->_errno;
-            q->_h_errno = ni_resp->_h_errno;
-
-            if (ni_resp->hostlen)
-                if (!(q->host = strndup((const char*) ni_resp + sizeof(nameinfo_response_t), ni_resp->hostlen-1)))
-                    q->ret = EAI_MEMORY;
-
-            if (ni_resp->servlen)
-                if (!(q->serv = strndup((const char*) ni_resp + sizeof(nameinfo_response_t) + ni_resp->hostlen, ni_resp->servlen-1)))
-                    q->ret = EAI_MEMORY;
-
-            complete_query(asyncns, q);
-            break;
-        }
-
-        case RESPONSE_RES: {
-            const res_response_t *res_resp = &packet->res_response;
-
-            assert(length >= sizeof(res_response_t));
-            assert(q->type == REQUEST_RES_QUERY || q->type == REQUEST_RES_SEARCH);
-
-            q->ret = res_resp->ret;
-            q->_errno = res_resp->_errno;
-            q->_h_errno = res_resp->_h_errno;
-
-            if (res_resp->ret >= 0)  {
-                if (!(q->serv = malloc(res_resp->ret))) {
-                    q->ret = -1;
-                    q->_errno = ENOMEM;
-                } else
-                    memcpy(q->serv, (const char *)resp + sizeof(res_response_t), res_resp->ret);
-            }
-
-            complete_query(asyncns, q);
-            break;
-        }
-
-        default:
-            ;
-    }
-
-    return 0;
-}
-
-int _g_asyncns_wait(_g_asyncns_t *asyncns, int block) {
-    int handled = 0;
-    assert(asyncns);
-
-    for (;;) {
-        packet_t buf[BUFSIZE/sizeof(packet_t) + 1];
-        ssize_t l;
-
-        if (asyncns->dead) {
-            errno = ECHILD;
-            return -1;
-        }
-
-        if (((l = recv(asyncns->fds[RESPONSE_RECV_FD], buf, sizeof(buf), 0)) < 0)) {
-            fd_set fds;
-
-            if (errno != EAGAIN)
-                return -1;
-
-            if (!block || handled)
-                return 0;
-
-            FD_ZERO(&fds);
-            FD_SET(asyncns->fds[RESPONSE_RECV_FD], &fds);
-
-            if (select(asyncns->fds[RESPONSE_RECV_FD]+1, &fds, NULL, NULL, NULL) < 0)
-                return -1;
-
-            continue;
-        }
-
-        if (handle_response(asyncns, buf, (size_t) l) < 0)
-            return -1;
-
-        handled = 1;
-    }
-}
-
-static _g_asyncns_query_t *alloc_query(_g_asyncns_t *asyncns) {
-    _g_asyncns_query_t *q;
-    assert(asyncns);
-
-    if (asyncns->n_queries >= MAX_QUERIES) {
-        errno = ENOMEM;
-        return NULL;
-    }
-
-    while (asyncns->queries[asyncns->current_index]) {
-
-        asyncns->current_index++;
-        asyncns->current_id++;
-
-        while (asyncns->current_index >= MAX_QUERIES)
-            asyncns->current_index -= MAX_QUERIES;
-    }
-
-    if (!(q = asyncns->queries[asyncns->current_index] = malloc(sizeof(_g_asyncns_query_t)))) {
-        errno = ENOMEM;
-        return NULL;
-    }
-
-    asyncns->n_queries++;
-
-    q->asyncns = asyncns;
-    q->done = 0;
-    q->id = asyncns->current_id;
-    q->done_next = q->done_prev = NULL;
-    q->ret = 0;
-    q->_errno = 0;
-    q->_h_errno = 0;
-    q->addrinfo = NULL;
-    q->userdata = NULL;
-    q->host = q->serv = NULL;
-
-    return q;
-}
-
-_g_asyncns_query_t* _g_asyncns_getaddrinfo(_g_asyncns_t *asyncns, const char *node, const char *service, const struct addrinfo *hints) {
-    addrinfo_request_t data[BUFSIZE/sizeof(addrinfo_request_t) + 1];
-    addrinfo_request_t *req = data;
-    _g_asyncns_query_t *q;
-    assert(asyncns);
-    assert(node || service);
-
-    if (asyncns->dead) {
-        errno = ECHILD;
-        return NULL;
-    }
-
-    if (!(q = alloc_query(asyncns)))
-        return NULL;
-
-    memset(req, 0, sizeof(addrinfo_request_t));
-
-    req->node_len = node ? strlen(node)+1 : 0;
-    req->service_len = service ? strlen(service)+1 : 0;
-
-    req->header.id = q->id;
-    req->header.type = q->type = REQUEST_ADDRINFO;
-    req->header.length = sizeof(addrinfo_request_t) + req->node_len + req->service_len;
-
-    if (req->header.length > BUFSIZE) {
-        errno = ENOMEM;
-        goto fail;
-    }
-
-    if (!(req->hints_is_null = !hints)) {
-        req->ai_flags = hints->ai_flags;
-        req->ai_family = hints->ai_family;
-        req->ai_socktype = hints->ai_socktype;
-        req->ai_protocol = hints->ai_protocol;
-    }
-
-    if (node)
-        strcpy((char*) req + sizeof(addrinfo_request_t), node);
-
-    if (service)
-        strcpy((char*) req + sizeof(addrinfo_request_t) + req->node_len, service);
-
-    if (send(asyncns->fds[REQUEST_SEND_FD], req, req->header.length, MSG_NOSIGNAL) < 0)
-        goto fail;
-
-    return q;
-
-fail:
-    if (q)
-        _g_asyncns_cancel(asyncns, q);
-
-    return NULL;
-}
-
-int _g_asyncns_getaddrinfo_done(_g_asyncns_t *asyncns, _g_asyncns_query_t* q, struct addrinfo **ret_res) {
-    int ret;
-    assert(asyncns);
-    assert(q);
-    assert(q->asyncns == asyncns);
-    assert(q->type == REQUEST_ADDRINFO);
-
-    if (asyncns->dead) {
-        errno = ECHILD;
-        return EAI_SYSTEM;
-    }
-
-    if (!q->done)
-        return EAI_AGAIN;
-
-    *ret_res = q->addrinfo;
-    q->addrinfo = NULL;
-
-    ret = q->ret;
-
-    if (ret == EAI_SYSTEM)
-        errno = q->_errno;
-
-    if (ret != 0)
-        h_errno = q->_h_errno;
-
-    _g_asyncns_cancel(asyncns, q);
-
-    return ret;
-}
-
-_g_asyncns_query_t* _g_asyncns_getnameinfo(_g_asyncns_t *asyncns, const struct sockaddr *sa, socklen_t salen, int flags, int gethost, int getserv) {
-    nameinfo_request_t data[BUFSIZE/sizeof(nameinfo_request_t) + 1];
-    nameinfo_request_t *req = data;
-    _g_asyncns_query_t *q;
-
-    assert(asyncns);
-    assert(sa);
-    assert(salen > 0);
-
-    if (asyncns->dead) {
-        errno = ECHILD;
-        return NULL;
-    }
-
-    if (!(q = alloc_query(asyncns)))
-        return NULL;
-
-    memset(req, 0, sizeof(nameinfo_request_t));
-
-    req->header.id = q->id;
-    req->header.type = q->type = REQUEST_NAMEINFO;
-    req->header.length = sizeof(nameinfo_request_t) + salen;
-
-    if (req->header.length > BUFSIZE) {
-        errno = ENOMEM;
-        goto fail;
-    }
-
-    req->flags = flags;
-    req->sockaddr_len = salen;
-    req->gethost = gethost;
-    req->getserv = getserv;
-
-    memcpy((uint8_t*) req + sizeof(nameinfo_request_t), sa, salen);
-
-    if (send(asyncns->fds[REQUEST_SEND_FD], req, req->header.length, MSG_NOSIGNAL) < 0)
-        goto fail;
-
-    return q;
-
-fail:
-    if (q)
-        _g_asyncns_cancel(asyncns, q);
-
-    return NULL;
-}
-
-int _g_asyncns_getnameinfo_done(_g_asyncns_t *asyncns, _g_asyncns_query_t* q, char *ret_host, size_t hostlen, char *ret_serv, size_t servlen) {
-    int ret;
-    assert(asyncns);
-    assert(q);
-    assert(q->asyncns == asyncns);
-    assert(q->type == REQUEST_NAMEINFO);
-    assert(!ret_host || hostlen);
-    assert(!ret_serv || servlen);
-
-    if (asyncns->dead) {
-        errno = ECHILD;
-        return EAI_SYSTEM;
-    }
-
-    if (!q->done)
-        return EAI_AGAIN;
-
-    if (ret_host && q->host) {
-        strncpy(ret_host, q->host, hostlen);
-        ret_host[hostlen-1] = 0;
-    }
-
-    if (ret_serv && q->serv) {
-        strncpy(ret_serv, q->serv, servlen);
-        ret_serv[servlen-1] = 0;
-    }
-
-    ret = q->ret;
-
-    if (ret == EAI_SYSTEM)
-        errno = q->_errno;
-
-    if (ret != 0)
-        h_errno = q->_h_errno;
-
-    _g_asyncns_cancel(asyncns, q);
-
-    return ret;
-}
-
-static _g_asyncns_query_t * _g_asyncns_res(_g_asyncns_t *asyncns, query_type_t qtype, const char *dname, int class, int type) {
-    res_request_t data[BUFSIZE/sizeof(res_request_t) + 1];
-    res_request_t *req = data;
-    _g_asyncns_query_t *q;
-
-    assert(asyncns);
-    assert(dname);
-
-    if (asyncns->dead) {
-        errno = ECHILD;
-        return NULL;
-    }
-
-    if (!(q = alloc_query(asyncns)))
-        return NULL;
-
-    memset(req, 0, sizeof(res_request_t));
-
-    req->dname_len = strlen(dname) + 1;
-
-    req->header.id = q->id;
-    req->header.type = q->type = qtype;
-    req->header.length = sizeof(res_request_t) + req->dname_len;
-
-    if (req->header.length > BUFSIZE) {
-        errno = ENOMEM;
-        goto fail;
-    }
-
-    req->class = class;
-    req->type = type;
-
-    strcpy((char*) req + sizeof(res_request_t), dname);
-
-    if (send(asyncns->fds[REQUEST_SEND_FD], req, req->header.length, MSG_NOSIGNAL) < 0)
-        goto fail;
-
-    return q;
-
-fail:
-    if (q)
-        _g_asyncns_cancel(asyncns, q);
-
-    return NULL;
-}
-
-_g_asyncns_query_t* _g_asyncns_res_query(_g_asyncns_t *asyncns, const char *dname, int class, int type) {
-    return _g_asyncns_res(asyncns, REQUEST_RES_QUERY, dname, class, type);
-}
-
-_g_asyncns_query_t* _g_asyncns_res_search(_g_asyncns_t *asyncns, const char *dname, int class, int type) {
-    return _g_asyncns_res(asyncns, REQUEST_RES_SEARCH, dname, class, type);
-}
-
-int _g_asyncns_res_done(_g_asyncns_t *asyncns, _g_asyncns_query_t* q, unsigned char **answer) {
-    int ret;
-    assert(asyncns);
-    assert(q);
-    assert(q->asyncns == asyncns);
-    assert(q->type == REQUEST_RES_QUERY || q->type == REQUEST_RES_SEARCH);
-    assert(answer);
-
-    if (asyncns->dead) {
-        errno = ECHILD;
-        return -ECHILD;
-    }
-
-    if (!q->done) {
-        errno = EAGAIN;
-        return -EAGAIN;
-    }
-
-    *answer = (unsigned char *)q->serv;
-    q->serv = NULL;
-
-    ret = q->ret;
-
-    if (ret < 0) {
-        errno = q->_errno;
-        h_errno = q->_h_errno;
-    }
-
-    _g_asyncns_cancel(asyncns, q);
-
-    return ret < 0 ? -errno : ret;
-}
-
-_g_asyncns_query_t* _g_asyncns_getnext(_g_asyncns_t *asyncns) {
-    assert(asyncns);
-    return asyncns->done_head;
-}
-
-int _g_asyncns_getnqueries(_g_asyncns_t *asyncns) {
-    assert(asyncns);
-    return asyncns->n_queries;
-}
-
-void _g_asyncns_cancel(_g_asyncns_t *asyncns, _g_asyncns_query_t* q) {
-    int i;
-    int saved_errno = errno;
-
-    assert(asyncns);
-    assert(q);
-    assert(q->asyncns == asyncns);
-    assert(asyncns->n_queries > 0);
-
-    if (q->done) {
-
-        if (q->done_prev)
-            q->done_prev->done_next = q->done_next;
-        else
-            asyncns->done_head = q->done_next;
-
-        if (q->done_next)
-            q->done_next->done_prev = q->done_prev;
-        else
-            asyncns->done_tail = q->done_prev;
-    }
-
-    i = q->id % MAX_QUERIES;
-    assert(asyncns->queries[i] == q);
-    asyncns->queries[i] = NULL;
-
-    _g_asyncns_freeaddrinfo(q->addrinfo);
-    free(q->host);
-    free(q->serv);
-
-    asyncns->n_queries--;
-    free(q);
-
-    errno = saved_errno;
-}
-
-void _g_asyncns_freeaddrinfo(struct addrinfo *ai) {
-    int saved_errno = errno;
-
-    while (ai) {
-        struct addrinfo *next = ai->ai_next;
-
-        free(ai->ai_addr);
-        free(ai->ai_canonname);
-        free(ai);
-
-        ai = next;
-    }
-
-    errno = saved_errno;
-}
-
-void _g_asyncns_freeanswer(unsigned char *answer) {
-    int saved_errno = errno;
-
-    if (!answer)
-        return;
-
-    /* Please note that this function is new in libasyncns 0.4. In
-     * older versions you were supposed to free the answer directly
-     * with free(). Hence, if this function is changed to do more than
-     * just a simple free() this must be considered ABI/API breakage! */
-
-    free(answer);
-
-    errno = saved_errno;
-}
-
-int _g_asyncns_isdone(_g_asyncns_t *asyncns, _g_asyncns_query_t*q) {
-    assert(asyncns);
-    assert(q);
-    assert(q->asyncns == asyncns);
-
-    return q->done;
-}
-
-void _g_asyncns_setuserdata(_g_asyncns_t *asyncns, _g_asyncns_query_t *q, void *userdata) {
-    assert(q);
-    assert(asyncns);
-    assert(q->asyncns = asyncns);
-
-    q->userdata = userdata;
-}
-
-void* _g_asyncns_getuserdata(_g_asyncns_t *asyncns, _g_asyncns_query_t *q) {
-    assert(q);
-    assert(asyncns);
-    assert(q->asyncns = asyncns);
-
-    return q->userdata;
-}
diff --git a/gio/libasyncns/asyncns.h b/gio/libasyncns/asyncns.h
deleted file mode 100644 (file)
index b3d49ff..0000000
+++ /dev/null
@@ -1,163 +0,0 @@
-#ifndef fooasyncnshfoo
-#define fooasyncnshfoo
-
-/***
-  This file is part of libasyncns.
-
-  Copyright 2005-2008 Lennart Poettering
-
-  libasyncns is free software; you can redistribute it and/or modify
-  it under the terms of the GNU Lesser General Public License as
-  published by the Free Software Foundation, either version 2.1 of the
-  License, or (at your option) any later version.
-
-  libasyncns is distributed in the hope that it will be useful, but
-  WITHOUT ANY WARRANTY; without even the implied warranty of
-  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-  Lesser General Public License for more details.
-
-  You should have received a copy of the GNU Lesser General Public
-  License along with libasyncns. If not, see
-  <http://www.gnu.org/licenses/>.
-***/
-
-#include <sys/types.h>
-#include <sys/socket.h>
-#include <netdb.h>
-
-/** \mainpage
- *
- * \section moo Method of operation
- *
- * To use libasyncns allocate an _g_asyncns_t object with
- * _g_asyncns_new(). This will spawn a number of worker threads (or processes, depending on what is available) which
- * are subsequently used to process the queries the controlling
- * program issues via _g_asyncns_getaddrinfo() and
- * _g_asyncns_getnameinfo(). Use _g_asyncns_free() to shut down the worker
- * threads/processes.
- *
- * Since libasyncns may fork off new processes you have to make sure that
- * your program is not irritated by spurious SIGCHLD signals.
- */
-
-/** \example asyncns-test.c
- * An example program */
-
-#ifdef  __cplusplus
-extern "C" {
-#endif
-
-/** An opaque libasyncns session structure */
-typedef struct asyncns _g_asyncns_t;
-
-/** An opaque libasyncns query structure */
-typedef struct _g_asyncns_query _g_asyncns_query_t;
-
-/** Allocate a new libasyncns session with n_proc worker processes/threads */
-_g_asyncns_t* _g_asyncns_new(unsigned n_proc);
-
-/** Free a libasyncns session. This destroys all attached
- * _g_asyncns_query_t objects automatically */
-void _g_asyncns_free(_g_asyncns_t *asyncns);
-
-/** Return the UNIX file descriptor to select() for readability
- * on. Use this function to integrate libasyncns with your custom main
- * loop. */
-int _g_asyncns_fd(_g_asyncns_t *asyncns);
-
-/** Process pending responses. After this function is called you can
- * get the next completed query object(s) using _g_asyncns_getnext(). If
- * block is non-zero wait until at least one response has been
- * processed. If block is zero, process all pending responses and
- * return. */
-int _g_asyncns_wait(_g_asyncns_t *asyncns, int block);
-
-/** Issue a name to address query on the specified session. The
- * arguments are compatible with the ones of libc's
- * getaddrinfo(3). The function returns a new query object. When the
- * query is completed you may retrieve the results using
- * _g_asyncns_getaddrinfo_done().*/
-_g_asyncns_query_t* _g_asyncns_getaddrinfo(_g_asyncns_t *asyncns, const char *node, const char *service, const struct addrinfo *hints);
-
-/** Retrieve the results of a preceding _g_asyncns_getaddrinfo()
- * call. Returns a addrinfo structure and a return value compatible
- * with libc's getaddrinfo(3). The query object q is destroyed by this
- * call and may not be used any further. Make sure to free the
- * returned addrinfo structure with _g_asyncns_freeaddrinfo() and not
- * libc's freeaddrinfo(3)! If the query is not completed yet EAI_AGAIN
- * is returned.*/
-int _g_asyncns_getaddrinfo_done(_g_asyncns_t *asyncns, _g_asyncns_query_t* q, struct addrinfo **ret_res);
-
-/** Issue an address to name query on the specified session. The
- * arguments are compatible with the ones of libc's
- * getnameinfo(3). The function returns a new query object. When the
- * query is completed you may retrieve the results using
- * _g_asyncns_getnameinfo_done(). Set gethost (resp. getserv) to non-zero
- * if you want to query the hostname (resp. the service name). */
-_g_asyncns_query_t* _g_asyncns_getnameinfo(_g_asyncns_t *asyncns, const struct sockaddr *sa, socklen_t salen, int flags, int gethost, int getserv);
-
-/** Retrieve the results of a preceding _g_asyncns_getnameinfo()
- * call. Returns the hostname and the service name in ret_host and
- * ret_serv. The query object q is destroyed by this call and may not
- * be used any further. If the query is not completed yet EAI_AGAIN is
- * returned. */
-int _g_asyncns_getnameinfo_done(_g_asyncns_t *asyncns, _g_asyncns_query_t* q, char *ret_host, size_t hostlen, char *ret_serv, size_t servlen);
-
-/** Issue a resolver query on the specified session. The arguments are
- * compatible with the ones of libc's res_query(3). The function returns a new
- * query object. When the query is completed you may retrieve the results using
- * _g_asyncns_res_done().  */
-_g_asyncns_query_t* _g_asyncns_res_query(_g_asyncns_t *asyncns, const char *dname, int class, int type);
-
-/** Issue an resolver query on the specified session. The arguments are
- * compatible with the ones of libc's res_search(3). The function returns a new
- * query object. When the query is completed you may retrieve the results using
- * _g_asyncns_res_done().  */
-_g_asyncns_query_t* _g_asyncns_res_search(_g_asyncns_t *asyncns, const char *dname, int class, int type);
-
-/** Retrieve the results of a preceding _g_asyncns_res_query() or
- * _g_asyncns_res_search call.  The query object q is destroyed by this
- * call and may not be used any further. Returns a pointer to the
- * answer of the res_query call. If the query is not completed yet
- * -EAGAIN is returned, on failure -errno is returned, otherwise the
- * length of answer is returned. Make sure to free the answer is a
- * call to _g_asyncns_freeanswer(). */
-int _g_asyncns_res_done(_g_asyncns_t *asyncns, _g_asyncns_query_t* q, unsigned char **answer);
-
-/** Return the next completed query object. If no query has been
- * completed yet, return NULL. Please note that you need to run
- * _g_asyncns_wait() before this function will return sensible data.  */
-_g_asyncns_query_t* _g_asyncns_getnext(_g_asyncns_t *asyncns);
-
-/** Return the number of query objects (completed or not) attached to
- * this session */
-int _g_asyncns_getnqueries(_g_asyncns_t *asyncns);
-
-/** Cancel a currently running query. q is is destroyed by this call
- * and may not be used any futher. */
-void _g_asyncns_cancel(_g_asyncns_t *asyncns, _g_asyncns_query_t* q);
-
-/** Free the addrinfo structure as returned by
- * _g_asyncns_getaddrinfo_done(). Make sure to use this functions instead
- * of the libc's freeaddrinfo()! */
-void _g_asyncns_freeaddrinfo(struct addrinfo *ai);
-
-/** Free the answer data as returned by _g_asyncns_res_done().*/
-void _g_asyncns_freeanswer(unsigned char *answer);
-
-/** Returns non-zero when the query operation specified by q has been completed */
-int _g_asyncns_isdone(_g_asyncns_t *asyncns, _g_asyncns_query_t*q);
-
-/** Assign some opaque userdata with a query object */
-void _g_asyncns_setuserdata(_g_asyncns_t *asyncns, _g_asyncns_query_t *q, void *userdata);
-
-/** Return userdata assigned to a query object. Use
- * _g_asyncns_setuserdata() to set this data. If no data has been set
- * prior to this call it returns NULL. */
-void* _g_asyncns_getuserdata(_g_asyncns_t *asyncns, _g_asyncns_query_t *q);
-
-#ifdef  __cplusplus
-}
-#endif
-
-#endif
diff --git a/gio/libasyncns/g-asyncns.h b/gio/libasyncns/g-asyncns.h
deleted file mode 100644 (file)
index 8a526d1..0000000
+++ /dev/null
@@ -1,33 +0,0 @@
-/* GLIB - Library of useful routines for C programming
- * Copyright (C) 2008 Red Hat, Inc.
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the
- * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
- * Boston, MA 02111-1307, USA.
- */
-#ifndef __G_ASYNCNS_H__
-
-#include "config.h"
-
-/* We want to build the fork-based version, not the threaded version. */
-#undef HAVE_PTHREAD
-
-/* asyncns.c removed this for #580301, but that appears to have been wrong */
-#if HAVE_ARPA_NAMESER_COMPAT_H
-#include <arpa/nameser_compat.h>
-#endif
-
-#include "asyncns.h"
-
-#endif
diff --git a/gio/libasyncns/update.sh b/gio/libasyncns/update.sh
deleted file mode 100644 (file)
index 4c43ca5..0000000
+++ /dev/null
@@ -1,20 +0,0 @@
-#!/bin/sh
-
-if test $# = 1 ; then 
-  ORIGINAL=$1
-else
-  echo "Usage: update.sh /path/to/libasyncns" 1>&2
-  exit 1
-fi
-
-if test -f $ORIGINAL/libasyncns/asyncns.c ; then : ; else
-  echo "Usage: update.sh /path/to/libasyncns" 1>&2
-  exit 1
-fi
-
-for i in asyncns.c asyncns.h ; do
-  sed -e 's/\([^a-z]\)asyncns_/\1_g_asyncns_/g' \
-      -e 's/^asyncns_/_g_asyncns_/' \
-      -e 's/<config\.h>/"g-asyncns\.h"/' \
-    $ORIGINAL/libasyncns/$i > $i
-done
index 0b2a3fd..cec4e26 100644 (file)
@@ -40,13 +40,11 @@ static int nlookups = 0;
 static void G_GNUC_NORETURN
 usage (void)
 {
-       fprintf (stderr, "Usage: resolver [-t] [-s] [hostname | IP | service/protocol/domain ] ...\n");
-       fprintf (stderr, "       resolver [-t] [-s] -c NUMBER [hostname | IP | service/protocol/domain ]\n");
-       fprintf (stderr, "       Use -t to enable threading.\n");
+       fprintf (stderr, "Usage: resolver [-s] [hostname | IP | service/protocol/domain ] ...\n");
+       fprintf (stderr, "       resolver [-s] -c NUMBER [hostname | IP | service/protocol/domain ]\n");
        fprintf (stderr, "       Use -s to do synchronous lookups.\n");
-       fprintf (stderr, "       Both together will result in simultaneous lookups in multiple threads\n");
-       fprintf (stderr, "       Use -c NUMBER(and only a single resolvable argument) to test GSocketConnectable.\n");
-       fprintf (stderr, "       The given NUMBER determines how often the connectable will be enumerated.\n");
+       fprintf (stderr, "       Use -c NUMBER (and only a single resolvable argument) to test GSocketConnectable.\n");
+       fprintf (stderr, "       The given NUMBER determines how many times the connectable will be enumerated.\n");
        exit (1);
 }
 
@@ -198,21 +196,12 @@ lookup_thread (gpointer arg)
 }
 
 static void
-start_threaded_lookups (char **argv, int argc)
-{
-  int i;
-
-  for (i = 0; i < argc; i++)
-    g_thread_create (lookup_thread, argv[i], FALSE, NULL);
-}
-
-static void
 start_sync_lookups (char **argv, int argc)
 {
   int i;
 
   for (i = 0; i < argc; i++)
-    lookup_one_sync (argv[i]);
+    g_thread_create (lookup_thread, argv[i], FALSE, NULL);
 }
 
 static void
@@ -438,24 +427,19 @@ async_cancel (GIOChannel *source, GIOCondition cond, gpointer cancel)
 int
 main (int argc, char **argv)
 {
-  gboolean threaded = FALSE, synchronous = FALSE;
+  gboolean synchronous = FALSE;
   guint connectable_count = 0;
 #ifdef G_OS_UNIX
   GIOChannel *chan;
   guint watch;
 #endif
 
-  /* We can't use GOptionContext because we use the arguments to
-   * decide whether or not to call g_thread_init().
-   */
+  g_type_init ();
+
+  /* FIXME: use GOptionContext */
   while (argc >= 2 && argv[1][0] == '-')
     {
-      if (!strcmp (argv[1], "-t"))
-        {
-          g_thread_init (NULL);
-          threaded = TRUE;
-        }
-      else if (!strcmp (argv[1], "-s"))
+      if (!strcmp (argv[1], "-s"))
         synchronous = TRUE;
       else if (!strcmp (argv[1], "-c"))
         {
@@ -469,7 +453,6 @@ main (int argc, char **argv)
       argv++;
       argc--;
     }
-  g_type_init ();
 
   if (argc < 2 || (argc > 2 && connectable_count))
     usage ();
@@ -504,9 +487,7 @@ main (int argc, char **argv)
     }
   else
     {
-      if (threaded && synchronous)
-        start_threaded_lookups (argv + 1, argc - 1);
-      else if (synchronous)
+      if (synchronous)
         start_sync_lookups (argv + 1, argc - 1);
       else
         start_async_lookups (argv + 1, argc - 1);