+static void
+splice_cancelled_cb (GCancellable *cancellable,
+ GTask *task)
+{
+ SpliceContext *ctx;
+
+ ctx = g_task_get_task_data (task);
+ g_cancellable_cancel (ctx->op1_cancellable);
+ g_cancellable_cancel (ctx->op2_cancellable);
+}
+
+/**
+ * g_io_stream_splice_async:
+ * @stream1: a #GIOStream.
+ * @stream2: a #GIOStream.
+ * @flags: a set of #GIOStreamSpliceFlags.
+ * @io_priority: the io priority of the request.
+ * @cancellable: (allow-none): optional #GCancellable object, %NULL to ignore.
+ * @callback: (scope async): a #GAsyncReadyCallback.
+ * @user_data: (closure): user data passed to @callback.
+ *
+ * Asyncronously splice the output stream of @stream1 to the input stream of
+ * @stream2, and splice the output stream of @stream2 to the input stream of
+ * @stream1.
+ *
+ * When the operation is finished @callback will be called.
+ * You can then call g_io_stream_splice_finish() to get the
+ * result of the operation.
+ *
+ * Since: 2.28
+ **/
+void
+g_io_stream_splice_async (GIOStream *stream1,
+ GIOStream *stream2,
+ GIOStreamSpliceFlags flags,
+ gint io_priority,
+ GCancellable *cancellable,
+ GAsyncReadyCallback callback,
+ gpointer user_data)
+{
+ GTask *task;
+ SpliceContext *ctx;
+ GInputStream *istream;
+ GOutputStream *ostream;
+
+ if (cancellable != NULL && g_cancellable_is_cancelled (cancellable))
+ {
+ g_task_report_new_error (NULL, callback, user_data,
+ g_io_stream_splice_async,
+ G_IO_ERROR, G_IO_ERROR_CANCELLED,
+ "Operation has been cancelled");
+ return;
+ }
+
+ ctx = g_slice_new0 (SpliceContext);
+ ctx->stream1 = g_object_ref (stream1);
+ ctx->stream2 = g_object_ref (stream2);
+ ctx->flags = flags;
+ ctx->op1_cancellable = g_cancellable_new ();
+ ctx->op2_cancellable = g_cancellable_new ();
+ ctx->completed = 0;
+
+ task = g_task_new (NULL, cancellable, callback, user_data);
+ g_task_set_task_data (task, ctx, (GDestroyNotify) splice_context_free);
+
+ if (cancellable != NULL)
+ {
+ ctx->cancellable = g_object_ref (cancellable);
+ ctx->cancelled_id = g_cancellable_connect (cancellable,
+ G_CALLBACK (splice_cancelled_cb), g_object_ref (task),
+ g_object_unref);
+ }
+
+ istream = g_io_stream_get_input_stream (stream1);
+ ostream = g_io_stream_get_output_stream (stream2);
+ g_output_stream_splice_async (ostream, istream, G_OUTPUT_STREAM_SPLICE_NONE,
+ io_priority, ctx->op1_cancellable, splice_cb,
+ g_object_ref (task));
+
+ istream = g_io_stream_get_input_stream (stream2);
+ ostream = g_io_stream_get_output_stream (stream1);
+ g_output_stream_splice_async (ostream, istream, G_OUTPUT_STREAM_SPLICE_NONE,
+ io_priority, ctx->op2_cancellable, splice_cb,
+ g_object_ref (task));
+
+ g_object_unref (task);
+}
+
+/**
+ * g_io_stream_splice_finish:
+ * @result: a #GAsyncResult.
+ * @error: a #GError location to store the error occurring, or %NULL to
+ * ignore.
+ *
+ * Finishes an asynchronous io stream splice operation.
+ *
+ * Returns: %TRUE on success, %FALSE otherwise.
+ *
+ * Since: 2.28
+ **/
+gboolean
+g_io_stream_splice_finish (GAsyncResult *result,
+ GError **error)
+{
+ g_return_val_if_fail (g_task_is_valid (result, NULL), FALSE);
+
+ return g_task_propagate_boolean (G_TASK (result), error);
+}