/** * soup_address_resolve_async: * @addr: a #SoupAddress * @async_context: (allow-none): the #GMainContext to call @callback from * @cancellable: a #GCancellable object, or %NULL * @callback: (scope async): callback to call with the result * @user_data: data for @callback * * Asynchronously resolves the missing half of @addr (its IP address * if it was created with soup_address_new(), or its hostname if it * was created with soup_address_new_from_sockaddr() or * soup_address_new_any().) * * If @cancellable is non-%NULL, it can be used to cancel the * resolution. @callback will still be invoked in this case, with a * status of %SOUP_STATUS_CANCELLED. * * It is safe to call this more than once on a given address, from the * same thread, with the same @async_context (and doing so will not * result in redundant DNS queries being made). But it is not safe to * call from multiple threads, or with different @async_contexts, or * mixed with calls to soup_address_resolve_sync(). **/ void soup_address_resolve_async (SoupAddress *addr, GMainContext *async_context, GCancellable *cancellable, SoupAddressCallback callback, gpointer user_data) { SoupAddressPrivate *priv; SoupAddressResolveAsyncData *res_data; GResolver *resolver; gboolean already_started; g_return_if_fail (SOUP_IS_ADDRESS (addr)); priv = SOUP_ADDRESS_GET_PRIVATE (addr); g_return_if_fail (priv->name || priv->sockaddr); /* We don't need to do locking here because the async case is * not intended to be thread-safe. */ if (priv->name && priv->sockaddr && !callback) return; res_data = g_slice_new0 (SoupAddressResolveAsyncData); res_data->callback = callback; res_data->callback_data = user_data; already_started = priv->async_lookups != NULL; priv->async_lookups = g_slist_prepend (priv->async_lookups, res_data); if (already_started) return; g_object_ref (addr); if (priv->name && priv->sockaddr) { soup_add_completion (async_context, idle_complete_resolve, addr); return; } resolver = g_resolver_get_default (); if (async_context) g_main_context_push_thread_default (async_context); if (priv->name) { g_resolver_lookup_by_name_async (resolver, priv->name, cancellable, lookup_resolved, addr); } else { GInetAddress *gia; gia = soup_address_make_inet_address (addr); g_resolver_lookup_by_address_async (resolver, gia, cancellable, lookup_resolved, addr); g_object_unref (gia); } if (async_context) g_main_context_pop_thread_default (async_context); g_object_unref (resolver); }
static void do_idle_run_queue (SoupSession *session) { SoupSessionAsyncPrivate *priv = SOUP_SESSION_ASYNC_GET_PRIVATE (session); if (!priv->idle_run_queue_source) { priv->idle_run_queue_source = soup_add_completion ( soup_session_get_async_context (session), idle_run_queue, session); } }
static void soupProxyResolverWkGetProxyURIAsync(SoupProxyURIResolver* proxyResolver, SoupURI* uri, GMainContext* asyncContext, GCancellable*, SoupProxyURIResolverCallback callback, void* userData) { SoupWkAsyncData* ssad; ssad = g_slice_new0(SoupWkAsyncData); ssad->proxyResolver = SOUP_PROXY_URI_RESOLVER(g_object_ref(proxyResolver)); ssad->uri = soup_uri_copy(uri); ssad->callback = callback; ssad->userData = userData; soup_add_completion(asyncContext, idle_return_proxy_uri, ssad); }
static void libproxy_threadpool_func (gpointer user_data, gpointer thread_data) { SoupGNOMEAsyncData *sgad = user_data; /* We don't just call get_proxy_for_uri here, since it's * possible that the proxy mode has changed... */ sgad->status = get_proxy_uri_sync (sgad->proxy_uri_resolver, sgad->uri, sgad->cancellable, &sgad->proxy_uri); soup_add_completion (sgad->async_context, resolved_proxy, sgad); }
static gpointer queue_message_thread (gpointer data) { SoupMessageQueueItem *item = data; soup_session_process_queue_item (item->session, item, NULL, TRUE); if (item->callback) { soup_add_completion (soup_session_get_async_context (item->session), queue_message_callback, item); } else soup_message_queue_item_unref (item); return NULL; }
static void get_proxy_uri_async (SoupProxyURIResolver *proxy_uri_resolver, SoupURI *uri, GMainContext *async_context, GCancellable *cancellable, SoupProxyURIResolverCallback callback, gpointer user_data) { SoupGNOMEAsyncData *sgad; sgad = g_slice_new0 (SoupGNOMEAsyncData); sgad->proxy_uri_resolver = g_object_ref (proxy_uri_resolver); sgad->cancellable = cancellable ? g_object_ref (cancellable) : NULL; sgad->callback = callback; sgad->user_data = user_data; G_LOCK (resolver_gnome); switch (proxy_mode) { case SOUP_PROXY_RESOLVER_GNOME_MODE_NONE: sgad->proxy_uri = NULL; sgad->status = SOUP_STATUS_OK; break; case SOUP_PROXY_RESOLVER_GNOME_MODE_MANUAL: /* We know libproxy won't do PAC or WPAD in this case, * so we can make a "blocking" call to it. */ sgad->status = get_proxy_for_uri (uri, &sgad->proxy_uri); break; case SOUP_PROXY_RESOLVER_GNOME_MODE_AUTO: /* FIXME: cancellable */ sgad->uri = soup_uri_copy (uri); sgad->async_context = async_context ? g_main_context_ref (async_context) : NULL; g_thread_pool_push (libproxy_threadpool, sgad, NULL); G_UNLOCK (resolver_gnome); return; } G_UNLOCK (resolver_gnome); soup_add_completion (async_context, resolved_proxy, sgad); }
static void test_server_shutdown (void) { g_object_add_weak_pointer (G_OBJECT (test_server), (gpointer *)&test_server); if (server_thread) { soup_add_completion (soup_server_get_async_context (test_server), idle_quit_server, test_server); g_thread_join (server_thread); } else soup_server_quit (test_server); g_object_unref (test_server); if (test_server) { errors++; debug_printf (1, "leaked SoupServer!\n"); g_object_remove_weak_pointer (G_OBJECT (test_server), (gpointer *)&test_server); } }
void soup_test_server_quit_unref (SoupServer *server) { GThread *thread; g_object_add_weak_pointer (G_OBJECT (server), (gpointer *)&server); thread = g_object_get_data (G_OBJECT (server), "thread"); if (thread) { soup_add_completion (soup_server_get_async_context (server), idle_quit_server, server); g_thread_join (thread); } else soup_server_quit (server); g_object_unref (server); if (server) { errors++; debug_printf (1, "leaked SoupServer!\n"); g_object_remove_weak_pointer (G_OBJECT (server), (gpointer *)&server); } }
void soup_message_io_unpause (SoupMessage *msg) { SoupMessagePrivate *priv = SOUP_MESSAGE_GET_PRIVATE (msg); SoupMessageIOData *io = priv->io_data; gboolean non_blocking; GMainContext *async_context; g_return_if_fail (io != NULL); g_object_get (io->sock, SOUP_SOCKET_FLAG_NONBLOCKING, &non_blocking, SOUP_SOCKET_ASYNC_CONTEXT, &async_context, NULL); if (non_blocking) { if (!io->unpause_source) { io->unpause_source = soup_add_completion ( async_context, io_unpause_internal, msg); } } else io_unpause_internal (msg); if (async_context) g_main_context_unref (async_context); }