-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 file descriptor: %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;
-}
-