mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2024-11-09 19:06:15 +01:00
gio: port networking classes from GSimpleAsyncResult to GTask
https://bugzilla.gnome.org/show_bug.cgi?id=661767
This commit is contained in:
parent
130d0fdac0
commit
d21309464c
@ -29,7 +29,7 @@
|
||||
#include "gasyncresult.h"
|
||||
#include "gcancellable.h"
|
||||
#include "gproxyresolver.h"
|
||||
#include "gsimpleasyncresult.h"
|
||||
#include "gtask.h"
|
||||
|
||||
#include "giomodule.h"
|
||||
#include "giomodule-priv.h"
|
||||
@ -93,29 +93,17 @@ g_dummy_proxy_resolver_lookup_async (GProxyResolver *resolver,
|
||||
gpointer user_data)
|
||||
{
|
||||
GError *error = NULL;
|
||||
GSimpleAsyncResult *simple;
|
||||
GTask *task;
|
||||
gchar **proxies;
|
||||
|
||||
task = g_task_new (resolver, cancellable, callback, user_data);
|
||||
|
||||
proxies = g_dummy_proxy_resolver_lookup (resolver, uri, cancellable, &error);
|
||||
|
||||
|
||||
simple = g_simple_async_result_new (G_OBJECT (resolver),
|
||||
callback, user_data,
|
||||
g_dummy_proxy_resolver_lookup_async);
|
||||
|
||||
if (proxies == NULL)
|
||||
{
|
||||
g_simple_async_result_take_error (simple, error);
|
||||
}
|
||||
if (proxies)
|
||||
g_task_return_pointer (task, proxies, (GDestroyNotify) g_strfreev);
|
||||
else
|
||||
{
|
||||
g_simple_async_result_set_op_res_gpointer (simple,
|
||||
proxies,
|
||||
NULL);
|
||||
}
|
||||
|
||||
g_simple_async_result_complete_in_idle (simple);
|
||||
g_object_unref (simple);
|
||||
g_task_return_error (task, error);
|
||||
g_object_unref (task);
|
||||
}
|
||||
|
||||
static gchar **
|
||||
@ -123,17 +111,9 @@ g_dummy_proxy_resolver_lookup_finish (GProxyResolver *resolver,
|
||||
GAsyncResult *result,
|
||||
GError **error)
|
||||
{
|
||||
if (G_IS_SIMPLE_ASYNC_RESULT (result))
|
||||
{
|
||||
GSimpleAsyncResult *simple = G_SIMPLE_ASYNC_RESULT (result);
|
||||
g_return_val_if_fail (g_task_is_valid (result, resolver), NULL);
|
||||
|
||||
if (g_simple_async_result_propagate_error (simple, error))
|
||||
return NULL;
|
||||
|
||||
return g_simple_async_result_get_op_res_gpointer (simple);
|
||||
}
|
||||
|
||||
return NULL;
|
||||
return g_task_propagate_pointer (G_TASK (result), error);
|
||||
}
|
||||
|
||||
static void
|
||||
|
@ -32,7 +32,7 @@
|
||||
#include "gnetworkingprivate.h"
|
||||
#include "gproxyaddressenumerator.h"
|
||||
#include "gresolver.h"
|
||||
#include "gsimpleasyncresult.h"
|
||||
#include "gtask.h"
|
||||
#include "gsocketaddressenumerator.h"
|
||||
#include "gioerror.h"
|
||||
#include "gsocketconnectable.h"
|
||||
@ -852,19 +852,19 @@ got_addresses (GObject *source_object,
|
||||
GAsyncResult *result,
|
||||
gpointer user_data)
|
||||
{
|
||||
GSimpleAsyncResult *simple = user_data;
|
||||
GNetworkAddressAddressEnumerator *addr_enum =
|
||||
g_simple_async_result_get_op_res_gpointer (simple);
|
||||
GTask *task = user_data;
|
||||
GNetworkAddressAddressEnumerator *addr_enum = g_task_get_source_object (task);
|
||||
GResolver *resolver = G_RESOLVER (source_object);
|
||||
GList *addresses;
|
||||
GError *error = NULL;
|
||||
GSocketAddress *sockaddr;
|
||||
|
||||
if (!addr_enum->addr->priv->sockaddrs)
|
||||
{
|
||||
addresses = g_resolver_lookup_by_name_finish (resolver, result, &error);
|
||||
|
||||
if (error)
|
||||
g_simple_async_result_take_error (simple, error);
|
||||
g_task_return_error (task, error);
|
||||
else
|
||||
g_network_address_set_addresses (addr_enum->addr, addresses);
|
||||
}
|
||||
@ -874,8 +874,17 @@ got_addresses (GObject *source_object,
|
||||
addr_enum->addresses = addr_enum->addr->priv->sockaddrs;
|
||||
addr_enum->next = addr_enum->addresses;
|
||||
|
||||
g_simple_async_result_complete (simple);
|
||||
g_object_unref (simple);
|
||||
if (addr_enum->next)
|
||||
{
|
||||
sockaddr = g_object_ref (addr_enum->next->data);
|
||||
addr_enum->next = addr_enum->next->next;
|
||||
}
|
||||
else
|
||||
sockaddr = NULL;
|
||||
|
||||
if (!error)
|
||||
g_task_return_pointer (task, sockaddr, g_object_unref);
|
||||
g_object_unref (task);
|
||||
}
|
||||
|
||||
static void
|
||||
@ -886,11 +895,10 @@ g_network_address_address_enumerator_next_async (GSocketAddressEnumerator *enum
|
||||
{
|
||||
GNetworkAddressAddressEnumerator *addr_enum =
|
||||
G_NETWORK_ADDRESS_ADDRESS_ENUMERATOR (enumerator);
|
||||
GSimpleAsyncResult *simple;
|
||||
GSocketAddress *sockaddr;
|
||||
GTask *task;
|
||||
|
||||
simple = g_simple_async_result_new (G_OBJECT (enumerator),
|
||||
callback, user_data,
|
||||
g_network_address_address_enumerator_next_async);
|
||||
task = g_task_new (addr_enum, cancellable, callback, user_data);
|
||||
|
||||
if (addr_enum->addresses == NULL)
|
||||
{
|
||||
@ -898,11 +906,10 @@ g_network_address_address_enumerator_next_async (GSocketAddressEnumerator *enum
|
||||
{
|
||||
GResolver *resolver = g_resolver_get_default ();
|
||||
|
||||
g_simple_async_result_set_op_res_gpointer (simple, g_object_ref (addr_enum), g_object_unref);
|
||||
g_resolver_lookup_by_name_async (resolver,
|
||||
addr_enum->addr->priv->hostname,
|
||||
cancellable,
|
||||
got_addresses, simple);
|
||||
got_addresses, task);
|
||||
return;
|
||||
}
|
||||
|
||||
@ -910,8 +917,16 @@ g_network_address_address_enumerator_next_async (GSocketAddressEnumerator *enum
|
||||
addr_enum->next = addr_enum->addresses;
|
||||
}
|
||||
|
||||
g_simple_async_result_complete_in_idle (simple);
|
||||
g_object_unref (simple);
|
||||
if (addr_enum->next)
|
||||
{
|
||||
sockaddr = g_object_ref (addr_enum->next->data);
|
||||
addr_enum->next = addr_enum->next->next;
|
||||
}
|
||||
else
|
||||
sockaddr = NULL;
|
||||
|
||||
g_task_return_pointer (task, sockaddr, g_object_unref);
|
||||
g_object_unref (task);
|
||||
}
|
||||
|
||||
static GSocketAddress *
|
||||
@ -919,21 +934,9 @@ g_network_address_address_enumerator_next_finish (GSocketAddressEnumerator *enu
|
||||
GAsyncResult *result,
|
||||
GError **error)
|
||||
{
|
||||
GNetworkAddressAddressEnumerator *addr_enum =
|
||||
G_NETWORK_ADDRESS_ADDRESS_ENUMERATOR (enumerator);
|
||||
GSimpleAsyncResult *simple = G_SIMPLE_ASYNC_RESULT (result);
|
||||
GSocketAddress *sockaddr;
|
||||
g_return_val_if_fail (g_task_is_valid (result, enumerator), NULL);
|
||||
|
||||
if (g_simple_async_result_propagate_error (simple, error))
|
||||
return NULL;
|
||||
else if (!addr_enum->next)
|
||||
return NULL;
|
||||
else
|
||||
{
|
||||
sockaddr = addr_enum->next->data;
|
||||
addr_enum->next = addr_enum->next->next;
|
||||
return g_object_ref (sockaddr);
|
||||
}
|
||||
return g_task_propagate_pointer (G_TASK (result), error);
|
||||
}
|
||||
|
||||
static void
|
||||
|
@ -28,7 +28,7 @@
|
||||
#include "ginitable.h"
|
||||
#include "gioenumtypes.h"
|
||||
#include "giomodule-priv.h"
|
||||
#include "gsimpleasyncresult.h"
|
||||
#include "gtask.h"
|
||||
|
||||
/**
|
||||
* SECTION:gnetworkmonitor
|
||||
@ -148,18 +148,15 @@ g_network_monitor_real_can_reach_async (GNetworkMonitor *monitor,
|
||||
GAsyncReadyCallback callback,
|
||||
gpointer user_data)
|
||||
{
|
||||
GSimpleAsyncResult *simple;
|
||||
GTask *task;
|
||||
GError *error = NULL;
|
||||
|
||||
simple = g_simple_async_result_new (G_OBJECT (monitor),
|
||||
callback, user_data,
|
||||
g_network_monitor_real_can_reach_async);
|
||||
task = g_task_new (monitor, cancellable, callback, user_data);
|
||||
if (g_network_monitor_can_reach (monitor, connectable, cancellable, &error))
|
||||
g_simple_async_result_set_op_res_gboolean (simple, TRUE);
|
||||
g_task_return_boolean (task, TRUE);
|
||||
else
|
||||
g_simple_async_result_take_error (simple, error);
|
||||
g_simple_async_result_complete_in_idle (simple);
|
||||
g_object_unref (simple);
|
||||
g_task_return_error (task, error);
|
||||
g_object_unref (task);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -199,15 +196,9 @@ g_network_monitor_real_can_reach_finish (GNetworkMonitor *monitor,
|
||||
GAsyncResult *result,
|
||||
GError **error)
|
||||
{
|
||||
GSimpleAsyncResult *simple;
|
||||
g_return_val_if_fail (g_task_is_valid (result, monitor), FALSE);
|
||||
|
||||
g_return_val_if_fail (g_simple_async_result_is_valid (result, G_OBJECT (monitor), g_network_monitor_real_can_reach_async), FALSE);
|
||||
|
||||
simple = G_SIMPLE_ASYNC_RESULT (result);
|
||||
if (g_simple_async_result_propagate_error (simple, error))
|
||||
return FALSE;
|
||||
else
|
||||
return g_simple_async_result_get_op_res_gboolean (simple);
|
||||
return g_task_propagate_boolean (G_TASK (result), error);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -33,7 +33,7 @@
|
||||
#include "gnetworkaddress.h"
|
||||
#include "gnetworkingprivate.h"
|
||||
#include "gresolver.h"
|
||||
#include "gsimpleasyncresult.h"
|
||||
#include "gtask.h"
|
||||
#include "gsocketaddressenumerator.h"
|
||||
#include "gsocketconnectable.h"
|
||||
#include "gsrvtarget.h"
|
||||
@ -395,9 +395,6 @@ typedef struct {
|
||||
|
||||
GError *error;
|
||||
|
||||
/* For async operation */
|
||||
GCancellable *cancellable;
|
||||
GSimpleAsyncResult *result;
|
||||
} GNetworkServiceAddressEnumerator;
|
||||
|
||||
typedef struct {
|
||||
@ -530,13 +527,13 @@ g_network_service_address_enumerator_next (GSocketAddressEnumerator *enumerator
|
||||
return ret;
|
||||
}
|
||||
|
||||
static void next_async_resolved_targets (GObject *source_object,
|
||||
GAsyncResult *result,
|
||||
gpointer user_data);
|
||||
static void next_async_have_targets (GNetworkServiceAddressEnumerator *srv_enum);
|
||||
static void next_async_have_address (GObject *source_object,
|
||||
GAsyncResult *result,
|
||||
gpointer user_data);
|
||||
static void next_async_resolved_targets (GObject *source_object,
|
||||
GAsyncResult *result,
|
||||
gpointer user_data);
|
||||
static void next_async_have_targets (GTask *srv_enum);
|
||||
static void next_async_have_address (GObject *source_object,
|
||||
GAsyncResult *result,
|
||||
gpointer user_data);
|
||||
|
||||
static void
|
||||
g_network_service_address_enumerator_next_async (GSocketAddressEnumerator *enumerator,
|
||||
@ -546,15 +543,9 @@ g_network_service_address_enumerator_next_async (GSocketAddressEnumerator *enum
|
||||
{
|
||||
GNetworkServiceAddressEnumerator *srv_enum =
|
||||
G_NETWORK_SERVICE_ADDRESS_ENUMERATOR (enumerator);
|
||||
GTask *task;
|
||||
|
||||
g_return_if_fail (srv_enum->result == NULL);
|
||||
|
||||
srv_enum->result = g_simple_async_result_new (G_OBJECT (enumerator),
|
||||
callback, user_data,
|
||||
g_network_service_address_enumerator_next_async);
|
||||
|
||||
if (cancellable)
|
||||
srv_enum->cancellable = g_object_ref (cancellable);
|
||||
task = g_task_new (enumerator, cancellable, callback, user_data);
|
||||
|
||||
/* If we haven't yet resolved srv, do that */
|
||||
if (!srv_enum->srv->priv->targets)
|
||||
@ -565,10 +556,10 @@ g_network_service_address_enumerator_next_async (GSocketAddressEnumerator *enum
|
||||
srv_enum->srv->priv->domain,
|
||||
cancellable,
|
||||
next_async_resolved_targets,
|
||||
srv_enum);
|
||||
task);
|
||||
}
|
||||
else
|
||||
next_async_have_targets (srv_enum);
|
||||
next_async_have_targets (task);
|
||||
}
|
||||
|
||||
static void
|
||||
@ -576,7 +567,8 @@ next_async_resolved_targets (GObject *source_object,
|
||||
GAsyncResult *result,
|
||||
gpointer user_data)
|
||||
{
|
||||
GNetworkServiceAddressEnumerator *srv_enum = user_data;
|
||||
GTask *task = user_data;
|
||||
GNetworkServiceAddressEnumerator *srv_enum = g_task_get_source_object (task);
|
||||
GError *error = NULL;
|
||||
GList *targets;
|
||||
|
||||
@ -593,23 +585,21 @@ next_async_resolved_targets (GObject *source_object,
|
||||
|
||||
if (error)
|
||||
{
|
||||
GSimpleAsyncResult *simple = srv_enum->result;
|
||||
|
||||
srv_enum->result = NULL;
|
||||
g_simple_async_result_take_error (simple, error);
|
||||
g_simple_async_result_complete (simple);
|
||||
g_object_unref (simple);
|
||||
g_task_return_error (task, error);
|
||||
g_object_unref (task);
|
||||
}
|
||||
else
|
||||
{
|
||||
srv_enum->t = srv_enum->srv->priv->targets = targets;
|
||||
next_async_have_targets (srv_enum);
|
||||
next_async_have_targets (task);
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
next_async_have_targets (GNetworkServiceAddressEnumerator *srv_enum)
|
||||
next_async_have_targets (GTask *task)
|
||||
{
|
||||
GNetworkServiceAddressEnumerator *srv_enum = g_task_get_source_object (task);
|
||||
|
||||
/* Delegate to GNetworkAddress */
|
||||
if (srv_enum->addr_enum == NULL && srv_enum->t)
|
||||
{
|
||||
@ -631,23 +621,21 @@ next_async_have_targets (GNetworkServiceAddressEnumerator *srv_enum)
|
||||
if (srv_enum->addr_enum)
|
||||
{
|
||||
g_socket_address_enumerator_next_async (srv_enum->addr_enum,
|
||||
srv_enum->cancellable,
|
||||
g_task_get_cancellable (task),
|
||||
next_async_have_address,
|
||||
srv_enum);
|
||||
task);
|
||||
}
|
||||
else
|
||||
{
|
||||
GSimpleAsyncResult *simple = srv_enum->result;
|
||||
srv_enum->result = NULL;
|
||||
|
||||
if (srv_enum->error)
|
||||
{
|
||||
g_simple_async_result_take_error (simple, srv_enum->error);
|
||||
g_task_return_error (task, srv_enum->error);
|
||||
srv_enum->error = NULL;
|
||||
}
|
||||
else
|
||||
g_task_return_pointer (task, NULL, NULL);
|
||||
|
||||
g_simple_async_result_complete (simple);
|
||||
g_object_unref (simple);
|
||||
g_object_unref (task);
|
||||
}
|
||||
}
|
||||
|
||||
@ -656,7 +644,8 @@ next_async_have_address (GObject *source_object,
|
||||
GAsyncResult *result,
|
||||
gpointer user_data)
|
||||
{
|
||||
GNetworkServiceAddressEnumerator *srv_enum = user_data;
|
||||
GTask *task = user_data;
|
||||
GNetworkServiceAddressEnumerator *srv_enum = g_task_get_source_object (task);
|
||||
GSocketAddress *address;
|
||||
GError *error = NULL;
|
||||
|
||||
@ -677,20 +666,12 @@ next_async_have_address (GObject *source_object,
|
||||
g_object_unref (srv_enum->addr_enum);
|
||||
srv_enum->addr_enum = NULL;
|
||||
|
||||
next_async_have_targets (srv_enum);
|
||||
next_async_have_targets (task);
|
||||
}
|
||||
else
|
||||
{
|
||||
GSimpleAsyncResult *simple = srv_enum->result;
|
||||
|
||||
srv_enum->result = NULL;
|
||||
|
||||
if (address)
|
||||
g_simple_async_result_set_op_res_gpointer (simple,
|
||||
address, g_object_unref);
|
||||
|
||||
g_simple_async_result_complete (simple);
|
||||
g_object_unref (simple);
|
||||
g_task_return_pointer (task, address, g_object_unref);
|
||||
g_object_unref (task);
|
||||
}
|
||||
}
|
||||
|
||||
@ -699,14 +680,7 @@ g_network_service_address_enumerator_next_finish (GSocketAddressEnumerator *enu
|
||||
GAsyncResult *result,
|
||||
GError **error)
|
||||
{
|
||||
GSimpleAsyncResult *simple = G_SIMPLE_ASYNC_RESULT (result);
|
||||
GSocketAddress *sockaddr;
|
||||
|
||||
if (g_simple_async_result_propagate_error (simple, error))
|
||||
return NULL;
|
||||
|
||||
sockaddr = g_simple_async_result_get_op_res_gpointer (simple);
|
||||
return sockaddr ? g_object_ref (sockaddr) : NULL;
|
||||
return g_task_propagate_pointer (G_TASK (result), error);
|
||||
}
|
||||
|
||||
static void
|
||||
@ -729,12 +703,6 @@ g_network_service_address_enumerator_finalize (GObject *object)
|
||||
if (srv_enum->resolver)
|
||||
g_object_unref (srv_enum->resolver);
|
||||
|
||||
if (srv_enum->result)
|
||||
g_object_unref (srv_enum->result);
|
||||
|
||||
if (srv_enum->cancellable)
|
||||
g_object_unref (srv_enum->cancellable);
|
||||
|
||||
if (srv_enum->error)
|
||||
g_error_free (srv_enum->error);
|
||||
|
||||
|
@ -33,7 +33,7 @@
|
||||
#include "gproxy.h"
|
||||
#include "gproxyaddress.h"
|
||||
#include "gproxyresolver.h"
|
||||
#include "gsimpleasyncresult.h"
|
||||
#include "gtask.h"
|
||||
#include "gresolver.h"
|
||||
#include "gsocketaddress.h"
|
||||
#include "gsocketaddressenumerator.h"
|
||||
@ -71,10 +71,6 @@ struct _GProxyAddressEnumeratorPrivate
|
||||
gboolean supports_hostname;
|
||||
GList *next_dest_ip;
|
||||
GError *last_error;
|
||||
|
||||
/* Async attributes */
|
||||
GSimpleAsyncResult *simple;
|
||||
GCancellable *cancellable;
|
||||
};
|
||||
|
||||
static void
|
||||
@ -313,31 +309,25 @@ g_proxy_address_enumerator_next (GSocketAddressEnumerator *enumerator,
|
||||
|
||||
|
||||
static void
|
||||
complete_async (GProxyAddressEnumeratorPrivate *priv)
|
||||
complete_async (GTask *task)
|
||||
{
|
||||
GSimpleAsyncResult *simple = priv->simple;
|
||||
|
||||
if (priv->cancellable)
|
||||
{
|
||||
g_object_unref (priv->cancellable);
|
||||
priv->cancellable = NULL;
|
||||
}
|
||||
|
||||
priv->simple = NULL;
|
||||
GProxyAddressEnumeratorPrivate *priv = g_task_get_task_data (task);
|
||||
|
||||
if (priv->last_error)
|
||||
{
|
||||
g_simple_async_result_take_error (simple, priv->last_error);
|
||||
g_task_return_error (task, priv->last_error);
|
||||
priv->last_error = NULL;
|
||||
}
|
||||
else
|
||||
g_task_return_pointer (task, NULL, NULL);
|
||||
|
||||
g_simple_async_result_complete (simple);
|
||||
g_object_unref (simple);
|
||||
g_object_unref (task);
|
||||
}
|
||||
|
||||
static void
|
||||
save_result (GProxyAddressEnumeratorPrivate *priv)
|
||||
return_result (GTask *task)
|
||||
{
|
||||
GProxyAddressEnumeratorPrivate *priv = g_task_get_task_data (task);
|
||||
GSocketAddress *result;
|
||||
|
||||
if (strcmp ("direct", priv->proxy_type) == 0)
|
||||
@ -397,9 +387,8 @@ save_result (GProxyAddressEnumeratorPrivate *priv)
|
||||
}
|
||||
}
|
||||
|
||||
g_simple_async_result_set_op_res_gpointer (priv->simple,
|
||||
result,
|
||||
g_object_unref);
|
||||
g_task_return_pointer (task, result, g_object_unref);
|
||||
g_object_unref (task);
|
||||
}
|
||||
|
||||
static void address_enumerate_cb (GObject *object,
|
||||
@ -407,8 +396,10 @@ static void address_enumerate_cb (GObject *object,
|
||||
gpointer user_data);
|
||||
|
||||
static void
|
||||
next_proxy (GProxyAddressEnumeratorPrivate *priv)
|
||||
next_proxy (GTask *task)
|
||||
{
|
||||
GProxyAddressEnumeratorPrivate *priv = g_task_get_task_data (task);
|
||||
|
||||
if (*priv->next_proxy)
|
||||
{
|
||||
g_object_unref (priv->addr_enum);
|
||||
@ -425,14 +416,14 @@ next_proxy (GProxyAddressEnumeratorPrivate *priv)
|
||||
if (priv->addr_enum)
|
||||
{
|
||||
g_socket_address_enumerator_next_async (priv->addr_enum,
|
||||
priv->cancellable,
|
||||
g_task_get_cancellable (task),
|
||||
address_enumerate_cb,
|
||||
priv);
|
||||
task);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
complete_async (priv);
|
||||
complete_async (task);
|
||||
}
|
||||
|
||||
static void
|
||||
@ -440,21 +431,19 @@ dest_hostname_lookup_cb (GObject *object,
|
||||
GAsyncResult *result,
|
||||
gpointer user_data)
|
||||
{
|
||||
GProxyAddressEnumeratorPrivate *priv = user_data;
|
||||
GTask *task = user_data;
|
||||
GProxyAddressEnumeratorPrivate *priv = g_task_get_task_data (task);
|
||||
|
||||
g_clear_error (&priv->last_error);
|
||||
priv->dest_ips = g_resolver_lookup_by_name_finish (G_RESOLVER (object),
|
||||
result,
|
||||
&priv->last_error);
|
||||
if (priv->dest_ips)
|
||||
{
|
||||
save_result (priv);
|
||||
complete_async (priv);
|
||||
}
|
||||
return_result (task);
|
||||
else
|
||||
{
|
||||
g_clear_object (&priv->proxy_address);
|
||||
next_proxy (priv);
|
||||
next_proxy (task);
|
||||
}
|
||||
}
|
||||
|
||||
@ -463,7 +452,8 @@ address_enumerate_cb (GObject *object,
|
||||
GAsyncResult *result,
|
||||
gpointer user_data)
|
||||
{
|
||||
GProxyAddressEnumeratorPrivate *priv = user_data;
|
||||
GTask *task = user_data;
|
||||
GProxyAddressEnumeratorPrivate *priv = g_task_get_task_data (task);
|
||||
|
||||
g_clear_error (&priv->last_error);
|
||||
priv->proxy_address =
|
||||
@ -478,18 +468,17 @@ address_enumerate_cb (GObject *object,
|
||||
resolver = g_resolver_get_default();
|
||||
g_resolver_lookup_by_name_async (resolver,
|
||||
priv->dest_hostname,
|
||||
priv->cancellable,
|
||||
g_task_get_cancellable (task),
|
||||
dest_hostname_lookup_cb,
|
||||
priv);
|
||||
task);
|
||||
g_object_unref (resolver);
|
||||
return;
|
||||
}
|
||||
|
||||
save_result (priv);
|
||||
complete_async (priv);
|
||||
return_result (task);
|
||||
}
|
||||
else
|
||||
next_proxy (priv);
|
||||
next_proxy (task);
|
||||
}
|
||||
|
||||
static void
|
||||
@ -497,18 +486,19 @@ proxy_lookup_cb (GObject *object,
|
||||
GAsyncResult *result,
|
||||
gpointer user_data)
|
||||
{
|
||||
GError *error = NULL;
|
||||
GProxyAddressEnumeratorPrivate *priv = user_data;
|
||||
GSimpleAsyncResult *simple = priv->simple;
|
||||
GTask *task = user_data;
|
||||
GProxyAddressEnumeratorPrivate *priv = g_task_get_task_data (task);
|
||||
|
||||
g_clear_error (&priv->last_error);
|
||||
priv->proxies = g_proxy_resolver_lookup_finish (G_PROXY_RESOLVER (object),
|
||||
result,
|
||||
&error);
|
||||
&priv->last_error);
|
||||
priv->next_proxy = priv->proxies;
|
||||
|
||||
if (error)
|
||||
if (priv->last_error)
|
||||
{
|
||||
g_simple_async_result_take_error (simple, error);
|
||||
complete_async (task);
|
||||
return;
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -516,14 +506,14 @@ proxy_lookup_cb (GObject *object,
|
||||
if (priv->addr_enum)
|
||||
{
|
||||
g_socket_address_enumerator_next_async (priv->addr_enum,
|
||||
priv->cancellable,
|
||||
g_task_get_cancellable (task),
|
||||
address_enumerate_cb,
|
||||
priv);
|
||||
task);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
complete_async (priv);
|
||||
complete_async (task);
|
||||
}
|
||||
|
||||
static void
|
||||
@ -533,15 +523,10 @@ g_proxy_address_enumerator_next_async (GSocketAddressEnumerator *enumerator,
|
||||
gpointer user_data)
|
||||
{
|
||||
GProxyAddressEnumeratorPrivate *priv = GET_PRIVATE (enumerator);
|
||||
GTask *task;
|
||||
|
||||
g_return_if_fail (priv->simple == NULL);
|
||||
g_return_if_fail (priv->cancellable == NULL);
|
||||
|
||||
priv->simple = g_simple_async_result_new (G_OBJECT (enumerator),
|
||||
callback, user_data,
|
||||
g_proxy_address_enumerator_next_async);
|
||||
|
||||
priv->cancellable = cancellable ? g_object_ref (cancellable) : NULL;
|
||||
task = g_task_new (enumerator, cancellable, callback, user_data);
|
||||
g_task_set_task_data (task, priv, NULL);
|
||||
|
||||
if (priv->proxies == NULL)
|
||||
{
|
||||
@ -550,7 +535,7 @@ g_proxy_address_enumerator_next_async (GSocketAddressEnumerator *enumerator,
|
||||
priv->dest_uri,
|
||||
cancellable,
|
||||
proxy_lookup_cb,
|
||||
priv);
|
||||
task);
|
||||
return;
|
||||
}
|
||||
|
||||
@ -558,28 +543,20 @@ g_proxy_address_enumerator_next_async (GSocketAddressEnumerator *enumerator,
|
||||
{
|
||||
if (priv->proxy_address)
|
||||
{
|
||||
save_result (priv);
|
||||
return_result (task);
|
||||
return;
|
||||
}
|
||||
else
|
||||
{
|
||||
g_socket_address_enumerator_next_async (priv->addr_enum,
|
||||
cancellable,
|
||||
address_enumerate_cb,
|
||||
priv);
|
||||
task);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
g_simple_async_result_complete_in_idle (priv->simple);
|
||||
|
||||
g_object_unref (priv->simple);
|
||||
priv->simple = NULL;
|
||||
|
||||
if (priv->cancellable)
|
||||
{
|
||||
g_object_unref (priv->cancellable);
|
||||
priv->cancellable = NULL;
|
||||
}
|
||||
complete_async (task);
|
||||
}
|
||||
|
||||
static GSocketAddress *
|
||||
@ -587,17 +564,9 @@ g_proxy_address_enumerator_next_finish (GSocketAddressEnumerator *enumerator,
|
||||
GAsyncResult *result,
|
||||
GError **error)
|
||||
{
|
||||
GSimpleAsyncResult *simple = G_SIMPLE_ASYNC_RESULT (result);
|
||||
GSocketAddress *address;
|
||||
g_return_val_if_fail (g_task_is_valid (result, enumerator), NULL);
|
||||
|
||||
if (g_simple_async_result_propagate_error (simple, error))
|
||||
return NULL;
|
||||
|
||||
address = g_simple_async_result_get_op_res_gpointer (simple);
|
||||
if (address)
|
||||
g_object_ref (address);
|
||||
|
||||
return address;
|
||||
return g_task_propagate_pointer (G_TASK (result), error);
|
||||
}
|
||||
|
||||
static void
|
||||
@ -702,9 +671,6 @@ g_proxy_address_enumerator_finalize (GObject *object)
|
||||
g_free (priv->proxy_username);
|
||||
g_free (priv->proxy_password);
|
||||
|
||||
if (priv->cancellable)
|
||||
g_object_unref (priv->cancellable);
|
||||
|
||||
g_clear_error (&priv->last_error);
|
||||
|
||||
G_OBJECT_CLASS (g_proxy_address_enumerator_parent_class)->finalize (object);
|
||||
|
@ -30,6 +30,7 @@
|
||||
#include "ginetaddress.h"
|
||||
#include "ginetsocketaddress.h"
|
||||
#include "gsimpleasyncresult.h"
|
||||
#include "gtask.h"
|
||||
#include "gsrvtarget.h"
|
||||
#include "gthreadedresolver.h"
|
||||
|
||||
@ -395,15 +396,13 @@ g_resolver_lookup_by_name_async (GResolver *resolver,
|
||||
addr = g_inet_address_new_from_string (hostname);
|
||||
if (addr)
|
||||
{
|
||||
GSimpleAsyncResult *simple;
|
||||
GTask *task;
|
||||
|
||||
simple = g_simple_async_result_new (G_OBJECT (resolver),
|
||||
callback, user_data,
|
||||
g_resolver_lookup_by_name_async);
|
||||
|
||||
g_simple_async_result_set_op_res_gpointer (simple, addr, g_object_unref);
|
||||
g_simple_async_result_complete_in_idle (simple);
|
||||
g_object_unref (simple);
|
||||
task = g_task_new (resolver, cancellable, callback, user_data);
|
||||
g_task_set_source_tag (task, g_resolver_lookup_by_name_async);
|
||||
g_task_return_pointer (task, g_list_append (NULL, addr),
|
||||
(GDestroyNotify) g_resolver_free_addresses);
|
||||
g_object_unref (task);
|
||||
return;
|
||||
}
|
||||
|
||||
@ -449,12 +448,8 @@ g_resolver_lookup_by_name_finish (GResolver *resolver,
|
||||
return NULL;
|
||||
else if (g_async_result_is_tagged (result, g_resolver_lookup_by_name_async))
|
||||
{
|
||||
GSimpleAsyncResult *simple = G_SIMPLE_ASYNC_RESULT (result);
|
||||
GInetAddress *addr;
|
||||
|
||||
/* Handle the stringified-IP-addr case */
|
||||
addr = g_simple_async_result_get_op_res_gpointer (simple);
|
||||
return g_list_append (NULL, g_object_ref (addr));
|
||||
return g_task_propagate_pointer (G_TASK (result), error);
|
||||
}
|
||||
|
||||
addrs = G_RESOLVER_GET_CLASS (resolver)->
|
||||
|
@ -22,7 +22,7 @@
|
||||
#include "gsocketaddressenumerator.h"
|
||||
#include "glibintl.h"
|
||||
|
||||
#include "gsimpleasyncresult.h"
|
||||
#include "gtask.h"
|
||||
|
||||
|
||||
G_DEFINE_ABSTRACT_TYPE (GSocketAddressEnumerator, g_socket_address_enumerator, G_TYPE_OBJECT);
|
||||
@ -95,21 +95,19 @@ g_socket_address_enumerator_real_next_async (GSocketAddressEnumerator *enumerato
|
||||
GAsyncReadyCallback callback,
|
||||
gpointer user_data)
|
||||
{
|
||||
GSimpleAsyncResult *result;
|
||||
GTask *task;
|
||||
GSocketAddress *address;
|
||||
GError *error = NULL;
|
||||
|
||||
result = g_simple_async_result_new (G_OBJECT (enumerator),
|
||||
callback, user_data,
|
||||
g_socket_address_enumerator_real_next_async);
|
||||
address = g_socket_address_enumerator_next (enumerator, cancellable, &error);
|
||||
if (address)
|
||||
g_simple_async_result_set_op_res_gpointer (result, address, NULL);
|
||||
else if (error)
|
||||
g_simple_async_result_take_error (result, error);
|
||||
task = g_task_new (enumerator, NULL, callback, user_data);
|
||||
|
||||
g_simple_async_result_complete_in_idle (result);
|
||||
g_object_unref (result);
|
||||
address = g_socket_address_enumerator_next (enumerator, cancellable, &error);
|
||||
if (error)
|
||||
g_task_return_error (task, error);
|
||||
else
|
||||
g_task_return_pointer (task, address, g_object_unref);
|
||||
|
||||
g_object_unref (task);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -144,16 +142,9 @@ g_socket_address_enumerator_real_next_finish (GSocketAddressEnumerator *enumera
|
||||
GAsyncResult *result,
|
||||
GError **error)
|
||||
{
|
||||
GSimpleAsyncResult *simple;
|
||||
g_return_val_if_fail (g_task_is_valid (result, enumerator), NULL);
|
||||
|
||||
g_return_val_if_fail (G_IS_SIMPLE_ASYNC_RESULT (result), NULL);
|
||||
simple = G_SIMPLE_ASYNC_RESULT (result);
|
||||
g_return_val_if_fail (g_simple_async_result_get_source_tag (simple) == g_socket_address_enumerator_real_next_async, NULL);
|
||||
|
||||
if (g_simple_async_result_propagate_error (simple, error))
|
||||
return NULL;
|
||||
else
|
||||
return g_simple_async_result_get_op_res_gpointer (simple);
|
||||
return g_task_propagate_pointer (G_TASK (result), error);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -34,7 +34,7 @@
|
||||
#include <gio/gsocketconnection.h>
|
||||
#include <gio/gproxyaddressenumerator.h>
|
||||
#include <gio/gproxyaddress.h>
|
||||
#include <gio/gsimpleasyncresult.h>
|
||||
#include <gio/gtask.h>
|
||||
#include <gio/gcancellable.h>
|
||||
#include <gio/gioerror.h>
|
||||
#include <gio/gsocket.h>
|
||||
@ -1271,8 +1271,7 @@ g_socket_client_connect_to_uri (GSocketClient *client,
|
||||
|
||||
typedef struct
|
||||
{
|
||||
GSimpleAsyncResult *result;
|
||||
GCancellable *cancellable;
|
||||
GTask *task;
|
||||
GSocketClient *client;
|
||||
|
||||
GSocketConnectable *connectable;
|
||||
@ -1285,47 +1284,40 @@ typedef struct
|
||||
GError *last_error;
|
||||
} GSocketClientAsyncConnectData;
|
||||
|
||||
static void
|
||||
g_socket_client_async_connect_data_free (GSocketClientAsyncConnectData *data)
|
||||
{
|
||||
g_clear_object (&data->connectable);
|
||||
g_clear_object (&data->enumerator);
|
||||
g_clear_object (&data->proxy_addr);
|
||||
g_clear_object (&data->current_addr);
|
||||
g_clear_object (&data->current_socket);
|
||||
g_clear_object (&data->connection);
|
||||
|
||||
g_clear_error (&data->last_error);
|
||||
|
||||
g_slice_free (GSocketClientAsyncConnectData, data);
|
||||
}
|
||||
|
||||
static void
|
||||
g_socket_client_async_connect_complete (GSocketClientAsyncConnectData *data)
|
||||
{
|
||||
g_assert (data->connection);
|
||||
|
||||
if (!G_IS_SOCKET_CONNECTION (data->connection))
|
||||
{
|
||||
GSocketConnection *wrapper_connection;
|
||||
|
||||
wrapper_connection = g_tcp_wrapper_connection_new (data->connection,
|
||||
data->current_socket);
|
||||
g_object_unref (data->connection);
|
||||
data->connection = (GIOStream *)wrapper_connection;
|
||||
}
|
||||
|
||||
g_socket_client_emit_event (data->client, G_SOCKET_CLIENT_COMPLETE, data->connectable, data->connection);
|
||||
|
||||
if (data->last_error)
|
||||
{
|
||||
g_simple_async_result_take_error (data->result, data->last_error);
|
||||
}
|
||||
else
|
||||
{
|
||||
g_assert (data->connection);
|
||||
|
||||
if (!G_IS_SOCKET_CONNECTION (data->connection))
|
||||
{
|
||||
GSocketConnection *wrapper_connection;
|
||||
|
||||
wrapper_connection = g_tcp_wrapper_connection_new (data->connection,
|
||||
data->current_socket);
|
||||
g_object_unref (data->connection);
|
||||
data->connection = (GIOStream *)wrapper_connection;
|
||||
}
|
||||
|
||||
g_simple_async_result_set_op_res_gpointer (data->result,
|
||||
data->connection,
|
||||
g_object_unref);
|
||||
}
|
||||
|
||||
g_simple_async_result_complete (data->result);
|
||||
g_object_unref (data->result);
|
||||
g_object_unref (data->connectable);
|
||||
g_object_unref (data->enumerator);
|
||||
if (data->cancellable)
|
||||
g_object_unref (data->cancellable);
|
||||
if (data->current_addr)
|
||||
g_object_unref (data->current_addr);
|
||||
if (data->current_socket)
|
||||
g_object_unref (data->current_socket);
|
||||
if (data->proxy_addr)
|
||||
g_object_unref (data->proxy_addr);
|
||||
g_slice_free (GSocketClientAsyncConnectData, data);
|
||||
g_task_return_pointer (data->task, data->connection, g_object_unref);
|
||||
data->connection = NULL;
|
||||
g_object_unref (data->task);
|
||||
}
|
||||
|
||||
|
||||
@ -1353,7 +1345,7 @@ enumerator_next_async (GSocketClientAsyncConnectData *data)
|
||||
|
||||
g_socket_client_emit_event (data->client, G_SOCKET_CLIENT_RESOLVING, data->connectable, NULL);
|
||||
g_socket_address_enumerator_next_async (data->enumerator,
|
||||
data->cancellable,
|
||||
g_task_get_cancellable (data->task),
|
||||
g_socket_client_enumerator_callback,
|
||||
data);
|
||||
}
|
||||
@ -1403,7 +1395,7 @@ g_socket_client_tls_handshake (GSocketClientAsyncConnectData *data)
|
||||
g_socket_client_emit_event (data->client, G_SOCKET_CLIENT_TLS_HANDSHAKING, data->connectable, G_IO_STREAM (tlsconn));
|
||||
g_tls_connection_handshake_async (G_TLS_CONNECTION (tlsconn),
|
||||
G_PRIORITY_DEFAULT,
|
||||
data->cancellable,
|
||||
g_task_get_cancellable (data->task),
|
||||
g_socket_client_tls_handshake_callback,
|
||||
data);
|
||||
}
|
||||
@ -1493,7 +1485,7 @@ g_socket_client_connected_callback (GObject *source,
|
||||
g_proxy_connect_async (proxy,
|
||||
data->connection,
|
||||
data->proxy_addr,
|
||||
data->cancellable,
|
||||
g_task_get_cancellable (data->task),
|
||||
g_socket_client_proxy_connect_callback,
|
||||
data);
|
||||
g_object_unref (proxy);
|
||||
@ -1525,28 +1517,31 @@ g_socket_client_enumerator_callback (GObject *object,
|
||||
GSocketClientAsyncConnectData *data = user_data;
|
||||
GSocketAddress *address = NULL;
|
||||
GSocket *socket;
|
||||
GError *tmp_error = NULL;
|
||||
GError *error = NULL;
|
||||
|
||||
if (g_cancellable_is_cancelled (data->cancellable))
|
||||
{
|
||||
g_clear_error (&data->last_error);
|
||||
g_cancellable_set_error_if_cancelled (data->cancellable, &data->last_error);
|
||||
g_socket_client_async_connect_complete (data);
|
||||
return;
|
||||
}
|
||||
if (g_task_return_error_if_cancelled (data->task))
|
||||
return;
|
||||
|
||||
address = g_socket_address_enumerator_next_finish (data->enumerator,
|
||||
result, &tmp_error);
|
||||
|
||||
result, &error);
|
||||
if (address == NULL)
|
||||
{
|
||||
if (tmp_error)
|
||||
set_last_error (data, tmp_error);
|
||||
else if (data->last_error == NULL)
|
||||
g_set_error_literal (&data->last_error, G_IO_ERROR, G_IO_ERROR_FAILED,
|
||||
_("Unknown error on connect"));
|
||||
|
||||
g_socket_client_async_connect_complete (data);
|
||||
g_socket_client_emit_event (data->client, G_SOCKET_CLIENT_COMPLETE, data->connectable, NULL);
|
||||
if (!error)
|
||||
{
|
||||
if (data->last_error)
|
||||
{
|
||||
error = data->last_error;
|
||||
data->last_error = NULL;
|
||||
}
|
||||
else
|
||||
{
|
||||
g_set_error_literal (&error, G_IO_ERROR, G_IO_ERROR_FAILED,
|
||||
_("Unknown error on connect"));
|
||||
}
|
||||
}
|
||||
g_task_return_error (data->task, error);
|
||||
g_object_unref (data->task);
|
||||
return;
|
||||
}
|
||||
|
||||
@ -1573,7 +1568,8 @@ g_socket_client_enumerator_callback (GObject *object,
|
||||
|
||||
g_socket_client_emit_event (data->client, G_SOCKET_CLIENT_CONNECTING, data->connectable, data->connection);
|
||||
g_socket_connection_connect_async (G_SOCKET_CONNECTION (data->connection),
|
||||
address, data->cancellable,
|
||||
address,
|
||||
g_task_get_cancellable (data->task),
|
||||
g_socket_client_connected_callback, data);
|
||||
}
|
||||
|
||||
@ -1605,16 +1601,7 @@ g_socket_client_connect_async (GSocketClient *client,
|
||||
g_return_if_fail (G_IS_SOCKET_CLIENT (client));
|
||||
|
||||
data = g_slice_new0 (GSocketClientAsyncConnectData);
|
||||
|
||||
data->result = g_simple_async_result_new (G_OBJECT (client),
|
||||
callback, user_data,
|
||||
g_socket_client_connect_async);
|
||||
data->client = client;
|
||||
if (cancellable)
|
||||
data->cancellable = g_object_ref (cancellable);
|
||||
else
|
||||
data->cancellable = NULL;
|
||||
data->last_error = NULL;
|
||||
data->connectable = g_object_ref (connectable);
|
||||
|
||||
if (can_use_proxy (client))
|
||||
@ -1622,6 +1609,9 @@ g_socket_client_connect_async (GSocketClient *client,
|
||||
else
|
||||
data->enumerator = g_socket_connectable_enumerate (connectable);
|
||||
|
||||
data->task = g_task_new (client, cancellable, callback, user_data);
|
||||
g_task_set_task_data (data->task, data, (GDestroyNotify)g_socket_client_async_connect_data_free);
|
||||
|
||||
enumerator_next_async (data);
|
||||
}
|
||||
|
||||
@ -1658,8 +1648,9 @@ g_socket_client_connect_to_host_async (GSocketClient *client,
|
||||
&error);
|
||||
if (connectable == NULL)
|
||||
{
|
||||
g_simple_async_report_take_gerror_in_idle (G_OBJECT (client),
|
||||
callback, user_data, error);
|
||||
g_task_report_error (client, callback, user_data,
|
||||
g_socket_client_connect_to_host_async,
|
||||
error);
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -1733,8 +1724,9 @@ g_socket_client_connect_to_uri_async (GSocketClient *client,
|
||||
connectable = g_network_address_parse_uri (uri, default_port, &error);
|
||||
if (connectable == NULL)
|
||||
{
|
||||
g_simple_async_report_take_gerror_in_idle (G_OBJECT (client),
|
||||
callback, user_data, error);
|
||||
g_task_report_error (client, callback, user_data,
|
||||
g_socket_client_connect_to_uri_async,
|
||||
error);
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -1764,12 +1756,9 @@ g_socket_client_connect_finish (GSocketClient *client,
|
||||
GAsyncResult *result,
|
||||
GError **error)
|
||||
{
|
||||
GSimpleAsyncResult *simple = G_SIMPLE_ASYNC_RESULT (result);
|
||||
g_return_val_if_fail (g_task_is_valid (result, client), NULL);
|
||||
|
||||
if (g_simple_async_result_propagate_error (simple, error))
|
||||
return NULL;
|
||||
|
||||
return g_object_ref (g_simple_async_result_get_op_res_gpointer (simple));
|
||||
return g_task_propagate_pointer (G_TASK (result), error);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -32,7 +32,7 @@
|
||||
#include "gsocketoutputstream.h"
|
||||
#include "gsocketinputstream.h"
|
||||
#include <gio/giostream.h>
|
||||
#include <gio/gsimpleasyncresult.h>
|
||||
#include <gio/gtask.h>
|
||||
#include "gunixconnection.h"
|
||||
#include "gtcpconnection.h"
|
||||
#include "glibintl.h"
|
||||
@ -184,23 +184,21 @@ g_socket_connection_connect_async (GSocketConnection *connection,
|
||||
GAsyncReadyCallback callback,
|
||||
gpointer user_data)
|
||||
{
|
||||
GSimpleAsyncResult *simple;
|
||||
GTask *task;
|
||||
GError *tmp_error = NULL;
|
||||
|
||||
g_return_if_fail (G_IS_SOCKET_CONNECTION (connection));
|
||||
g_return_if_fail (G_IS_SOCKET_ADDRESS (address));
|
||||
|
||||
simple = g_simple_async_result_new (G_OBJECT (connection),
|
||||
callback, user_data,
|
||||
g_socket_connection_connect_async);
|
||||
task = g_task_new (connection, cancellable, callback, user_data);
|
||||
|
||||
g_socket_set_blocking (connection->priv->socket, FALSE);
|
||||
|
||||
if (g_socket_connect (connection->priv->socket, address,
|
||||
cancellable, &tmp_error))
|
||||
{
|
||||
g_simple_async_result_set_op_res_gboolean (simple, TRUE);
|
||||
g_simple_async_result_complete_in_idle (simple);
|
||||
g_task_return_boolean (task, TRUE);
|
||||
g_object_unref (task);
|
||||
}
|
||||
else if (g_error_matches (tmp_error, G_IO_ERROR, G_IO_ERROR_PENDING))
|
||||
{
|
||||
@ -209,16 +207,14 @@ g_socket_connection_connect_async (GSocketConnection *connection,
|
||||
g_error_free (tmp_error);
|
||||
source = g_socket_create_source (connection->priv->socket,
|
||||
G_IO_OUT, cancellable);
|
||||
g_source_set_callback (source,
|
||||
(GSourceFunc) g_socket_connection_connect_callback,
|
||||
simple, NULL);
|
||||
g_source_attach (source, g_main_context_get_thread_default ());
|
||||
g_task_attach_source (task, source,
|
||||
(GSourceFunc) g_socket_connection_connect_callback);
|
||||
g_source_unref (source);
|
||||
}
|
||||
else
|
||||
{
|
||||
g_simple_async_result_take_error (simple, tmp_error);
|
||||
g_simple_async_result_complete_in_idle (simple);
|
||||
g_task_return_error (task, tmp_error);
|
||||
g_object_unref (task);
|
||||
}
|
||||
}
|
||||
|
||||
@ -227,20 +223,16 @@ g_socket_connection_connect_callback (GSocket *socket,
|
||||
GIOCondition condition,
|
||||
gpointer user_data)
|
||||
{
|
||||
GSimpleAsyncResult *simple = user_data;
|
||||
GSocketConnection *connection;
|
||||
GTask *task = user_data;
|
||||
GSocketConnection *connection = g_task_get_source_object (task);
|
||||
GError *error = NULL;
|
||||
|
||||
connection = G_SOCKET_CONNECTION (g_async_result_get_source_object (G_ASYNC_RESULT (simple)));
|
||||
g_object_unref (connection);
|
||||
|
||||
if (g_socket_check_connect_result (connection->priv->socket, &error))
|
||||
g_simple_async_result_set_op_res_gboolean (simple, TRUE);
|
||||
g_task_return_boolean (task, TRUE);
|
||||
else
|
||||
g_simple_async_result_take_error (simple, error);
|
||||
g_task_return_error (task, error);
|
||||
|
||||
g_simple_async_result_complete (simple);
|
||||
g_object_unref (simple);
|
||||
g_object_unref (task);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
@ -261,15 +253,10 @@ g_socket_connection_connect_finish (GSocketConnection *connection,
|
||||
GAsyncResult *result,
|
||||
GError **error)
|
||||
{
|
||||
GSimpleAsyncResult *simple;
|
||||
|
||||
g_return_val_if_fail (G_IS_SOCKET_CONNECTION (connection), FALSE);
|
||||
g_return_val_if_fail (g_simple_async_result_is_valid (result, G_OBJECT (connection), g_socket_connection_connect_async), FALSE);
|
||||
g_return_val_if_fail (g_task_is_valid (result, connection), FALSE);
|
||||
|
||||
simple = G_SIMPLE_ASYNC_RESULT (result);
|
||||
if (g_simple_async_result_propagate_error (simple, error))
|
||||
return FALSE;
|
||||
return TRUE;
|
||||
return g_task_propagate_boolean (G_TASK (result), error);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -479,29 +466,23 @@ g_socket_connection_close_async (GIOStream *stream,
|
||||
GAsyncReadyCallback callback,
|
||||
gpointer user_data)
|
||||
{
|
||||
GSimpleAsyncResult *res;
|
||||
GTask *task;
|
||||
GIOStreamClass *class;
|
||||
GError *error;
|
||||
|
||||
class = G_IO_STREAM_GET_CLASS (stream);
|
||||
|
||||
task = g_task_new (stream, cancellable, callback, user_data);
|
||||
|
||||
/* socket close is not blocked, just do it! */
|
||||
error = NULL;
|
||||
if (class->close_fn &&
|
||||
!class->close_fn (stream, cancellable, &error))
|
||||
{
|
||||
g_simple_async_report_take_gerror_in_idle (G_OBJECT (stream),
|
||||
callback, user_data,
|
||||
error);
|
||||
return;
|
||||
}
|
||||
g_task_return_error (task, error);
|
||||
else
|
||||
g_task_return_boolean (task, TRUE);
|
||||
|
||||
res = g_simple_async_result_new (G_OBJECT (stream),
|
||||
callback,
|
||||
user_data,
|
||||
g_socket_connection_close_async);
|
||||
g_simple_async_result_complete_in_idle (res);
|
||||
g_object_unref (res);
|
||||
g_object_unref (task);
|
||||
}
|
||||
|
||||
static gboolean
|
||||
@ -509,7 +490,7 @@ g_socket_connection_close_finish (GIOStream *stream,
|
||||
GAsyncResult *result,
|
||||
GError **error)
|
||||
{
|
||||
return TRUE;
|
||||
return g_task_propagate_boolean (G_TASK (result), error);
|
||||
}
|
||||
|
||||
typedef struct {
|
||||
|
@ -27,7 +27,6 @@
|
||||
#include "gsocketinputstream.h"
|
||||
#include "glibintl.h"
|
||||
|
||||
#include "gsimpleasyncresult.h"
|
||||
#include "gcancellable.h"
|
||||
#include "gpollableinputstream.h"
|
||||
#include "gioerror.h"
|
||||
@ -62,8 +61,6 @@ struct _GSocketInputStreamPrivate
|
||||
GSocket *socket;
|
||||
|
||||
/* pending operation metadata */
|
||||
GSimpleAsyncResult *result;
|
||||
GCancellable *cancellable;
|
||||
gpointer buffer;
|
||||
gsize count;
|
||||
};
|
||||
|
@ -28,7 +28,7 @@
|
||||
#include "config.h"
|
||||
#include "gsocketlistener.h"
|
||||
|
||||
#include <gio/gsimpleasyncresult.h>
|
||||
#include <gio/gtask.h>
|
||||
#include <gio/gcancellable.h>
|
||||
#include <gio/gsocketaddress.h>
|
||||
#include <gio/ginetaddress.h>
|
||||
@ -681,43 +681,32 @@ g_socket_listener_accept (GSocketListener *listener,
|
||||
return connection;
|
||||
}
|
||||
|
||||
struct AcceptAsyncData {
|
||||
GSimpleAsyncResult *simple;
|
||||
GCancellable *cancellable;
|
||||
GList *sources;
|
||||
};
|
||||
|
||||
static gboolean
|
||||
accept_ready (GSocket *accept_socket,
|
||||
GIOCondition condition,
|
||||
gpointer _data)
|
||||
gpointer user_data)
|
||||
{
|
||||
struct AcceptAsyncData *data = _data;
|
||||
GTask *task = user_data;
|
||||
GError *error = NULL;
|
||||
GSocket *socket;
|
||||
GObject *source_object;
|
||||
|
||||
socket = g_socket_accept (accept_socket, data->cancellable, &error);
|
||||
socket = g_socket_accept (accept_socket, g_task_get_cancellable (task), &error);
|
||||
if (socket)
|
||||
{
|
||||
g_simple_async_result_set_op_res_gpointer (data->simple, socket,
|
||||
g_object_unref);
|
||||
g_task_return_pointer (task, socket, g_object_unref);
|
||||
source_object = g_object_get_qdata (G_OBJECT (accept_socket), source_quark);
|
||||
if (source_object)
|
||||
g_object_set_qdata_full (G_OBJECT (data->simple),
|
||||
g_object_set_qdata_full (G_OBJECT (task),
|
||||
source_quark,
|
||||
g_object_ref (source_object), g_object_unref);
|
||||
}
|
||||
else
|
||||
{
|
||||
g_simple_async_result_take_error (data->simple, error);
|
||||
g_task_return_error (task, error);
|
||||
}
|
||||
|
||||
g_simple_async_result_complete_in_idle (data->simple);
|
||||
g_object_unref (data->simple);
|
||||
free_sources (data->sources);
|
||||
g_free (data);
|
||||
|
||||
g_object_unref (task);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
@ -742,27 +731,25 @@ g_socket_listener_accept_socket_async (GSocketListener *listener,
|
||||
GAsyncReadyCallback callback,
|
||||
gpointer user_data)
|
||||
{
|
||||
struct AcceptAsyncData *data;
|
||||
GTask *task;
|
||||
GList *sources;
|
||||
GError *error = NULL;
|
||||
|
||||
task = g_task_new (listener, cancellable, callback, user_data);
|
||||
|
||||
if (!check_listener (listener, &error))
|
||||
{
|
||||
g_simple_async_report_take_gerror_in_idle (G_OBJECT (listener),
|
||||
callback, user_data,
|
||||
error);
|
||||
g_task_return_error (task, error);
|
||||
g_object_unref (task);
|
||||
return;
|
||||
}
|
||||
|
||||
data = g_new0 (struct AcceptAsyncData, 1);
|
||||
data->simple = g_simple_async_result_new (G_OBJECT (listener),
|
||||
callback, user_data,
|
||||
g_socket_listener_accept_socket_async);
|
||||
data->cancellable = cancellable;
|
||||
data->sources = add_sources (listener,
|
||||
accept_ready,
|
||||
data,
|
||||
cancellable,
|
||||
g_main_context_get_thread_default ());
|
||||
sources = add_sources (listener,
|
||||
accept_ready,
|
||||
task,
|
||||
cancellable,
|
||||
g_main_context_get_thread_default ());
|
||||
g_task_set_task_data (task, sources, (GDestroyNotify) free_sources);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -785,24 +772,13 @@ g_socket_listener_accept_socket_finish (GSocketListener *listener,
|
||||
GObject **source_object,
|
||||
GError **error)
|
||||
{
|
||||
GSocket *socket;
|
||||
GSimpleAsyncResult *simple;
|
||||
|
||||
g_return_val_if_fail (G_IS_SOCKET_LISTENER (listener), NULL);
|
||||
|
||||
simple = G_SIMPLE_ASYNC_RESULT (result);
|
||||
|
||||
if (g_simple_async_result_propagate_error (simple, error))
|
||||
return NULL;
|
||||
|
||||
g_warn_if_fail (g_simple_async_result_get_source_tag (simple) == g_socket_listener_accept_socket_async);
|
||||
|
||||
socket = g_simple_async_result_get_op_res_gpointer (simple);
|
||||
g_return_val_if_fail (g_task_is_valid (result, listener), NULL);
|
||||
|
||||
if (source_object)
|
||||
*source_object = g_object_get_qdata (G_OBJECT (result), source_quark);
|
||||
|
||||
return g_object_ref (socket);
|
||||
return g_task_propagate_pointer (G_TASK (result), error);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -29,7 +29,6 @@
|
||||
#include "gsocket.h"
|
||||
#include "glibintl.h"
|
||||
|
||||
#include "gsimpleasyncresult.h"
|
||||
#include "gcancellable.h"
|
||||
#include "gpollableinputstream.h"
|
||||
#include "gpollableoutputstream.h"
|
||||
@ -66,8 +65,6 @@ struct _GSocketOutputStreamPrivate
|
||||
GSocket *socket;
|
||||
|
||||
/* pending operation metadata */
|
||||
GSimpleAsyncResult *result;
|
||||
GCancellable *cancellable;
|
||||
gconstpointer buffer;
|
||||
gsize count;
|
||||
};
|
||||
|
@ -26,7 +26,6 @@
|
||||
|
||||
#include <string.h>
|
||||
|
||||
#include "gasyncresult.h"
|
||||
#include "giomodule.h"
|
||||
#include "giomodule-priv.h"
|
||||
#include "giostream.h"
|
||||
@ -36,7 +35,7 @@
|
||||
#include "goutputstream.h"
|
||||
#include "gproxy.h"
|
||||
#include "gproxyaddress.h"
|
||||
#include "gsimpleasyncresult.h"
|
||||
#include "gtask.h"
|
||||
|
||||
#define SOCKS4_VERSION 4
|
||||
|
||||
@ -249,10 +248,7 @@ error:
|
||||
|
||||
typedef struct
|
||||
{
|
||||
GSimpleAsyncResult *simple;
|
||||
GIOStream *io_stream;
|
||||
GProxyAddress *proxy_address;
|
||||
GCancellable *cancellable;
|
||||
|
||||
/* For connecting */
|
||||
guint8 *buffer;
|
||||
@ -271,50 +267,34 @@ static void connect_reply_read_cb (GObject *source,
|
||||
static void
|
||||
free_connect_data (ConnectAsyncData *data)
|
||||
{
|
||||
if (data->io_stream)
|
||||
g_object_unref (data->io_stream);
|
||||
|
||||
if (data->proxy_address)
|
||||
g_object_unref (data->proxy_address);
|
||||
|
||||
if (data->cancellable)
|
||||
g_object_unref (data->cancellable);
|
||||
|
||||
g_object_unref (data->io_stream);
|
||||
g_slice_free (ConnectAsyncData, data);
|
||||
}
|
||||
|
||||
static void
|
||||
complete_async_from_error (ConnectAsyncData *data, GError *error)
|
||||
{
|
||||
GSimpleAsyncResult *simple = data->simple;
|
||||
g_simple_async_result_take_error (data->simple, error);
|
||||
g_simple_async_result_set_op_res_gpointer (simple, NULL, NULL);
|
||||
g_simple_async_result_complete (simple);
|
||||
g_object_unref (simple);
|
||||
}
|
||||
|
||||
static void
|
||||
do_read (GAsyncReadyCallback callback, ConnectAsyncData *data)
|
||||
do_read (GAsyncReadyCallback callback, GTask *task, ConnectAsyncData *data)
|
||||
{
|
||||
GInputStream *in;
|
||||
in = g_io_stream_get_input_stream (data->io_stream);
|
||||
g_input_stream_read_async (in,
|
||||
data->buffer + data->offset,
|
||||
data->length - data->offset,
|
||||
G_PRIORITY_DEFAULT, data->cancellable,
|
||||
callback, data);
|
||||
g_task_get_priority (task),
|
||||
g_task_get_cancellable (task),
|
||||
callback, task);
|
||||
}
|
||||
|
||||
static void
|
||||
do_write (GAsyncReadyCallback callback, ConnectAsyncData *data)
|
||||
do_write (GAsyncReadyCallback callback, GTask *task, ConnectAsyncData *data)
|
||||
{
|
||||
GOutputStream *out;
|
||||
out = g_io_stream_get_output_stream (data->io_stream);
|
||||
g_output_stream_write_async (out,
|
||||
data->buffer + data->offset,
|
||||
data->length - data->offset,
|
||||
G_PRIORITY_DEFAULT, data->cancellable,
|
||||
callback, data);
|
||||
g_task_get_priority (task),
|
||||
g_task_get_cancellable (task),
|
||||
callback, task);
|
||||
}
|
||||
|
||||
|
||||
@ -328,26 +308,17 @@ g_socks4a_proxy_connect_async (GProxy *proxy,
|
||||
gpointer user_data)
|
||||
{
|
||||
GError *error = NULL;
|
||||
GSimpleAsyncResult *simple;
|
||||
GTask *task;
|
||||
ConnectAsyncData *data;
|
||||
const gchar *hostname;
|
||||
guint16 port;
|
||||
const gchar *username;
|
||||
|
||||
simple = g_simple_async_result_new (G_OBJECT (proxy),
|
||||
callback, user_data,
|
||||
g_socks4a_proxy_connect_async);
|
||||
|
||||
data = g_slice_new0 (ConnectAsyncData);
|
||||
|
||||
data->simple = simple;
|
||||
data->io_stream = g_object_ref (io_stream);
|
||||
|
||||
if (cancellable)
|
||||
data->cancellable = g_object_ref (cancellable);
|
||||
|
||||
g_simple_async_result_set_op_res_gpointer (simple, data,
|
||||
(GDestroyNotify) free_connect_data);
|
||||
task = g_task_new (proxy, cancellable, callback, user_data);
|
||||
g_task_set_task_data (task, data, (GDestroyNotify) free_connect_data);
|
||||
|
||||
hostname = g_proxy_address_get_destination_hostname (proxy_address);
|
||||
port = g_proxy_address_get_destination_port (proxy_address);
|
||||
@ -361,14 +332,12 @@ g_socks4a_proxy_connect_async (GProxy *proxy,
|
||||
|
||||
if (data->length < 0)
|
||||
{
|
||||
g_simple_async_result_take_error (data->simple, error);
|
||||
g_simple_async_result_set_op_res_gpointer (simple, NULL, NULL);
|
||||
g_simple_async_result_complete_in_idle (simple);
|
||||
g_object_unref (simple);
|
||||
g_task_return_error (task, error);
|
||||
g_object_unref (task);
|
||||
}
|
||||
else
|
||||
{
|
||||
do_write (connect_msg_write_cb, data);
|
||||
do_write (connect_msg_write_cb, task, data);
|
||||
}
|
||||
}
|
||||
|
||||
@ -377,8 +346,9 @@ connect_msg_write_cb (GObject *source,
|
||||
GAsyncResult *result,
|
||||
gpointer user_data)
|
||||
{
|
||||
GTask *task = user_data;
|
||||
ConnectAsyncData *data = g_task_get_task_data (task);
|
||||
GError *error = NULL;
|
||||
ConnectAsyncData *data = user_data;
|
||||
gssize written;
|
||||
|
||||
written = g_output_stream_write_finish (G_OUTPUT_STREAM (source),
|
||||
@ -386,7 +356,8 @@ connect_msg_write_cb (GObject *source,
|
||||
|
||||
if (written < 0)
|
||||
{
|
||||
complete_async_from_error (data, error);
|
||||
g_task_return_error (task, error);
|
||||
g_object_unref (task);
|
||||
return;
|
||||
}
|
||||
|
||||
@ -400,11 +371,11 @@ connect_msg_write_cb (GObject *source,
|
||||
data->length = SOCKS4_CONN_REP_LEN;
|
||||
data->offset = 0;
|
||||
|
||||
do_read (connect_reply_read_cb, data);
|
||||
do_read (connect_reply_read_cb, task, data);
|
||||
}
|
||||
else
|
||||
{
|
||||
do_write (connect_msg_write_cb, data);
|
||||
do_write (connect_msg_write_cb, task, data);
|
||||
}
|
||||
}
|
||||
|
||||
@ -413,8 +384,9 @@ connect_reply_read_cb (GObject *source,
|
||||
GAsyncResult *result,
|
||||
gpointer user_data)
|
||||
{
|
||||
GTask *task = user_data;
|
||||
ConnectAsyncData *data = g_task_get_task_data (task);
|
||||
GError *error = NULL;
|
||||
ConnectAsyncData *data = user_data;
|
||||
gssize read;
|
||||
|
||||
read = g_input_stream_read_finish (G_INPUT_STREAM (source),
|
||||
@ -422,7 +394,8 @@ connect_reply_read_cb (GObject *source,
|
||||
|
||||
if (read < 0)
|
||||
{
|
||||
complete_async_from_error (data, error);
|
||||
g_task_return_error (task, error);
|
||||
g_object_unref (task);
|
||||
return;
|
||||
}
|
||||
|
||||
@ -432,18 +405,20 @@ connect_reply_read_cb (GObject *source,
|
||||
{
|
||||
if (!parse_connect_reply (data->buffer, &error))
|
||||
{
|
||||
complete_async_from_error (data, error);
|
||||
g_task_return_error (task, error);
|
||||
g_object_unref (task);
|
||||
return;
|
||||
}
|
||||
else
|
||||
{
|
||||
GSimpleAsyncResult *simple = data->simple;
|
||||
g_simple_async_result_complete (simple);
|
||||
g_object_unref (simple);
|
||||
g_task_return_pointer (task, g_object_ref (data->io_stream), g_object_unref);
|
||||
g_object_unref (task);
|
||||
return;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
do_read (connect_reply_read_cb, data);
|
||||
do_read (connect_reply_read_cb, task, data);
|
||||
}
|
||||
}
|
||||
|
||||
@ -456,13 +431,7 @@ g_socks4a_proxy_connect_finish (GProxy *proxy,
|
||||
GAsyncResult *result,
|
||||
GError **error)
|
||||
{
|
||||
GSimpleAsyncResult *simple = G_SIMPLE_ASYNC_RESULT (result);
|
||||
ConnectAsyncData *data = g_simple_async_result_get_op_res_gpointer (simple);
|
||||
|
||||
if (g_simple_async_result_propagate_error (simple, error))
|
||||
return NULL;
|
||||
|
||||
return g_object_ref (data->io_stream);
|
||||
return g_task_propagate_pointer (G_TASK (result), error);
|
||||
}
|
||||
|
||||
static gboolean
|
||||
|
@ -39,7 +39,7 @@
|
||||
#include "goutputstream.h"
|
||||
#include "gproxy.h"
|
||||
#include "gproxyaddress.h"
|
||||
#include "gsimpleasyncresult.h"
|
||||
#include "gtask.h"
|
||||
|
||||
#define SOCKS5_VERSION 0x05
|
||||
|
||||
@ -538,7 +538,6 @@ error:
|
||||
|
||||
typedef struct
|
||||
{
|
||||
GSimpleAsyncResult *simple;
|
||||
GIOStream *io_stream;
|
||||
gchar *hostname;
|
||||
guint16 port;
|
||||
@ -547,7 +546,6 @@ typedef struct
|
||||
guint8 *buffer;
|
||||
gssize length;
|
||||
gssize offset;
|
||||
GCancellable *cancellable;
|
||||
} ConnectAsyncData;
|
||||
|
||||
static void nego_msg_write_cb (GObject *source,
|
||||
@ -562,7 +560,7 @@ static void auth_msg_write_cb (GObject *source,
|
||||
static void auth_reply_read_cb (GObject *source,
|
||||
GAsyncResult *result,
|
||||
gpointer user_data);
|
||||
static void send_connect_msg (ConnectAsyncData *data);
|
||||
static void send_connect_msg (GTask *task);
|
||||
static void connect_msg_write_cb (GObject *source,
|
||||
GAsyncResult *result,
|
||||
gpointer user_data);
|
||||
@ -579,52 +577,40 @@ static void connect_addr_read_cb (GObject *source,
|
||||
static void
|
||||
free_connect_data (ConnectAsyncData *data)
|
||||
{
|
||||
if (data->io_stream)
|
||||
g_object_unref (data->io_stream);
|
||||
g_object_unref (data->io_stream);
|
||||
|
||||
g_free (data->hostname);
|
||||
g_free (data->username);
|
||||
g_free (data->password);
|
||||
g_free (data->buffer);
|
||||
|
||||
if (data->cancellable)
|
||||
g_object_unref (data->cancellable);
|
||||
|
||||
g_slice_free (ConnectAsyncData, data);
|
||||
}
|
||||
|
||||
static void
|
||||
complete_async_from_error (ConnectAsyncData *data, GError *error)
|
||||
{
|
||||
GSimpleAsyncResult *simple = data->simple;
|
||||
g_simple_async_result_take_error (data->simple, error);
|
||||
g_simple_async_result_set_op_res_gpointer (simple, NULL, NULL);
|
||||
g_simple_async_result_complete (simple);
|
||||
g_object_unref (simple);
|
||||
}
|
||||
|
||||
static void
|
||||
do_read (GAsyncReadyCallback callback, ConnectAsyncData *data)
|
||||
do_read (GAsyncReadyCallback callback, GTask *task, ConnectAsyncData *data)
|
||||
{
|
||||
GInputStream *in;
|
||||
in = g_io_stream_get_input_stream (data->io_stream);
|
||||
g_input_stream_read_async (in,
|
||||
data->buffer + data->offset,
|
||||
data->length - data->offset,
|
||||
G_PRIORITY_DEFAULT, data->cancellable,
|
||||
callback, data);
|
||||
g_task_get_priority (task),
|
||||
g_task_get_cancellable (task),
|
||||
callback, task);
|
||||
}
|
||||
|
||||
static void
|
||||
do_write (GAsyncReadyCallback callback, ConnectAsyncData *data)
|
||||
do_write (GAsyncReadyCallback callback, GTask *task, ConnectAsyncData *data)
|
||||
{
|
||||
GOutputStream *out;
|
||||
out = g_io_stream_get_output_stream (data->io_stream);
|
||||
g_output_stream_write_async (out,
|
||||
data->buffer + data->offset,
|
||||
data->length - data->offset,
|
||||
G_PRIORITY_DEFAULT, data->cancellable,
|
||||
callback, data);
|
||||
g_task_get_priority (task),
|
||||
g_task_get_cancellable (task),
|
||||
callback, task);
|
||||
}
|
||||
|
||||
static void
|
||||
@ -635,20 +621,14 @@ g_socks5_proxy_connect_async (GProxy *proxy,
|
||||
GAsyncReadyCallback callback,
|
||||
gpointer user_data)
|
||||
{
|
||||
GSimpleAsyncResult *simple;
|
||||
GTask *task;
|
||||
ConnectAsyncData *data;
|
||||
|
||||
simple = g_simple_async_result_new (G_OBJECT (proxy),
|
||||
callback, user_data,
|
||||
g_socks5_proxy_connect_async);
|
||||
|
||||
data = g_slice_new0 (ConnectAsyncData);
|
||||
|
||||
data->simple = simple;
|
||||
data->io_stream = g_object_ref (io_stream);
|
||||
|
||||
if (cancellable)
|
||||
data->cancellable = g_object_ref (cancellable);
|
||||
task = g_task_new (proxy, cancellable, callback, user_data);
|
||||
g_task_set_task_data (task, data, (GDestroyNotify) free_connect_data);
|
||||
|
||||
g_object_get (G_OBJECT (proxy_address),
|
||||
"destination-hostname", &data->hostname,
|
||||
@ -657,15 +637,12 @@ g_socks5_proxy_connect_async (GProxy *proxy,
|
||||
"password", &data->password,
|
||||
NULL);
|
||||
|
||||
g_simple_async_result_set_op_res_gpointer (simple, data,
|
||||
(GDestroyNotify) free_connect_data);
|
||||
|
||||
data->buffer = g_malloc0 (SOCKS5_NEGO_MSG_LEN);
|
||||
data->length = set_nego_msg (data->buffer,
|
||||
data->username || data->password);
|
||||
data->offset = 0;
|
||||
|
||||
do_write (nego_msg_write_cb, data);
|
||||
do_write (nego_msg_write_cb, task, data);
|
||||
}
|
||||
|
||||
|
||||
@ -674,8 +651,9 @@ nego_msg_write_cb (GObject *source,
|
||||
GAsyncResult *res,
|
||||
gpointer user_data)
|
||||
{
|
||||
GTask *task = user_data;
|
||||
ConnectAsyncData *data = g_task_get_task_data (task);
|
||||
GError *error = NULL;
|
||||
ConnectAsyncData *data = user_data;
|
||||
gssize written;
|
||||
|
||||
written = g_output_stream_write_finish (G_OUTPUT_STREAM (source),
|
||||
@ -683,7 +661,8 @@ nego_msg_write_cb (GObject *source,
|
||||
|
||||
if (written < 0)
|
||||
{
|
||||
complete_async_from_error (data, error);
|
||||
g_task_return_error (task, error);
|
||||
g_object_unref (task);
|
||||
return;
|
||||
}
|
||||
|
||||
@ -697,11 +676,11 @@ nego_msg_write_cb (GObject *source,
|
||||
data->length = SOCKS5_NEGO_REP_LEN;
|
||||
data->offset = 0;
|
||||
|
||||
do_read (nego_reply_read_cb, data);
|
||||
do_read (nego_reply_read_cb, task, data);
|
||||
}
|
||||
else
|
||||
{
|
||||
do_write (nego_msg_write_cb, data);
|
||||
do_write (nego_msg_write_cb, task, data);
|
||||
}
|
||||
}
|
||||
|
||||
@ -710,8 +689,9 @@ nego_reply_read_cb (GObject *source,
|
||||
GAsyncResult *res,
|
||||
gpointer user_data)
|
||||
{
|
||||
GTask *task = user_data;
|
||||
ConnectAsyncData *data = g_task_get_task_data (task);
|
||||
GError *error = NULL;
|
||||
ConnectAsyncData *data = user_data;
|
||||
gssize read;
|
||||
|
||||
read = g_input_stream_read_finish (G_INPUT_STREAM (source),
|
||||
@ -719,7 +699,8 @@ nego_reply_read_cb (GObject *source,
|
||||
|
||||
if (read < 0)
|
||||
{
|
||||
complete_async_from_error (data, error);
|
||||
g_task_return_error (task, error);
|
||||
g_object_unref (task);
|
||||
return;
|
||||
}
|
||||
|
||||
@ -733,7 +714,8 @@ nego_reply_read_cb (GObject *source,
|
||||
|
||||
if (!parse_nego_reply (data->buffer, has_auth, &must_auth, &error))
|
||||
{
|
||||
complete_async_from_error (data, error);
|
||||
g_task_return_error (task, error);
|
||||
g_object_unref (task);
|
||||
return;
|
||||
}
|
||||
|
||||
@ -750,20 +732,21 @@ nego_reply_read_cb (GObject *source,
|
||||
|
||||
if (data->length < 0)
|
||||
{
|
||||
complete_async_from_error (data, error);
|
||||
g_task_return_error (task, error);
|
||||
g_object_unref (task);
|
||||
return;
|
||||
}
|
||||
|
||||
do_write (auth_msg_write_cb, data);
|
||||
do_write (auth_msg_write_cb, task, data);
|
||||
}
|
||||
else
|
||||
{
|
||||
send_connect_msg (data);
|
||||
send_connect_msg (task);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
do_read (nego_reply_read_cb, data);
|
||||
do_read (nego_reply_read_cb, task, data);
|
||||
}
|
||||
}
|
||||
|
||||
@ -772,8 +755,9 @@ auth_msg_write_cb (GObject *source,
|
||||
GAsyncResult *result,
|
||||
gpointer user_data)
|
||||
{
|
||||
GTask *task = user_data;
|
||||
ConnectAsyncData *data = g_task_get_task_data (task);
|
||||
GError *error = NULL;
|
||||
ConnectAsyncData *data = user_data;
|
||||
gssize written;
|
||||
|
||||
written = g_output_stream_write_finish (G_OUTPUT_STREAM (source),
|
||||
@ -781,7 +765,8 @@ auth_msg_write_cb (GObject *source,
|
||||
|
||||
if (written < 0)
|
||||
{
|
||||
complete_async_from_error (data, error);
|
||||
g_task_return_error (task, error);
|
||||
g_object_unref (task);
|
||||
return;
|
||||
}
|
||||
|
||||
@ -795,11 +780,11 @@ auth_msg_write_cb (GObject *source,
|
||||
data->length = SOCKS5_NEGO_REP_LEN;
|
||||
data->offset = 0;
|
||||
|
||||
do_read (auth_reply_read_cb, data);
|
||||
do_read (auth_reply_read_cb, task, data);
|
||||
}
|
||||
else
|
||||
{
|
||||
do_write (auth_msg_write_cb, data);
|
||||
do_write (auth_msg_write_cb, task, data);
|
||||
}
|
||||
}
|
||||
|
||||
@ -808,8 +793,9 @@ auth_reply_read_cb (GObject *source,
|
||||
GAsyncResult *result,
|
||||
gpointer user_data)
|
||||
{
|
||||
GTask *task = user_data;
|
||||
ConnectAsyncData *data = g_task_get_task_data (task);
|
||||
GError *error = NULL;
|
||||
ConnectAsyncData *data = user_data;
|
||||
gssize read;
|
||||
|
||||
read = g_input_stream_read_finish (G_INPUT_STREAM (source),
|
||||
@ -817,7 +803,8 @@ auth_reply_read_cb (GObject *source,
|
||||
|
||||
if (read < 0)
|
||||
{
|
||||
complete_async_from_error (data, error);
|
||||
g_task_return_error (task, error);
|
||||
g_object_unref (task);
|
||||
return;
|
||||
}
|
||||
|
||||
@ -827,21 +814,23 @@ auth_reply_read_cb (GObject *source,
|
||||
{
|
||||
if (!check_auth_status (data->buffer, &error))
|
||||
{
|
||||
complete_async_from_error (data, error);
|
||||
g_task_return_error (task, error);
|
||||
g_object_unref (task);
|
||||
return;
|
||||
}
|
||||
|
||||
send_connect_msg (data);
|
||||
send_connect_msg (task);
|
||||
}
|
||||
else
|
||||
{
|
||||
do_read (auth_reply_read_cb, data);
|
||||
do_read (auth_reply_read_cb, task, data);
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
send_connect_msg (ConnectAsyncData *data)
|
||||
send_connect_msg (GTask *task)
|
||||
{
|
||||
ConnectAsyncData *data = g_task_get_task_data (task);
|
||||
GError *error = NULL;
|
||||
|
||||
g_free (data->buffer);
|
||||
@ -855,11 +844,12 @@ send_connect_msg (ConnectAsyncData *data)
|
||||
|
||||
if (data->length < 0)
|
||||
{
|
||||
complete_async_from_error (data, error);
|
||||
g_task_return_error (task, error);
|
||||
g_object_unref (task);
|
||||
return;
|
||||
}
|
||||
|
||||
do_write (connect_msg_write_cb, data);
|
||||
do_write (connect_msg_write_cb, task, data);
|
||||
}
|
||||
|
||||
static void
|
||||
@ -867,8 +857,9 @@ connect_msg_write_cb (GObject *source,
|
||||
GAsyncResult *result,
|
||||
gpointer user_data)
|
||||
{
|
||||
GTask *task = user_data;
|
||||
ConnectAsyncData *data = g_task_get_task_data (task);
|
||||
GError *error = NULL;
|
||||
ConnectAsyncData *data = user_data;
|
||||
gssize written;
|
||||
|
||||
written = g_output_stream_write_finish (G_OUTPUT_STREAM (source),
|
||||
@ -876,7 +867,8 @@ connect_msg_write_cb (GObject *source,
|
||||
|
||||
if (written < 0)
|
||||
{
|
||||
complete_async_from_error (data, error);
|
||||
g_task_return_error (task, error);
|
||||
g_object_unref (task);
|
||||
return;
|
||||
}
|
||||
|
||||
@ -890,11 +882,11 @@ connect_msg_write_cb (GObject *source,
|
||||
data->length = 4;
|
||||
data->offset = 0;
|
||||
|
||||
do_read (connect_reply_read_cb, data);
|
||||
do_read (connect_reply_read_cb, task, data);
|
||||
}
|
||||
else
|
||||
{
|
||||
do_write (connect_msg_write_cb, data);
|
||||
do_write (connect_msg_write_cb, task, data);
|
||||
}
|
||||
}
|
||||
|
||||
@ -903,8 +895,9 @@ connect_reply_read_cb (GObject *source,
|
||||
GAsyncResult *result,
|
||||
gpointer user_data)
|
||||
{
|
||||
GTask *task = user_data;
|
||||
ConnectAsyncData *data = g_task_get_task_data (task);
|
||||
GError *error = NULL;
|
||||
ConnectAsyncData *data = user_data;
|
||||
gssize read;
|
||||
|
||||
read = g_input_stream_read_finish (G_INPUT_STREAM (source),
|
||||
@ -912,7 +905,8 @@ connect_reply_read_cb (GObject *source,
|
||||
|
||||
if (read < 0)
|
||||
{
|
||||
complete_async_from_error (data, error);
|
||||
g_task_return_error (task, error);
|
||||
g_object_unref (task);
|
||||
return;
|
||||
}
|
||||
|
||||
@ -924,7 +918,8 @@ connect_reply_read_cb (GObject *source,
|
||||
|
||||
if (!parse_connect_reply (data->buffer, &atype, &error))
|
||||
{
|
||||
complete_async_from_error (data, error);
|
||||
g_task_return_error (task, error);
|
||||
g_object_unref (task);
|
||||
return;
|
||||
}
|
||||
|
||||
@ -933,25 +928,25 @@ connect_reply_read_cb (GObject *source,
|
||||
case SOCKS5_ATYP_IPV4:
|
||||
data->length = 6;
|
||||
data->offset = 0;
|
||||
do_read (connect_addr_read_cb, data);
|
||||
do_read (connect_addr_read_cb, task, data);
|
||||
break;
|
||||
|
||||
case SOCKS5_ATYP_IPV6:
|
||||
data->length = 18;
|
||||
data->offset = 0;
|
||||
do_read (connect_addr_read_cb, data);
|
||||
do_read (connect_addr_read_cb, task, data);
|
||||
break;
|
||||
|
||||
case SOCKS5_ATYP_DOMAINNAME:
|
||||
data->length = 1;
|
||||
data->offset = 0;
|
||||
do_read (connect_addr_len_read_cb, data);
|
||||
do_read (connect_addr_len_read_cb, task, data);
|
||||
break;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
do_read (connect_reply_read_cb, data);
|
||||
do_read (connect_reply_read_cb, task, data);
|
||||
}
|
||||
}
|
||||
|
||||
@ -960,8 +955,9 @@ connect_addr_len_read_cb (GObject *source,
|
||||
GAsyncResult *result,
|
||||
gpointer user_data)
|
||||
{
|
||||
GTask *task = user_data;
|
||||
ConnectAsyncData *data = g_task_get_task_data (task);
|
||||
GError *error = NULL;
|
||||
ConnectAsyncData *data = user_data;
|
||||
gssize read;
|
||||
|
||||
read = g_input_stream_read_finish (G_INPUT_STREAM (source),
|
||||
@ -969,14 +965,15 @@ connect_addr_len_read_cb (GObject *source,
|
||||
|
||||
if (read < 0)
|
||||
{
|
||||
complete_async_from_error (data, error);
|
||||
g_task_return_error (task, error);
|
||||
g_object_unref (task);
|
||||
return;
|
||||
}
|
||||
|
||||
data->length = data->buffer[0] + 2;
|
||||
data->offset = 0;
|
||||
|
||||
do_read (connect_addr_read_cb, data);
|
||||
do_read (connect_addr_read_cb, task, data);
|
||||
}
|
||||
|
||||
static void
|
||||
@ -984,8 +981,9 @@ connect_addr_read_cb (GObject *source,
|
||||
GAsyncResult *result,
|
||||
gpointer user_data)
|
||||
{
|
||||
GTask *task = user_data;
|
||||
ConnectAsyncData *data = g_task_get_task_data (task);
|
||||
GError *error = NULL;
|
||||
ConnectAsyncData *data = user_data;
|
||||
gssize read;
|
||||
|
||||
read = g_input_stream_read_finish (G_INPUT_STREAM (source),
|
||||
@ -993,7 +991,8 @@ connect_addr_read_cb (GObject *source,
|
||||
|
||||
if (read < 0)
|
||||
{
|
||||
complete_async_from_error (data, error);
|
||||
g_task_return_error (task, error);
|
||||
g_object_unref (task);
|
||||
return;
|
||||
}
|
||||
|
||||
@ -1001,13 +1000,13 @@ connect_addr_read_cb (GObject *source,
|
||||
|
||||
if (data->offset == data->length)
|
||||
{
|
||||
GSimpleAsyncResult *simple = data->simple;
|
||||
g_simple_async_result_complete (simple);
|
||||
g_object_unref (simple);
|
||||
g_task_return_pointer (task, g_object_ref (data->io_stream), g_object_unref);
|
||||
g_object_unref (task);
|
||||
return;
|
||||
}
|
||||
else
|
||||
{
|
||||
do_read (connect_reply_read_cb, data);
|
||||
do_read (connect_reply_read_cb, task, data);
|
||||
}
|
||||
}
|
||||
|
||||
@ -1016,13 +1015,7 @@ g_socks5_proxy_connect_finish (GProxy *proxy,
|
||||
GAsyncResult *result,
|
||||
GError **error)
|
||||
{
|
||||
GSimpleAsyncResult *simple = G_SIMPLE_ASYNC_RESULT (result);
|
||||
ConnectAsyncData *data = g_simple_async_result_get_op_res_gpointer (simple);
|
||||
|
||||
if (g_simple_async_result_propagate_error (simple, error))
|
||||
return NULL;
|
||||
|
||||
return g_object_ref (data->io_stream);
|
||||
return g_task_propagate_pointer (G_TASK (result), error);
|
||||
}
|
||||
|
||||
static gboolean
|
||||
|
@ -25,7 +25,7 @@
|
||||
#include "config.h"
|
||||
#include "gtcpconnection.h"
|
||||
#include "gasyncresult.h"
|
||||
#include "gsimpleasyncresult.h"
|
||||
#include "gtask.h"
|
||||
#include "giostream.h"
|
||||
#include "glibintl.h"
|
||||
|
||||
@ -151,7 +151,6 @@ g_tcp_connection_close (GIOStream *stream,
|
||||
GSocket *socket;
|
||||
char buffer[1024];
|
||||
gssize ret;
|
||||
GError *my_error;
|
||||
gboolean had_error;
|
||||
|
||||
socket = g_socket_connection_get_socket (G_SOCKET_CONNECTION (stream));
|
||||
@ -169,20 +168,13 @@ g_tcp_connection_close (GIOStream *stream,
|
||||
{
|
||||
while (TRUE)
|
||||
{
|
||||
my_error = NULL;
|
||||
ret = g_socket_receive (socket, buffer, sizeof (buffer),
|
||||
cancellable, &my_error);
|
||||
ret = g_socket_receive_with_blocking (socket, buffer, sizeof (buffer),
|
||||
TRUE, cancellable, error);
|
||||
if (ret < 0)
|
||||
{
|
||||
if (g_error_matches (my_error, G_IO_ERROR, G_IO_ERROR_WOULD_BLOCK))
|
||||
g_error_free (my_error);
|
||||
else
|
||||
{
|
||||
had_error = TRUE;
|
||||
g_propagate_error (error, my_error);
|
||||
error = NULL;
|
||||
break;
|
||||
}
|
||||
had_error = TRUE;
|
||||
error = NULL;
|
||||
break;
|
||||
}
|
||||
if (ret == 0)
|
||||
break;
|
||||
@ -194,76 +186,60 @@ g_tcp_connection_close (GIOStream *stream,
|
||||
->close_fn (stream, cancellable, error) && !had_error;
|
||||
}
|
||||
|
||||
typedef struct {
|
||||
GSimpleAsyncResult *res;
|
||||
GCancellable *cancellable;
|
||||
} CloseAsyncData;
|
||||
|
||||
/* consumes @error */
|
||||
static void
|
||||
close_async_data_free (CloseAsyncData *data)
|
||||
{
|
||||
g_object_unref (data->res);
|
||||
if (data->cancellable)
|
||||
g_object_unref (data->cancellable);
|
||||
g_free (data);
|
||||
}
|
||||
|
||||
static void
|
||||
async_close_finish (CloseAsyncData *data,
|
||||
GError *error /* consumed */,
|
||||
gboolean in_mainloop)
|
||||
async_close_finish (GTask *task,
|
||||
GError *error)
|
||||
{
|
||||
GIOStreamClass *parent = G_IO_STREAM_CLASS (g_tcp_connection_parent_class);
|
||||
GIOStream *stream;
|
||||
GError *my_error;
|
||||
GIOStream *stream = g_task_get_source_object (task);
|
||||
GCancellable *cancellable = g_task_get_cancellable (task);
|
||||
|
||||
stream = G_IO_STREAM (g_async_result_get_source_object (G_ASYNC_RESULT (data->res)));
|
||||
|
||||
/* Doesn't block, ignore error */
|
||||
/* Close underlying stream, ignoring further errors if we already
|
||||
* have one.
|
||||
*/
|
||||
if (error)
|
||||
{
|
||||
parent->close_fn (stream, data->cancellable, NULL);
|
||||
g_simple_async_result_take_error (data->res, error);
|
||||
}
|
||||
parent->close_fn (stream, cancellable, NULL);
|
||||
else
|
||||
{
|
||||
my_error = NULL;
|
||||
parent->close_fn (stream, data->cancellable, &my_error);
|
||||
if (my_error)
|
||||
g_simple_async_result_take_error (data->res, my_error);
|
||||
}
|
||||
parent->close_fn (stream, cancellable, &error);
|
||||
|
||||
if (in_mainloop)
|
||||
g_simple_async_result_complete (data->res);
|
||||
if (error)
|
||||
g_task_return_error (task, error);
|
||||
else
|
||||
g_simple_async_result_complete_in_idle (data->res);
|
||||
g_task_return_boolean (task, TRUE);
|
||||
}
|
||||
|
||||
|
||||
static gboolean
|
||||
close_read_ready (GSocket *socket,
|
||||
GIOCondition condition,
|
||||
CloseAsyncData *data)
|
||||
GTask *task)
|
||||
{
|
||||
GError *error = NULL;
|
||||
char buffer[1024];
|
||||
gssize ret;
|
||||
|
||||
ret = g_socket_receive (socket, buffer, sizeof (buffer),
|
||||
data->cancellable, &error);
|
||||
ret = g_socket_receive_with_blocking (socket, buffer, sizeof (buffer),
|
||||
FALSE, g_task_get_cancellable (task),
|
||||
&error);
|
||||
if (ret < 0)
|
||||
{
|
||||
if (g_error_matches (error, G_IO_ERROR, G_IO_ERROR_WOULD_BLOCK))
|
||||
g_error_free (error);
|
||||
{
|
||||
g_error_free (error);
|
||||
return TRUE;
|
||||
}
|
||||
else
|
||||
{
|
||||
async_close_finish (data, error, TRUE);
|
||||
async_close_finish (task, error);
|
||||
g_object_unref (task);
|
||||
return FALSE;
|
||||
}
|
||||
}
|
||||
|
||||
if (ret == 0)
|
||||
{
|
||||
async_close_finish (data, NULL, TRUE);
|
||||
async_close_finish (task, NULL);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
@ -279,38 +255,29 @@ g_tcp_connection_close_async (GIOStream *stream,
|
||||
gpointer user_data)
|
||||
{
|
||||
GTcpConnection *connection = G_TCP_CONNECTION (stream);
|
||||
CloseAsyncData *data;
|
||||
GSocket *socket;
|
||||
GSource *source;
|
||||
GError *error;
|
||||
GTask *task;
|
||||
|
||||
if (connection->priv->graceful_disconnect &&
|
||||
!g_cancellable_is_cancelled (cancellable) /* Cancelled -> close fast */)
|
||||
{
|
||||
data = g_new (CloseAsyncData, 1);
|
||||
data->res =
|
||||
g_simple_async_result_new (G_OBJECT (stream), callback, user_data,
|
||||
g_tcp_connection_close_async);
|
||||
if (cancellable)
|
||||
data->cancellable = g_object_ref (cancellable);
|
||||
else
|
||||
data->cancellable = NULL;
|
||||
task = g_task_new (stream, cancellable, callback, user_data);
|
||||
g_task_set_priority (task, io_priority);
|
||||
|
||||
socket = g_socket_connection_get_socket (G_SOCKET_CONNECTION (stream));
|
||||
|
||||
error = NULL;
|
||||
if (!g_socket_shutdown (socket, FALSE, TRUE, &error))
|
||||
{
|
||||
async_close_finish (data, error, FALSE);
|
||||
close_async_data_free (data);
|
||||
g_task_return_error (task, error);
|
||||
g_object_unref (task);
|
||||
return;
|
||||
}
|
||||
|
||||
source = g_socket_create_source (socket, G_IO_IN, cancellable);
|
||||
g_source_set_callback (source,
|
||||
(GSourceFunc) close_read_ready,
|
||||
data, (GDestroyNotify)close_async_data_free);
|
||||
g_source_attach (source, g_main_context_get_thread_default ());
|
||||
g_task_attach_source (task, source, (GSourceFunc) close_read_ready);
|
||||
g_source_unref (source);
|
||||
|
||||
return;
|
||||
|
@ -27,8 +27,8 @@
|
||||
#include "gasyncresult.h"
|
||||
#include "gcancellable.h"
|
||||
#include "glibintl.h"
|
||||
#include "gsimpleasyncresult.h"
|
||||
#include "gsocketconnectable.h"
|
||||
#include "gtask.h"
|
||||
#include "gtlscertificate.h"
|
||||
#include "gtlsinteraction.h"
|
||||
|
||||
@ -89,7 +89,6 @@ typedef struct _AsyncVerifyChain {
|
||||
GSocketConnectable *identity;
|
||||
GTlsInteraction *interaction;
|
||||
GTlsDatabaseVerifyFlags flags;
|
||||
GTlsCertificateFlags verify_result;
|
||||
} AsyncVerifyChain;
|
||||
|
||||
static void
|
||||
@ -104,24 +103,27 @@ async_verify_chain_free (gpointer data)
|
||||
}
|
||||
|
||||
static void
|
||||
async_verify_chain_thread (GSimpleAsyncResult *res,
|
||||
GObject *object,
|
||||
GCancellable *cancellable)
|
||||
async_verify_chain_thread (GTask *task,
|
||||
gpointer object,
|
||||
gpointer task_data,
|
||||
GCancellable *cancellable)
|
||||
{
|
||||
AsyncVerifyChain *args = g_simple_async_result_get_op_res_gpointer (res);
|
||||
AsyncVerifyChain *args = task_data;
|
||||
GTlsCertificateFlags verify_result;
|
||||
GError *error = NULL;
|
||||
|
||||
args->verify_result = g_tls_database_verify_chain (G_TLS_DATABASE (object),
|
||||
args->chain,
|
||||
args->purpose,
|
||||
args->identity,
|
||||
args->interaction,
|
||||
args->flags,
|
||||
cancellable,
|
||||
&error);
|
||||
|
||||
verify_result = g_tls_database_verify_chain (G_TLS_DATABASE (object),
|
||||
args->chain,
|
||||
args->purpose,
|
||||
args->identity,
|
||||
args->interaction,
|
||||
args->flags,
|
||||
cancellable,
|
||||
&error);
|
||||
if (error)
|
||||
g_simple_async_result_take_error (res, error);
|
||||
g_task_return_error (task, error);
|
||||
else
|
||||
g_task_return_int (task, (gssize)verify_result);
|
||||
}
|
||||
|
||||
static void
|
||||
@ -135,7 +137,7 @@ g_tls_database_real_verify_chain_async (GTlsDatabase *self,
|
||||
GAsyncReadyCallback callback,
|
||||
gpointer user_data)
|
||||
{
|
||||
GSimpleAsyncResult *res;
|
||||
GTask *task;
|
||||
AsyncVerifyChain *args;
|
||||
|
||||
args = g_slice_new0 (AsyncVerifyChain);
|
||||
@ -145,12 +147,10 @@ g_tls_database_real_verify_chain_async (GTlsDatabase *self,
|
||||
args->interaction = interaction ? g_object_ref (interaction) : NULL;
|
||||
args->flags = flags;
|
||||
|
||||
res = g_simple_async_result_new (G_OBJECT (self), callback, user_data,
|
||||
g_tls_database_real_verify_chain_async);
|
||||
g_simple_async_result_set_op_res_gpointer (res, args, async_verify_chain_free);
|
||||
g_simple_async_result_run_in_thread (res, async_verify_chain_thread,
|
||||
G_PRIORITY_DEFAULT, cancellable);
|
||||
g_object_unref (res);
|
||||
task = g_task_new (self, cancellable, callback, user_data);
|
||||
g_task_set_task_data (task, args, async_verify_chain_free);
|
||||
g_task_run_in_thread (task, async_verify_chain_thread);
|
||||
g_object_unref (task);
|
||||
}
|
||||
|
||||
static GTlsCertificateFlags
|
||||
@ -158,24 +158,21 @@ g_tls_database_real_verify_chain_finish (GTlsDatabase *self,
|
||||
GAsyncResult *result,
|
||||
GError **error)
|
||||
{
|
||||
AsyncVerifyChain *args;
|
||||
GTlsCertificateFlags ret;
|
||||
|
||||
g_return_val_if_fail (G_IS_SIMPLE_ASYNC_RESULT (result), G_TLS_CERTIFICATE_GENERIC_ERROR);
|
||||
g_return_val_if_fail (g_simple_async_result_is_valid (result, G_OBJECT (self),
|
||||
g_tls_database_real_verify_chain_async), FALSE);
|
||||
g_return_val_if_fail (g_task_is_valid (result, self), G_TLS_CERTIFICATE_GENERIC_ERROR);
|
||||
|
||||
if (g_simple_async_result_propagate_error (G_SIMPLE_ASYNC_RESULT (result), error))
|
||||
ret = (GTlsCertificateFlags)g_task_propagate_int (G_TASK (result), error);
|
||||
if (ret == (GTlsCertificateFlags)-1)
|
||||
return G_TLS_CERTIFICATE_GENERIC_ERROR;
|
||||
|
||||
args = g_simple_async_result_get_op_res_gpointer (G_SIMPLE_ASYNC_RESULT (result));
|
||||
return args->verify_result;
|
||||
else
|
||||
return ret;
|
||||
}
|
||||
|
||||
typedef struct {
|
||||
gchar *handle;
|
||||
GTlsInteraction *interaction;
|
||||
GTlsDatabaseLookupFlags flags;
|
||||
GTlsCertificate *result;
|
||||
} AsyncLookupCertificateForHandle;
|
||||
|
||||
static void
|
||||
@ -185,27 +182,29 @@ async_lookup_certificate_for_handle_free (gpointer data)
|
||||
|
||||
g_free (args->handle);
|
||||
g_clear_object (&args->interaction);
|
||||
g_clear_object (&args->result);
|
||||
g_slice_free (AsyncLookupCertificateForHandle, args);
|
||||
}
|
||||
|
||||
static void
|
||||
async_lookup_certificate_for_handle_thread (GSimpleAsyncResult *res,
|
||||
GObject *object,
|
||||
GCancellable *cancellable)
|
||||
async_lookup_certificate_for_handle_thread (GTask *task,
|
||||
gpointer object,
|
||||
gpointer task_data,
|
||||
GCancellable *cancellable)
|
||||
{
|
||||
AsyncLookupCertificateForHandle *args = g_simple_async_result_get_op_res_gpointer (res);
|
||||
AsyncLookupCertificateForHandle *args = task_data;
|
||||
GTlsCertificate *result;
|
||||
GError *error = NULL;
|
||||
|
||||
args->result = g_tls_database_lookup_certificate_for_handle (G_TLS_DATABASE (object),
|
||||
args->handle,
|
||||
args->interaction,
|
||||
args->flags,
|
||||
cancellable,
|
||||
&error);
|
||||
|
||||
if (error)
|
||||
g_simple_async_result_take_error (res, error);
|
||||
result = g_tls_database_lookup_certificate_for_handle (G_TLS_DATABASE (object),
|
||||
args->handle,
|
||||
args->interaction,
|
||||
args->flags,
|
||||
cancellable,
|
||||
&error);
|
||||
if (result)
|
||||
g_task_return_pointer (task, result, g_object_unref);
|
||||
else
|
||||
g_task_return_error (task, error);
|
||||
}
|
||||
|
||||
static void
|
||||
@ -217,19 +216,17 @@ g_tls_database_real_lookup_certificate_for_handle_async (GTlsDatabase
|
||||
GAsyncReadyCallback callback,
|
||||
gpointer user_data)
|
||||
{
|
||||
GSimpleAsyncResult *res;
|
||||
GTask *task;
|
||||
AsyncLookupCertificateForHandle *args;
|
||||
|
||||
args = g_slice_new0 (AsyncLookupCertificateForHandle);
|
||||
args->handle = g_strdup (handle);
|
||||
args->interaction = interaction ? g_object_ref (interaction) : NULL;
|
||||
|
||||
res = g_simple_async_result_new (G_OBJECT (self), callback, user_data,
|
||||
g_tls_database_real_lookup_certificate_for_handle_async);
|
||||
g_simple_async_result_set_op_res_gpointer (res, args, async_lookup_certificate_for_handle_free);
|
||||
g_simple_async_result_run_in_thread (res, async_lookup_certificate_for_handle_thread,
|
||||
G_PRIORITY_DEFAULT, cancellable);
|
||||
g_object_unref (res);
|
||||
task = g_task_new (self, cancellable, callback, user_data);
|
||||
g_task_set_task_data (task, args, async_lookup_certificate_for_handle_free);
|
||||
g_task_run_in_thread (task, async_lookup_certificate_for_handle_thread);
|
||||
g_object_unref (task);
|
||||
}
|
||||
|
||||
static GTlsCertificate*
|
||||
@ -237,20 +234,9 @@ g_tls_database_real_lookup_certificate_for_handle_finish (GTlsDatabase
|
||||
GAsyncResult *result,
|
||||
GError **error)
|
||||
{
|
||||
AsyncLookupCertificateForHandle *args;
|
||||
GTlsCertificate *certificate;
|
||||
g_return_val_if_fail (g_task_is_valid (result, self), NULL);
|
||||
|
||||
g_return_val_if_fail (G_IS_SIMPLE_ASYNC_RESULT (result), NULL);
|
||||
g_return_val_if_fail (g_simple_async_result_is_valid (result, G_OBJECT (self),
|
||||
g_tls_database_real_lookup_certificate_for_handle_async), FALSE);
|
||||
|
||||
if (g_simple_async_result_propagate_error (G_SIMPLE_ASYNC_RESULT (result), error))
|
||||
return NULL;
|
||||
|
||||
args = g_simple_async_result_get_op_res_gpointer (G_SIMPLE_ASYNC_RESULT (result));
|
||||
certificate = args->result;
|
||||
args->result = NULL;
|
||||
return certificate;
|
||||
return g_task_propagate_pointer (G_TASK (result), error);
|
||||
}
|
||||
|
||||
|
||||
@ -258,7 +244,6 @@ typedef struct {
|
||||
GTlsCertificate *certificate;
|
||||
GTlsInteraction *interaction;
|
||||
GTlsDatabaseLookupFlags flags;
|
||||
GTlsCertificate *issuer;
|
||||
} AsyncLookupCertificateIssuer;
|
||||
|
||||
static void
|
||||
@ -268,27 +253,29 @@ async_lookup_certificate_issuer_free (gpointer data)
|
||||
|
||||
g_clear_object (&args->certificate);
|
||||
g_clear_object (&args->interaction);
|
||||
g_clear_object (&args->issuer);
|
||||
g_slice_free (AsyncLookupCertificateIssuer, args);
|
||||
}
|
||||
|
||||
static void
|
||||
async_lookup_certificate_issuer_thread (GSimpleAsyncResult *res,
|
||||
GObject *object,
|
||||
GCancellable *cancellable)
|
||||
async_lookup_certificate_issuer_thread (GTask *task,
|
||||
gpointer object,
|
||||
gpointer task_data,
|
||||
GCancellable *cancellable)
|
||||
{
|
||||
AsyncLookupCertificateIssuer *args = g_simple_async_result_get_op_res_gpointer (res);
|
||||
AsyncLookupCertificateIssuer *args = task_data;
|
||||
GTlsCertificate *issuer;
|
||||
GError *error = NULL;
|
||||
|
||||
args->issuer = g_tls_database_lookup_certificate_issuer (G_TLS_DATABASE (object),
|
||||
args->certificate,
|
||||
args->interaction,
|
||||
args->flags,
|
||||
cancellable,
|
||||
&error);
|
||||
|
||||
if (error)
|
||||
g_simple_async_result_take_error (res, error);
|
||||
issuer = g_tls_database_lookup_certificate_issuer (G_TLS_DATABASE (object),
|
||||
args->certificate,
|
||||
args->interaction,
|
||||
args->flags,
|
||||
cancellable,
|
||||
&error);
|
||||
if (issuer)
|
||||
g_task_return_pointer (task, issuer, g_object_unref);
|
||||
else
|
||||
g_task_return_error (task, error);
|
||||
}
|
||||
|
||||
static void
|
||||
@ -300,7 +287,7 @@ g_tls_database_real_lookup_certificate_issuer_async (GTlsDatabase *sel
|
||||
GAsyncReadyCallback callback,
|
||||
gpointer user_data)
|
||||
{
|
||||
GSimpleAsyncResult *res;
|
||||
GTask *task;
|
||||
AsyncLookupCertificateIssuer *args;
|
||||
|
||||
args = g_slice_new0 (AsyncLookupCertificateIssuer);
|
||||
@ -308,73 +295,66 @@ g_tls_database_real_lookup_certificate_issuer_async (GTlsDatabase *sel
|
||||
args->flags = flags;
|
||||
args->interaction = interaction ? g_object_ref (interaction) : NULL;
|
||||
|
||||
res = g_simple_async_result_new (G_OBJECT (self), callback, user_data,
|
||||
g_tls_database_real_lookup_certificate_issuer_async);
|
||||
g_simple_async_result_set_op_res_gpointer (res, args, async_lookup_certificate_issuer_free);
|
||||
g_simple_async_result_run_in_thread (res, async_lookup_certificate_issuer_thread,
|
||||
G_PRIORITY_DEFAULT, cancellable);
|
||||
g_object_unref (res);
|
||||
task = g_task_new (self, cancellable, callback, user_data);
|
||||
g_task_set_task_data (task, args, async_lookup_certificate_issuer_free);
|
||||
g_task_run_in_thread (task, async_lookup_certificate_issuer_thread);
|
||||
g_object_unref (task);
|
||||
}
|
||||
|
||||
static GTlsCertificate*
|
||||
static GTlsCertificate *
|
||||
g_tls_database_real_lookup_certificate_issuer_finish (GTlsDatabase *self,
|
||||
GAsyncResult *result,
|
||||
GError **error)
|
||||
{
|
||||
AsyncLookupCertificateIssuer *args;
|
||||
GTlsCertificate *issuer;
|
||||
g_return_val_if_fail (g_task_is_valid (result, self), NULL);
|
||||
|
||||
g_return_val_if_fail (G_IS_SIMPLE_ASYNC_RESULT (result), NULL);
|
||||
g_return_val_if_fail (g_simple_async_result_is_valid (result, G_OBJECT (self),
|
||||
g_tls_database_real_lookup_certificate_issuer_async), FALSE);
|
||||
|
||||
if (g_simple_async_result_propagate_error (G_SIMPLE_ASYNC_RESULT (result), error))
|
||||
return NULL;
|
||||
|
||||
args = g_simple_async_result_get_op_res_gpointer (G_SIMPLE_ASYNC_RESULT (result));
|
||||
issuer = args->issuer;
|
||||
args->issuer = NULL;
|
||||
return issuer;
|
||||
return g_task_propagate_pointer (G_TASK (result), error);
|
||||
}
|
||||
|
||||
typedef struct {
|
||||
GByteArray *issuer;
|
||||
GTlsInteraction *interaction;
|
||||
GTlsDatabaseLookupFlags flags;
|
||||
GList *results;
|
||||
} AsyncLookupCertificatesIssuedBy;
|
||||
|
||||
static void
|
||||
async_lookup_certificates_issued_by_free (gpointer data)
|
||||
{
|
||||
AsyncLookupCertificatesIssuedBy *args = data;
|
||||
GList *l;
|
||||
|
||||
g_byte_array_unref (args->issuer);
|
||||
g_clear_object (&args->interaction);
|
||||
for (l = args->results; l; l = g_list_next (l))
|
||||
g_object_unref (l->data);
|
||||
g_list_free (args->results);
|
||||
g_slice_free (AsyncLookupCertificatesIssuedBy, args);
|
||||
}
|
||||
|
||||
static void
|
||||
async_lookup_certificates_issued_by_thread (GSimpleAsyncResult *res,
|
||||
GObject *object,
|
||||
GCancellable *cancellable)
|
||||
async_lookup_certificates_free_certificates (gpointer data)
|
||||
{
|
||||
AsyncLookupCertificatesIssuedBy *args = g_simple_async_result_get_op_res_gpointer (res);
|
||||
GList *list = data;
|
||||
|
||||
g_list_free_full (list, g_object_unref);
|
||||
}
|
||||
|
||||
static void
|
||||
async_lookup_certificates_issued_by_thread (GTask *task,
|
||||
gpointer object,
|
||||
gpointer task_data,
|
||||
GCancellable *cancellable)
|
||||
{
|
||||
AsyncLookupCertificatesIssuedBy *args = task_data;
|
||||
GList *results;
|
||||
GError *error = NULL;
|
||||
|
||||
args->results = g_tls_database_lookup_certificates_issued_by (G_TLS_DATABASE (object),
|
||||
args->issuer,
|
||||
args->interaction,
|
||||
args->flags,
|
||||
cancellable,
|
||||
&error);
|
||||
|
||||
if (error)
|
||||
g_simple_async_result_take_error (res, error);
|
||||
results = g_tls_database_lookup_certificates_issued_by (G_TLS_DATABASE (object),
|
||||
args->issuer,
|
||||
args->interaction,
|
||||
args->flags,
|
||||
cancellable,
|
||||
&error);
|
||||
if (results)
|
||||
g_task_return_pointer (task, results, async_lookup_certificates_free_certificates);
|
||||
else
|
||||
g_task_return_error (task, error);
|
||||
}
|
||||
|
||||
static void
|
||||
@ -386,7 +366,7 @@ g_tls_database_real_lookup_certificates_issued_by_async (GTlsDatabase
|
||||
GAsyncReadyCallback callback,
|
||||
gpointer user_data)
|
||||
{
|
||||
GSimpleAsyncResult *res;
|
||||
GTask *task;
|
||||
AsyncLookupCertificatesIssuedBy *args;
|
||||
|
||||
args = g_slice_new0 (AsyncLookupCertificatesIssuedBy);
|
||||
@ -394,33 +374,20 @@ g_tls_database_real_lookup_certificates_issued_by_async (GTlsDatabase
|
||||
args->flags = flags;
|
||||
args->interaction = interaction ? g_object_ref (interaction) : NULL;
|
||||
|
||||
res = g_simple_async_result_new (G_OBJECT (self), callback, user_data,
|
||||
g_tls_database_real_lookup_certificates_issued_by_async);
|
||||
g_simple_async_result_set_op_res_gpointer (res, args, async_lookup_certificates_issued_by_free);
|
||||
g_simple_async_result_run_in_thread (res, async_lookup_certificates_issued_by_thread,
|
||||
G_PRIORITY_DEFAULT, cancellable);
|
||||
g_object_unref (res);
|
||||
task = g_task_new (self, cancellable, callback, user_data);
|
||||
g_task_set_task_data (task, args, async_lookup_certificates_issued_by_free);
|
||||
g_task_run_in_thread (task, async_lookup_certificates_issued_by_thread);
|
||||
g_object_unref (task);
|
||||
}
|
||||
|
||||
static GList*
|
||||
static GList *
|
||||
g_tls_database_real_lookup_certificates_issued_by_finish (GTlsDatabase *self,
|
||||
GAsyncResult *result,
|
||||
GError **error)
|
||||
{
|
||||
AsyncLookupCertificatesIssuedBy *args;
|
||||
GList *results;
|
||||
g_return_val_if_fail (g_task_is_valid (result, self), NULL);
|
||||
|
||||
g_return_val_if_fail (G_IS_SIMPLE_ASYNC_RESULT (result), NULL);
|
||||
g_return_val_if_fail (g_simple_async_result_is_valid (result, G_OBJECT (self),
|
||||
g_tls_database_real_lookup_certificates_issued_by_async), FALSE);
|
||||
|
||||
if (g_simple_async_result_propagate_error (G_SIMPLE_ASYNC_RESULT (result), error))
|
||||
return NULL;
|
||||
|
||||
args = g_simple_async_result_get_op_res_gpointer (G_SIMPLE_ASYNC_RESULT (result));
|
||||
results = args->results;
|
||||
args->results = NULL;
|
||||
return results;
|
||||
return g_task_propagate_pointer (G_TASK (result), error);
|
||||
}
|
||||
|
||||
static void
|
||||
|
@ -28,7 +28,7 @@
|
||||
#include "gtlspassword.h"
|
||||
#include "gasyncresult.h"
|
||||
#include "gcancellable.h"
|
||||
#include "gsimpleasyncresult.h"
|
||||
#include "gtask.h"
|
||||
#include "gioenumtypes.h"
|
||||
#include "glibintl.h"
|
||||
|
||||
@ -468,7 +468,7 @@ g_tls_interaction_ask_password_async (GTlsInteraction *interaction,
|
||||
gpointer user_data)
|
||||
{
|
||||
GTlsInteractionClass *klass;
|
||||
GSimpleAsyncResult *res;
|
||||
GTask *task;
|
||||
|
||||
g_return_if_fail (G_IS_TLS_INTERACTION (interaction));
|
||||
g_return_if_fail (G_IS_TLS_PASSWORD (password));
|
||||
@ -483,10 +483,10 @@ g_tls_interaction_ask_password_async (GTlsInteraction *interaction,
|
||||
}
|
||||
else
|
||||
{
|
||||
res = g_simple_async_result_new (G_OBJECT (interaction), callback, user_data,
|
||||
g_tls_interaction_ask_password_async);
|
||||
g_simple_async_result_complete_in_idle (res);
|
||||
g_object_unref (res);
|
||||
task = g_task_new (interaction, cancellable, callback, user_data);
|
||||
g_task_set_source_tag (task, g_tls_interaction_ask_password_async);
|
||||
g_task_return_int (task, G_TLS_INTERACTION_UNHANDLED);
|
||||
g_object_unref (task);
|
||||
}
|
||||
}
|
||||
|
||||
@ -520,18 +520,17 @@ g_tls_interaction_ask_password_finish (GTlsInteraction *interaction,
|
||||
g_return_val_if_fail (G_IS_TLS_INTERACTION (interaction), G_TLS_INTERACTION_UNHANDLED);
|
||||
g_return_val_if_fail (G_IS_ASYNC_RESULT (result), G_TLS_INTERACTION_UNHANDLED);
|
||||
|
||||
/* If it's one of our simple unhandled async results, handle here */
|
||||
if (g_simple_async_result_is_valid (result, G_OBJECT (interaction),
|
||||
g_tls_interaction_ask_password_async))
|
||||
klass = G_TLS_INTERACTION_GET_CLASS (interaction);
|
||||
if (klass->ask_password_finish)
|
||||
{
|
||||
return G_TLS_INTERACTION_UNHANDLED;
|
||||
}
|
||||
g_return_val_if_fail (klass->ask_password_async != NULL, G_TLS_INTERACTION_UNHANDLED);
|
||||
|
||||
/* Invoke finish of derived class */
|
||||
else
|
||||
{
|
||||
klass = G_TLS_INTERACTION_GET_CLASS (interaction);
|
||||
g_return_val_if_fail (klass->ask_password_finish, G_TLS_INTERACTION_UNHANDLED);
|
||||
return (klass->ask_password_finish) (interaction, result, error);
|
||||
}
|
||||
else
|
||||
{
|
||||
g_return_val_if_fail (g_async_result_is_tagged (result, g_tls_interaction_ask_password_async), G_TLS_INTERACTION_UNHANDLED);
|
||||
|
||||
return g_task_propagate_int (G_TASK (result), error);
|
||||
}
|
||||
}
|
||||
|
@ -359,18 +359,20 @@ g_unix_connection_send_credentials (GUnixConnection *connection,
|
||||
}
|
||||
|
||||
static void
|
||||
send_credentials_async_thread (GSimpleAsyncResult *result,
|
||||
GObject *object,
|
||||
GCancellable *cancellable)
|
||||
send_credentials_async_thread (GTask *task,
|
||||
gpointer source_object,
|
||||
gpointer task_data,
|
||||
GCancellable *cancellable)
|
||||
{
|
||||
GError *error = NULL;
|
||||
|
||||
if (!g_unix_connection_send_credentials (G_UNIX_CONNECTION (object),
|
||||
cancellable,
|
||||
&error))
|
||||
{
|
||||
g_simple_async_result_take_error (result, error);
|
||||
}
|
||||
if (g_unix_connection_send_credentials (G_UNIX_CONNECTION (source_object),
|
||||
cancellable,
|
||||
&error))
|
||||
g_task_return_boolean (task, TRUE);
|
||||
else
|
||||
g_task_return_error (task, error);
|
||||
g_object_unref (task);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -396,17 +398,11 @@ g_unix_connection_send_credentials_async (GUnixConnection *connection,
|
||||
GAsyncReadyCallback callback,
|
||||
gpointer user_data)
|
||||
{
|
||||
GSimpleAsyncResult *result;
|
||||
GTask *task;
|
||||
|
||||
result = g_simple_async_result_new (G_OBJECT (connection),
|
||||
callback, user_data,
|
||||
g_unix_connection_send_credentials_async);
|
||||
task = g_task_new (connection, cancellable, callback, user_data);
|
||||
|
||||
g_simple_async_result_run_in_thread (result,
|
||||
send_credentials_async_thread,
|
||||
G_PRIORITY_DEFAULT,
|
||||
cancellable);
|
||||
g_object_unref (result);
|
||||
g_task_run_in_thread (task, send_credentials_async_thread);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -427,18 +423,9 @@ g_unix_connection_send_credentials_finish (GUnixConnection *connection,
|
||||
GAsyncResult *result,
|
||||
GError **error)
|
||||
{
|
||||
g_return_val_if_fail (
|
||||
g_simple_async_result_is_valid (result,
|
||||
G_OBJECT (connection),
|
||||
g_unix_connection_send_credentials_async),
|
||||
FALSE);
|
||||
g_return_val_if_fail (g_task_is_valid (result, connection), FALSE);
|
||||
|
||||
if (g_simple_async_result_propagate_error (G_SIMPLE_ASYNC_RESULT (result),
|
||||
error))
|
||||
return FALSE;
|
||||
|
||||
|
||||
return TRUE;
|
||||
return g_task_propagate_boolean (G_TASK (result), error);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -644,21 +631,22 @@ g_unix_connection_receive_credentials (GUnixConnection *connection,
|
||||
}
|
||||
|
||||
static void
|
||||
receive_credentials_async_thread (GSimpleAsyncResult *result,
|
||||
GObject *object,
|
||||
GCancellable *cancellable)
|
||||
receive_credentials_async_thread (GTask *task,
|
||||
gpointer source_object,
|
||||
gpointer task_data,
|
||||
GCancellable *cancellable)
|
||||
{
|
||||
GCredentials *creds;
|
||||
GError *error = NULL;
|
||||
|
||||
creds = g_unix_connection_receive_credentials (G_UNIX_CONNECTION (object),
|
||||
creds = g_unix_connection_receive_credentials (G_UNIX_CONNECTION (source_object),
|
||||
cancellable,
|
||||
&error);
|
||||
|
||||
if (creds == NULL)
|
||||
g_simple_async_result_take_error (result, error);
|
||||
if (creds)
|
||||
g_task_return_pointer (task, creds, g_object_unref);
|
||||
else
|
||||
g_simple_async_result_set_op_res_gpointer (result, creds, g_object_unref);
|
||||
g_task_return_error (task, error);
|
||||
g_object_unref (task);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -684,18 +672,11 @@ g_unix_connection_receive_credentials_async (GUnixConnection *connection,
|
||||
GAsyncReadyCallback callback,
|
||||
gpointer user_data)
|
||||
{
|
||||
GSimpleAsyncResult *result;
|
||||
GTask *task;
|
||||
|
||||
result = g_simple_async_result_new (G_OBJECT (connection),
|
||||
callback, user_data,
|
||||
g_unix_connection_receive_credentials_async);
|
||||
task = g_task_new (connection, cancellable, callback, user_data);
|
||||
|
||||
g_simple_async_result_run_in_thread (result,
|
||||
receive_credentials_async_thread,
|
||||
G_PRIORITY_DEFAULT,
|
||||
cancellable);
|
||||
|
||||
g_object_unref (result);
|
||||
g_task_run_in_thread (task, receive_credentials_async_thread);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -717,16 +698,7 @@ g_unix_connection_receive_credentials_finish (GUnixConnection *connection,
|
||||
GAsyncResult *result,
|
||||
GError **error)
|
||||
{
|
||||
g_return_val_if_fail (
|
||||
g_simple_async_result_is_valid (result,
|
||||
G_OBJECT (connection),
|
||||
g_unix_connection_receive_credentials_async),
|
||||
NULL);
|
||||
g_return_val_if_fail (g_task_is_valid (result, connection), NULL);
|
||||
|
||||
if (g_simple_async_result_propagate_error (G_SIMPLE_ASYNC_RESULT (result),
|
||||
error))
|
||||
return NULL;
|
||||
|
||||
return g_object_ref (g_simple_async_result_get_op_res_gpointer (
|
||||
G_SIMPLE_ASYNC_RESULT (result)));
|
||||
return g_task_propagate_pointer (G_TASK (result), error);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user