[tracker] libtracker-extract: Made more resilient to dbus/splice failures
- From: Carlos Garnacho <carlosg src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [tracker] libtracker-extract: Made more resilient to dbus/splice failures
- Date: Fri, 25 Nov 2011 11:32:45 +0000 (UTC)
commit 514add76af0a0026cac9c9aaa2188ba81930df4d
Author: Carlos Garnacho <carlos lanedo com>
Date: Fri Nov 25 12:18:16 2011 +0100
libtracker-extract: Made more resilient to dbus/splice failures
Now if one of both operations fail, the other is cancelled right
away, instead of having the petition wait forever for the other
part to be finished, which might never happen.
src/libtracker-extract/tracker-extract-client.c | 42 +++++++++++++++++++---
1 files changed, 36 insertions(+), 6 deletions(-)
---
diff --git a/src/libtracker-extract/tracker-extract-client.c b/src/libtracker-extract/tracker-extract-client.c
index b54b398..c74bad6 100644
--- a/src/libtracker-extract/tracker-extract-client.c
+++ b/src/libtracker-extract/tracker-extract-client.c
@@ -44,10 +44,12 @@ typedef struct {
GOutputStream *output_stream;
SendAndSpliceCallback callback;
GCancellable *cancellable;
+ GCancellable *inner_cancellable;
gpointer data;
gboolean splice_finished;
gboolean dbus_finished;
GError *error;
+ guint cancel_handler_id;
} SendAndSpliceData;
typedef struct {
@@ -55,6 +57,13 @@ typedef struct {
GSimpleAsyncResult *res;
} MetadataCallData;
+static void
+propagate_cancellation (GCancellable *cancellable,
+ GCancellable *inner_cancellable)
+{
+ g_cancellable_cancel (inner_cancellable);
+}
+
static SendAndSpliceData *
send_and_splice_data_new (GInputStream *unix_input_stream,
GInputStream *buffered_input_stream,
@@ -69,9 +78,15 @@ send_and_splice_data_new (GInputStream *unix_input_stream,
data->unix_input_stream = unix_input_stream;
data->buffered_input_stream = buffered_input_stream;
data->output_stream = output_stream;
+ data->inner_cancellable = g_cancellable_new ();
if (cancellable) {
data->cancellable = g_object_ref (cancellable);
+
+ data->cancel_handler_id =
+ g_cancellable_connect (data->cancellable,
+ G_CALLBACK (propagate_cancellation),
+ data->inner_cancellable, NULL);
}
data->callback = callback;
@@ -83,14 +98,19 @@ send_and_splice_data_new (GInputStream *unix_input_stream,
static void
send_and_splice_data_free (SendAndSpliceData *data)
{
- g_object_unref (data->unix_input_stream);
- g_object_unref (data->buffered_input_stream);
- g_object_unref (data->output_stream);
-
if (data->cancellable) {
+ g_cancellable_disconnect (data->cancellable, data->cancel_handler_id);
g_object_unref (data->cancellable);
}
+ g_output_stream_close (data->output_stream, NULL, NULL);
+ g_input_stream_close (data->buffered_input_stream, NULL, NULL);
+
+ g_object_unref (data->unix_input_stream);
+ g_object_unref (data->buffered_input_stream);
+ g_object_unref (data->output_stream);
+ g_object_unref (data->inner_cancellable);
+
if (data->error) {
g_error_free (data->error);
}
@@ -150,6 +170,11 @@ send_and_splice_splice_callback (GObject *source,
} else {
g_error_free (error);
}
+
+ /* Ensure the other operation is cancelled */
+ if (!data->dbus_finished) {
+ g_cancellable_cancel (data->inner_cancellable);
+ }
}
data->splice_finished = TRUE;
@@ -185,6 +210,11 @@ send_and_splice_dbus_callback (GObject *source,
} else {
g_error_free (error);
}
+
+ /* Ensure the other operation is cancelled */
+ if (!data->splice_finished) {
+ g_cancellable_cancel (data->inner_cancellable);
+ }
}
data->dbus_finished = TRUE;
@@ -224,7 +254,7 @@ dbus_send_and_splice_async (GDBusConnection *connection,
G_DBUS_SEND_MESSAGE_FLAGS_NONE,
-1,
NULL,
- cancellable,
+ data->inner_cancellable,
send_and_splice_dbus_callback,
data);
@@ -233,7 +263,7 @@ dbus_send_and_splice_async (GDBusConnection *connection,
G_OUTPUT_STREAM_SPLICE_CLOSE_SOURCE |
G_OUTPUT_STREAM_SPLICE_CLOSE_TARGET,
0,
- cancellable,
+ data->inner_cancellable,
send_and_splice_splice_callback,
data);
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]