[glib/wip/tingping/socket-client-slow-fix] fixup! gsocketclient: Fix critical on cancellation
- From: Patrick Griffis <pgriffis src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [glib/wip/tingping/socket-client-slow-fix] fixup! gsocketclient: Fix critical on cancellation
- Date: Sat, 23 Feb 2019 17:54:15 +0000 (UTC)
commit 960dafa321c8f40a686693f4d88fc3c53587a96f
Author: Patrick Griffis <tingping tingping se>
Date: Sat Feb 23 12:53:36 2019 -0500
fixup! gsocketclient: Fix critical on cancellation
gio/gsocketclient.c | 13 ++++++----
gio/tests/gsocketclient-slow.c | 58 ++++++++++++++++++++++++++++++++++++++++--
2 files changed, 64 insertions(+), 7 deletions(-)
---
diff --git a/gio/gsocketclient.c b/gio/gsocketclient.c
index f289f8be5..689d87d38 100644
--- a/gio/gsocketclient.c
+++ b/gio/gsocketclient.c
@@ -1432,7 +1432,6 @@ g_socket_client_async_connect_complete (GSocketClientAsyncConnectData *data)
else
g_socket_client_emit_event (data->client, G_SOCKET_CLIENT_COMPLETE, data->connectable, NULL);
- g_clear_object (&data->connection);
g_object_unref (data->task);
}
@@ -1551,8 +1550,9 @@ g_socket_client_proxy_connect_callback (GObject *object,
}
static gboolean
-task_completed_or_cancelled (GTask *task)
+task_completed_or_cancelled (GSocketClientAsyncConnectData *data)
{
+ GTask *task = data->task;
GCancellable *cancellable = g_task_get_cancellable (task);
GError *error = NULL;
@@ -1561,7 +1561,10 @@ task_completed_or_cancelled (GTask *task)
else if (cancellable && g_cancellable_set_error_if_cancelled (cancellable, &error))
{
if (!g_task_had_error (task))
- g_task_return_error (task, g_steal_pointer (&error));
+ {
+ g_socket_client_emit_event (data->client, G_SOCKET_CLIENT_COMPLETE, data->connectable, NULL);
+ g_task_return_error (task, g_steal_pointer (&error));
+ }
g_clear_error (&error);
return TRUE;
}
@@ -1581,7 +1584,7 @@ g_socket_client_connected_callback (GObject *source,
GProxy *proxy;
const gchar *protocol;
- if (task_completed_or_cancelled (data->task) || g_cancellable_is_cancelled (attempt->cancellable))
+ if (task_completed_or_cancelled (data) || g_cancellable_is_cancelled (attempt->cancellable))
{
g_object_unref (data->task);
connection_attempt_unref (attempt);
@@ -1715,7 +1718,7 @@ g_socket_client_enumerator_callback (GObject *object,
ConnectionAttempt *attempt;
GError *error = NULL;
- if (task_completed_or_cancelled (data->task))
+ if (task_completed_or_cancelled (data))
{
g_object_unref (data->task);
return;
diff --git a/gio/tests/gsocketclient-slow.c b/gio/tests/gsocketclient-slow.c
index a78ea71d0..181c278a4 100644
--- a/gio/tests/gsocketclient-slow.c
+++ b/gio/tests/gsocketclient-slow.c
@@ -87,7 +87,24 @@ on_timer (GCancellable *cancel)
}
static void
-test_happy_eyeballs_cancel (void)
+on_event (GSocketClient *client,
+ GSocketClientEvent event,
+ GSocketConnectable *connectable,
+ GIOStream *connection,
+ gboolean *got_completed_event)
+{
+ if (event == G_SOCKET_CLIENT_COMPLETE)
+ {
+ *got_completed_event = TRUE;
+ /* Due to timing it is impossible to ensure cancellation doesn't
+ happen after we returned the pointer. So this may be non-NULL.
+ */
+ /* g_assert_null (connection); */
+ }
+}
+
+static void
+test_happy_eyeballs_cancel_delayed (void)
{
GSocketClient *client;
GSocketService *service;
@@ -95,6 +112,7 @@ test_happy_eyeballs_cancel (void)
guint16 port;
GMainLoop *loop;
GCancellable *cancel;
+ gboolean got_completed_event = FALSE;
loop = g_main_loop_new (NULL, FALSE);
@@ -107,8 +125,42 @@ test_happy_eyeballs_cancel (void)
cancel = g_cancellable_new ();
g_socket_client_connect_to_host_async (client, "localhost", port, cancel, on_connected_cancelled, loop);
g_timeout_add (1, (GSourceFunc) on_timer, cancel);
+ g_signal_connect (client, "event", G_CALLBACK (on_event), &got_completed_event);
g_main_loop_run (loop);
+ g_assert_true (got_completed_event);
+ g_main_loop_unref (loop);
+ g_object_unref (service);
+ g_object_unref (client);
+ g_object_unref (cancel);
+}
+
+static void
+test_happy_eyeballs_cancel_instant (void)
+{
+ GSocketClient *client;
+ GSocketService *service;
+ GError *error = NULL;
+ guint16 port;
+ GMainLoop *loop;
+ GCancellable *cancel;
+ gboolean got_completed_event = FALSE;
+
+ loop = g_main_loop_new (NULL, FALSE);
+
+ service = g_socket_service_new ();
+ port = g_socket_listener_add_any_inet_port (G_SOCKET_LISTENER (service), NULL, &error);
+ g_assert_no_error (error);
+ g_socket_service_start (service);
+
+ client = g_socket_client_new ();
+ cancel = g_cancellable_new ();
+ g_cancellable_cancel (cancel);
+ g_socket_client_connect_to_host_async (client, "localhost", port, cancel, on_connected_cancelled, loop);
+ g_signal_connect (client, "event", G_CALLBACK (on_event), &got_completed_event);
+ g_main_loop_run (loop);
+
+ g_assert_true (got_completed_event);
g_main_loop_unref (loop);
g_object_unref (service);
g_object_unref (client);
@@ -121,7 +173,9 @@ main (int argc, char *argv[])
g_test_init (&argc, &argv, NULL);
g_test_add_func ("/socket-client/happy-eyeballs/slow", test_happy_eyeballs);
- g_test_add_func ("/socket-client/happy-eyeballs/cancellation", test_happy_eyeballs_cancel);
+ g_test_add_func ("/socket-client/happy-eyeballs/cancellation/instant", test_happy_eyeballs_cancel_instant);
+ g_test_add_func ("/socket-client/happy-eyeballs/cancellation/delayed", test_happy_eyeballs_cancel_delayed);
+
return g_test_run ();
}
\ No newline at end of file
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]