+/**
+ * g_output_stream_write_all_finish:
+ * @stream: a #GOutputStream
+ * @result: a #GAsyncResult
+ * @bytes_written: (out): location to store the number of bytes that was written to the stream
+ * @error: a #GError location to store the error occurring, or %NULL to ignore.
+ *
+ * Finishes an asynchronous stream write operation started with
+ * g_output_stream_write_all_async().
+ *
+ * As a special exception to the normal conventions for functions that
+ * use #GError, if this function returns %FALSE (and sets @error) then
+ * @bytes_written will be set to the number of bytes that were
+ * successfully written before the error was encountered. This
+ * functionality is only available from C. If you need it from another
+ * language then you must write your own loop around
+ * g_output_stream_write_async().
+ *
+ * Returns: %TRUE on success, %FALSE if there was an error
+ *
+ * Since: 2.44
+ **/
+gboolean
+g_output_stream_write_all_finish (GOutputStream *stream,
+ GAsyncResult *result,
+ gsize *bytes_written,
+ GError **error)
+{
+ GTask *task;
+
+ g_return_val_if_fail (G_IS_OUTPUT_STREAM (stream), FALSE);
+ g_return_val_if_fail (g_task_is_valid (result, stream), FALSE);
+
+ task = G_TASK (result);
+
+ if (bytes_written)
+ {
+ AsyncWriteAll *data = (AsyncWriteAll *)g_task_get_task_data (task);
+
+ *bytes_written = data->bytes_written;
+ }
+
+ return g_task_propagate_boolean (task, error);
+}
+
+static void
+write_bytes_callback (GObject *stream,
+ GAsyncResult *result,
+ gpointer user_data)
+{
+ GTask *task = user_data;
+ GError *error = NULL;
+ gssize nwrote;
+
+ nwrote = g_output_stream_write_finish (G_OUTPUT_STREAM (stream),
+ result, &error);
+ if (nwrote == -1)
+ g_task_return_error (task, error);
+ else
+ g_task_return_int (task, nwrote);
+ g_object_unref (task);
+}
+
+/**
+ * g_output_stream_write_bytes_async:
+ * @stream: A #GOutputStream.
+ * @bytes: The bytes to write
+ * @io_priority: the io priority of the request.
+ * @cancellable: (allow-none): optional #GCancellable object, %NULL to ignore.
+ * @callback: (scope async): callback to call when the request is satisfied
+ * @user_data: (closure): the data to pass to callback function
+ *
+ * This function is similar to g_output_stream_write_async(), but
+ * takes a #GBytes as input. Due to the refcounted nature of #GBytes,
+ * this allows the stream to avoid taking a copy of the data.
+ *
+ * However, note that this function may still perform partial writes,
+ * just like g_output_stream_write_async(). If that occurs, to continue
+ * writing, you will need to create a new #GBytes containing just the
+ * remaining bytes, using g_bytes_new_from_bytes(). Passing the same
+ * #GBytes instance multiple times potentially can result in duplicated
+ * data in the output stream.
+ *
+ * For the synchronous, blocking version of this function, see
+ * g_output_stream_write_bytes().
+ **/
+void
+g_output_stream_write_bytes_async (GOutputStream *stream,
+ GBytes *bytes,
+ int io_priority,
+ GCancellable *cancellable,
+ GAsyncReadyCallback callback,
+ gpointer user_data)
+{
+ GTask *task;
+ gsize size;
+ gconstpointer data;
+
+ data = g_bytes_get_data (bytes, &size);
+
+ task = g_task_new (stream, cancellable, callback, user_data);
+ g_task_set_task_data (task, g_bytes_ref (bytes),
+ (GDestroyNotify) g_bytes_unref);
+
+ g_output_stream_write_async (stream,
+ data, size,
+ io_priority,
+ cancellable,
+ write_bytes_callback,
+ task);
+}
+
+/**
+ * g_output_stream_write_bytes_finish:
+ * @stream: a #GOutputStream.
+ * @result: a #GAsyncResult.
+ * @error: a #GError location to store the error occurring, or %NULL to
+ * ignore.
+ *
+ * Finishes a stream write-from-#GBytes operation.
+ *
+ * Returns: a #gssize containing the number of bytes written to the stream.
+ **/
+gssize
+g_output_stream_write_bytes_finish (GOutputStream *stream,
+ GAsyncResult *result,
+ GError **error)
+{
+ g_return_val_if_fail (G_IS_OUTPUT_STREAM (stream), -1);
+ g_return_val_if_fail (g_task_is_valid (result, stream), -1);
+
+ return g_task_propagate_int (G_TASK (result), error);
+}
+
+static void
+async_ready_splice_callback_wrapper (GObject *source_object,
+ GAsyncResult *res,
+ gpointer _data)
+{
+ GOutputStream *stream = G_OUTPUT_STREAM (source_object);
+ GOutputStreamClass *class;
+ GTask *task = _data;
+ gssize nspliced;
+ GError *error = NULL;
+
+ g_output_stream_clear_pending (stream);
+
+ if (g_async_result_legacy_propagate_error (res, &error))
+ nspliced = -1;
+ else
+ {
+ class = G_OUTPUT_STREAM_GET_CLASS (stream);
+ nspliced = class->splice_finish (stream, res, &error);
+ }
+
+ if (nspliced >= 0)
+ g_task_return_int (task, nspliced);
+ else
+ g_task_return_error (task, error);
+ g_object_unref (task);
+}
+
+/**
+ * g_output_stream_splice_async:
+ * @stream: a #GOutputStream.
+ * @source: a #GInputStream.
+ * @flags: a set of #GOutputStreamSpliceFlags.
+ * @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.
+ *
+ * Splices a stream asynchronously.
+ * When the operation is finished @callback will be called.
+ * You can then call g_output_stream_splice_finish() to get the
+ * result of the operation.
+ *
+ * For the synchronous, blocking version of this function, see
+ * g_output_stream_splice().
+ **/
+void
+g_output_stream_splice_async (GOutputStream *stream,
+ GInputStream *source,
+ GOutputStreamSpliceFlags flags,
+ int io_priority,
+ GCancellable *cancellable,
+ GAsyncReadyCallback callback,
+ gpointer user_data)
+{
+ GOutputStreamClass *class;
+ GTask *task;
+ GError *error = NULL;
+
+ g_return_if_fail (G_IS_OUTPUT_STREAM (stream));
+ g_return_if_fail (G_IS_INPUT_STREAM (source));
+
+ task = g_task_new (stream, cancellable, callback, user_data);
+ g_task_set_source_tag (task, g_output_stream_splice_async);
+ g_task_set_priority (task, io_priority);
+ g_task_set_task_data (task, g_object_ref (source), g_object_unref);