- GUnixOutputStream *unix_stream = G_UNIX_OUTPUT_STREAM (stream);
- GSimpleAsyncResult *simple;
- gssize nwritten;
-
- if (!unix_stream->priv->is_pipe_or_socket)
- {
- return G_OUTPUT_STREAM_CLASS (g_unix_output_stream_parent_class)->
- write_finish (stream, result, error);
- }
-
- simple = G_SIMPLE_ASYNC_RESULT (result);
- g_warn_if_fail (g_simple_async_result_get_source_tag (simple) == g_unix_output_stream_write_async);
-
- nwritten = g_simple_async_result_get_op_res_gssize (simple);
- return nwritten;
-}
-
-typedef struct {
- GOutputStream *stream;
- GAsyncReadyCallback callback;
- gpointer user_data;
-} CloseAsyncData;
-
-static gboolean
-close_async_cb (CloseAsyncData *data)
-{
- GUnixOutputStream *unix_stream;
- GSimpleAsyncResult *simple;
- GError *error = NULL;
- gboolean result;
- int res;
-
- unix_stream = G_UNIX_OUTPUT_STREAM (data->stream);
-
- if (!unix_stream->priv->close_fd)
- {
- result = TRUE;
- goto out;
- }
-
- while (1)
- {
- res = close (unix_stream->priv->fd);
- if (res == -1)
- {
- int errsv = errno;
-
- g_set_error (&error, G_IO_ERROR,
- g_io_error_from_errno (errsv),
- _("Error closing unix: %s"),
- g_strerror (errsv));
- }
- break;
- }
-
- result = res != -1;
-
- out:
- simple = g_simple_async_result_new (G_OBJECT (data->stream),
- data->callback,
- data->user_data,
- g_unix_output_stream_close_async);
-
- if (!result)
- g_simple_async_result_take_error (simple, error);
-
- /* Complete immediately, not in idle, since we're already in a mainloop callout */
- g_simple_async_result_complete (simple);
- g_object_unref (simple);
-
- return FALSE;
-}
-
-static void
-g_unix_output_stream_close_async (GOutputStream *stream,
- int io_priority,
- GCancellable *cancellable,
- GAsyncReadyCallback callback,
- gpointer user_data)
-{
- GSource *idle;
- CloseAsyncData *data;