summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPhilip Withnall <pwithnall@endlessos.org>2023-04-25 18:38:40 +0100
committerPhilip Withnall <pwithnall@endlessos.org>2023-04-27 12:23:25 +0100
commit1c4384aec58cae002817cc55651fcf32b556143e (patch)
treee7f4aeb042651137288c0e9539d346f004d857b5
parent2ac66413a4669228d101d0a1f77664d7fe5e7d9a (diff)
downloadglib-1c4384aec58cae002817cc55651fcf32b556143e.tar.gz
tests: Fix cancellation source handling in resolver manual test
If `async_cancel()` was invoked, it would remove the IO watch source, which would cause the `g_source_remove()` call at the end of `main()` to warn about an unknown source ID. Fix that by handling the source as a pointer instead of a handle. Signed-off-by: Philip Withnall <pwithnall@endlessos.org>
-rw-r--r--gio/tests/resolver.c11
1 files changed, 7 insertions, 4 deletions
diff --git a/gio/tests/resolver.c b/gio/tests/resolver.c
index 68b3d3cfb..b8adb4a36 100644
--- a/gio/tests/resolver.c
+++ b/gio/tests/resolver.c
@@ -689,7 +689,7 @@ static gboolean
async_cancel (GIOChannel *source, GIOCondition cond, gpointer cancel)
{
g_cancellable_cancel (cancel);
- return FALSE;
+ return G_SOURCE_REMOVE;
}
#endif
@@ -734,7 +734,7 @@ main (int argc, char **argv)
GError *error = NULL;
#ifdef G_OS_UNIX
GIOChannel *chan;
- guint watch;
+ GSource *watch_source = NULL;
#endif
context = g_option_context_new ("lookups ...");
@@ -768,7 +768,9 @@ main (int argc, char **argv)
exit (1);
}
chan = g_io_channel_unix_new (cancel_fds[0]);
- watch = g_io_add_watch (chan, G_IO_IN, async_cancel, cancellable);
+ watch_source = g_io_create_watch (chan, G_IO_IN);
+ g_source_set_callback (watch_source, (GSourceFunc) async_cancel, cancellable, NULL);
+ g_source_attach (watch_source, NULL);
g_io_channel_unref (chan);
#endif
@@ -792,7 +794,8 @@ main (int argc, char **argv)
g_main_loop_unref (loop);
#ifdef G_OS_UNIX
- g_source_remove (watch);
+ g_source_destroy (watch_source);
+ g_clear_pointer (&watch_source, g_source_unref);
#endif
g_object_unref (cancellable);
g_option_context_free (context);