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