Commit 1b1c2c07 authored by Michael Catanzaro's avatar Michael Catanzaro Committed by Michael Catanzaro

Name all GTasks and tighten assertions around their use

Every GTask should have a name! This helps when debugging problems.

Also, for every GTask used in an async operation, we should check (a)
that the source tag matches, and (b) that the task is valid. This uses
g_return assertions for anything applications can screw up, and g_assert
for anything internal to glib-networking.

Lastly, there's no need to set a source tag in
g_libproxy_resolver_lookup() since that's a sync function and there's
nowhere it can ever be checked.
parent 03bc29b9
Pipeline #92992 passed with stage
in 1 minute and 52 seconds
......@@ -463,6 +463,7 @@ g_proxy_resolver_gnome_lookup_async (GProxyResolver *proxy_resolver,
task = g_task_new (resolver, cancellable, callback, user_data);
g_task_set_source_tag (task, g_proxy_resolver_gnome_lookup_async);
g_task_set_name (task, "[glib-networking] g_proxy_resolver_gnome_lookup_async");
if (!g_proxy_resolver_gnome_lookup_internal (resolver, uri,
&proxies, &pacrunner, &autoconfig_url,
......@@ -499,6 +500,7 @@ g_proxy_resolver_gnome_lookup_finish (GProxyResolver *resolver,
GError **error)
{
g_return_val_if_fail (g_task_is_valid (result, resolver), NULL);
g_return_val_if_fail (g_task_get_source_tag (G_TASK (result)) == g_proxy_resolver_gnome_lookup_async, NULL);
return g_task_propagate_pointer (G_TASK (result), error);
}
......
......@@ -172,7 +172,7 @@ g_libproxy_resolver_lookup (GProxyResolver *iresolver,
gchar **proxies;
task = g_task_new (resolver, cancellable, NULL, NULL);
g_task_set_source_tag (task, g_libproxy_resolver_lookup);
g_task_set_name (task, "[glib-networking] g_libproxy_resolver_lookup");
g_task_set_task_data (task, g_strdup (uri), g_free);
g_task_set_return_on_cancel (task, TRUE);
......@@ -194,6 +194,7 @@ g_libproxy_resolver_lookup_async (GProxyResolver *resolver,
task = g_task_new (resolver, cancellable, callback, user_data);
g_task_set_source_tag (task, g_libproxy_resolver_lookup_async);
g_task_set_name (task, "[glib-networking] g_libproxy_resolver_lookup_async");
g_task_set_task_data (task, g_strdup (uri), g_free);
g_task_set_return_on_cancel (task, TRUE);
g_task_run_in_thread (task, get_libproxy_proxies);
......@@ -206,6 +207,7 @@ g_libproxy_resolver_lookup_finish (GProxyResolver *resolver,
GError **error)
{
g_return_val_if_fail (g_task_is_valid (result, resolver), NULL);
g_return_val_if_fail (g_task_get_source_tag (G_TASK (result)) == g_libproxy_resolver_lookup_async, NULL);
return g_task_propagate_pointer (G_TASK (result), error);
}
......
......@@ -165,10 +165,21 @@ static gboolean do_implicit_handshake (GTlsConnectionBase *tls,
gint64 timeout,
GCancellable *cancellable,
GError **error);
static gboolean finish_handshake (GTlsConnectionBase *tls,
GTask *task,
GError **error);
static void g_tls_connection_base_handshake_async (GTlsConnection *conn,
int io_priority,
GCancellable *cancellable,
GAsyncReadyCallback callback,
gpointer user_data);
static gboolean g_tls_connection_base_handshake (GTlsConnection *conn,
GCancellable *cancellable,
GError **error);
G_DEFINE_ABSTRACT_TYPE_WITH_CODE (GTlsConnectionBase, g_tls_connection_base, G_TYPE_TLS_CONNECTION,
G_ADD_PRIVATE (GTlsConnectionBase);
G_IMPLEMENT_INTERFACE (G_TYPE_DATAGRAM_BASED,
......@@ -1401,6 +1412,11 @@ sync_handshake_thread_completed (GObject *object,
{
GTlsConnectionBase *tls = G_TLS_CONNECTION_BASE (object);
GTlsConnectionBasePrivate *priv = g_tls_connection_base_get_instance_private (tls);
gpointer source_tag;
source_tag = g_task_get_source_tag (G_TASK (result));
g_assert (source_tag == do_implicit_handshake || source_tag == g_tls_connection_base_handshake);
g_assert (g_task_is_valid (result, object));
g_assert (g_main_context_is_owner (priv->handshake_context));
......@@ -1511,6 +1527,7 @@ g_tls_connection_base_handshake (GTlsConnection *conn,
task = g_task_new (conn, cancellable, sync_handshake_thread_completed, NULL);
g_task_set_source_tag (task, g_tls_connection_base_handshake);
g_task_set_name (task, "[glib-networking] g_tls_connection_base_handshake");
g_task_set_return_on_cancel (task, TRUE);
timeout = g_new0 (gint64, 1);
......@@ -1560,6 +1577,9 @@ handshake_thread_completed (GObject *object,
GError *error = NULL;
gboolean need_finish_handshake, success;
g_assert (g_task_is_valid (result, object));
g_assert (g_task_get_source_tag (G_TASK (result)) == g_tls_connection_base_handshake_async);
g_mutex_lock (&priv->op_mutex);
if (priv->need_finish_handshake)
{
......@@ -1632,10 +1652,12 @@ g_tls_connection_base_handshake_async (GTlsConnection *conn,
caller_task = g_task_new (conn, cancellable, callback, user_data);
g_task_set_source_tag (caller_task, g_tls_connection_base_handshake_async);
g_task_set_name (caller_task, "[glib-networking] g_tls_connection_base_handshake_async (caller task)");
g_task_set_priority (caller_task, io_priority);
thread_task = g_task_new (conn, cancellable, handshake_thread_completed, caller_task);
g_task_set_source_tag (thread_task, g_tls_connection_base_handshake_async);
g_task_set_name (caller_task, "[glib-networking] g_tls_connection_base_handshake_async (thread task)");
g_task_set_priority (thread_task, io_priority);
timeout = g_new0 (gint64, 1);
......@@ -1652,6 +1674,7 @@ g_tls_connection_base_handshake_finish (GTlsConnection *conn,
GError **error)
{
g_return_val_if_fail (g_task_is_valid (result, conn), FALSE);
g_return_val_if_fail (g_task_get_source_tag (G_TASK (result)) == g_tls_connection_base_handshake_async, FALSE);
return g_task_propagate_boolean (G_TASK (result), error);
}
......@@ -1704,6 +1727,7 @@ do_implicit_handshake (GTlsConnectionBase *tls,
timeout ? sync_handshake_thread_completed : NULL,
NULL);
g_task_set_source_tag (priv->implicit_handshake, do_implicit_handshake);
g_task_set_name (priv->implicit_handshake, "[glib-networking] do_implicit_handshake");
thread_timeout = g_new0 (gint64, 1);
g_task_set_task_data (priv->implicit_handshake,
......@@ -2238,6 +2262,7 @@ g_tls_connection_base_close_internal_async (GIOStream *stream,
task = g_task_new (stream, cancellable, callback, user_data);
g_task_set_source_tag (task, g_tls_connection_base_close_internal_async);
g_task_set_name (task, "[glib-networking] g_tls_connection_base_close_internal_async");
g_task_set_priority (task, io_priority);
g_task_set_task_data (task, GINT_TO_POINTER (direction), NULL);
g_task_run_in_thread (task, close_thread);
......@@ -2262,6 +2287,7 @@ g_tls_connection_base_close_finish (GIOStream *stream,
GError **error)
{
g_return_val_if_fail (g_task_is_valid (result, stream), FALSE);
g_return_val_if_fail (g_task_get_source_tag (G_TASK (result)) == g_tls_connection_base_close_internal_async, FALSE);
return g_task_propagate_boolean (G_TASK (result), error);
}
......@@ -2293,6 +2319,7 @@ g_tls_connection_base_dtls_shutdown_finish (GDtlsConnection *conn,
GError **error)
{
g_return_val_if_fail (g_task_is_valid (result, conn), FALSE);
g_return_val_if_fail (g_task_get_source_tag (G_TASK (result)) == g_tls_connection_base_close_internal_async, FALSE);
return g_task_propagate_boolean (G_TASK (result), error);
}
......
......@@ -211,6 +211,7 @@ g_tls_input_stream_close_async (GInputStream *stream,
task = g_task_new (stream, cancellable, callback, user_data);
g_task_set_source_tag (task, g_tls_input_stream_close_async);
g_task_set_name (task, "[glib-networking] g_tls_input_stream_close_async");
g_task_set_priority (task, io_priority);
g_task_run_in_thread (task, close_thread);
g_object_unref (task);
......
......@@ -213,6 +213,7 @@ g_tls_output_stream_close_async (GOutputStream *stream,
task = g_task_new (stream, cancellable, callback, user_data);
g_task_set_source_tag (task, g_tls_output_stream_close_async);
g_task_set_name (task, "[glib-networking] g_tls_output_stream_close_async");
g_task_set_priority (task, io_priority);
g_task_run_in_thread (task, close_thread);
g_object_unref (task);
......
......@@ -51,6 +51,8 @@ mock_interaction_ask_password_async (GTlsInteraction *interaction,
GTask *task;
task = g_task_new (interaction, cancellable, callback, user_data);
g_task_set_source_tag (task, mock_interaction_ask_password_async);
g_task_set_name (task, "[glib-networking] mock_interaction_ask_password_async");
if (self->static_error)
g_task_return_error (task, g_error_copy (self->static_error));
......@@ -67,6 +69,8 @@ mock_interaction_ask_password_finish (GTlsInteraction *interaction,
{
g_return_val_if_fail (g_task_is_valid (result, interaction),
G_TLS_INTERACTION_UNHANDLED);
g_return_val_if_fail (g_task_get_source_tag (G_TASK (result)) == mock_interaction_ask_password_async,
G_TLS_INTERACTION_UNHANDLED);
if (g_task_had_error (G_TASK (result)))
{
......@@ -112,6 +116,8 @@ mock_interaction_request_certificate_async (GTlsInteraction *interact
GTask *task;
task = g_task_new (interaction, cancellable, callback, user_data);
g_task_set_source_tag (task, mock_interaction_request_certificate_async);
g_task_set_name (task, "[glib-networking] mock_interaction_request_certificate_async");
if (self->static_error)
g_task_return_error (task, g_error_copy (self->static_error));
......@@ -130,6 +136,8 @@ mock_interaction_request_certificate_finish (GTlsInteraction *interaction,
{
g_return_val_if_fail (g_task_is_valid (result, interaction),
G_TLS_INTERACTION_UNHANDLED);
g_return_val_if_fail (g_task_get_source_tag (G_TASK (result)) == mock_interaction_request_certificate_async,
G_TLS_INTERACTION_UNHANDLED);
if (!g_task_propagate_boolean (G_TASK (result), error))
return G_TLS_INTERACTION_FAILED;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment