diff options
author | Benjamin Otte <otte@gnome.org> | 2009-06-25 13:01:48 +0200 |
---|---|---|
committer | Benjamin Otte <otte@gnome.org> | 2009-06-25 13:01:48 +0200 |
commit | c372064a04f8c24efdb99a3b0811bd17ddfb2176 (patch) | |
tree | 61906e539114b76be2d7c82c384688f50bada002 /client/gvfsdaemondbus.c | |
parent | 133bd0ec75a94b8316b56c252dfc62a3ed23fade (diff) | |
download | gvfs-c372064a04f8c24efdb99a3b0811bd17ddfb2176.tar.gz |
try extra hard to make sure operations get cancelled properly
Previously there were some rather big windows that allowed for races
between cancelling and calling g_simple_async_result_complete().
This code makes sure we check for cancellaton right before calling
g_simple_async_result_complete(), which gets rid of that window and
gives you the guarantee that cancelling an operation in the main thread
will indeed return a CANCELLED error.
Diffstat (limited to 'client/gvfsdaemondbus.c')
-rw-r--r-- | client/gvfsdaemondbus.c | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/client/gvfsdaemondbus.c b/client/gvfsdaemondbus.c index a9dae139..4675d4fc 100644 --- a/client/gvfsdaemondbus.c +++ b/client/gvfsdaemondbus.c @@ -1024,3 +1024,28 @@ _g_dbus_connection_get_sync (const char *dbus_id, return connection; } + +/** + * _g_simple_async_result_complete_with_cancellable: + * @result: the result + * @cancellable: a cancellable to check + * + * If @cancellable is cancelled, sets @result into the cancelled error + * state. Then calls g_simple_async_result_complete(). + * This function is useful to ensure that @result is properly set into + * an error state on cancellation. + **/ +void +_g_simple_async_result_complete_with_cancellable (GSimpleAsyncResult *result, + GCancellable *cancellable) +{ + if (cancellable && + g_cancellable_is_cancelled (cancellable)) + g_simple_async_result_set_error (result, + G_IO_ERROR, + G_IO_ERROR_CANCELLED, + "%s", _("Operation was cancelled")); + + g_simple_async_result_complete (result); +} + |