summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorXavier Claessens <xclaesse@gmail.com>2010-07-12 17:11:41 +0200
committerXavier Claessens <xclaesse@gmail.com>2010-07-12 17:11:41 +0200
commit381ba707694ef6b45db23428208e96ab5f3cae84 (patch)
treed71cf37df35e32b6abcb711506041ea2979405f5
parent55f1b8ecbb5a23cf3e86838f85b2eed8d8868be5 (diff)
Propagate the GError if splice operation fails
-rw-r--r--src/common.c23
-rw-r--r--src/common.h3
-rw-r--r--src/service.c9
3 files changed, 29 insertions, 6 deletions
diff --git a/src/common.c b/src/common.c
index 4a8a38e..e963169 100644
--- a/src/common.c
+++ b/src/common.c
@@ -24,6 +24,9 @@
typedef struct
{
guint ref_count;
+ gboolean closed;
+ GError *error;
+
GIOStream *stream1;
GIOStream *stream2;
@@ -44,8 +47,10 @@ splice_context_unref (SpliceContext *self)
if (--self->ref_count == 0)
{
if (self->callback != NULL)
- self->callback (self->user_data);
+ self->callback (self->stream1, self->stream2, self->error,
+ self->user_data);
+ g_clear_error (&self->error);
g_object_unref (self->stream1);
g_object_unref (self->stream2);
@@ -54,8 +59,15 @@ splice_context_unref (SpliceContext *self)
}
static void
-splice_context_close (SpliceContext *self)
+splice_context_close (SpliceContext *self, const GError *error)
{
+ if (self->closed)
+ return;
+ self->closed = TRUE;
+
+ if (error != NULL)
+ self->error = g_error_copy (error);
+
g_io_stream_close (self->stream1, NULL, NULL);
g_io_stream_close (self->stream2, NULL, NULL);
}
@@ -66,9 +78,14 @@ splice_cb (GObject *ostream,
gpointer user_data)
{
SpliceContext *ctx = user_data;
+ GError *error = NULL;
- splice_context_close (ctx);
+ g_output_stream_splice_finish (G_OUTPUT_STREAM (ostream), res, &error);
+
+ splice_context_close (ctx, error);
splice_context_unref (ctx);
+
+ g_clear_error (&error);
}
void
diff --git a/src/common.h b/src/common.h
index 5903bf9..2773c01 100644
--- a/src/common.h
+++ b/src/common.h
@@ -24,7 +24,8 @@
G_BEGIN_DECLS
-typedef void (*_GIOStreamSpliceCallback) (gpointer user_data);
+typedef void (*_GIOStreamSpliceCallback) (GIOStream *stream1,
+ GIOStream *stream2, const GError *error, gpointer user_data);
void _g_io_stream_splice (GIOStream *stream1, GIOStream *stream2,
_GIOStreamSpliceCallback callback, gpointer user_data);
diff --git a/src/service.c b/src/service.c
index 18b26d7..b0f307a 100644
--- a/src/service.c
+++ b/src/service.c
@@ -39,9 +39,14 @@ throw_error (const GError *error)
}
static void
-splice_cb (gpointer user_data)
+splice_cb (GIOStream *stream1,
+ GIOStream *stream2,
+ const GError *error,
+ gpointer user_data)
{
- if (--n_sessions == 0)
+ if (error != NULL)
+ throw_error (error);
+ else if (--n_sessions == 0)
g_main_loop_quit (loop);
}