- class->close_async (stream, io_priority, cancellable,
- async_ready_close_callback_wrapper, user_data);
+
+ data = g_slice_new0 (CloseUserData);
+
+ if (cancellable != NULL)
+ data->cancellable = g_object_ref (cancellable);
+
+ data->io_priority = io_priority;
+ data->user_data = user_data;
+
+ /* Call close_async directly if there is no need to flush, or if the flush
+ can be done sync (in the output stream async close thread) */
+ if (class->flush_async == NULL ||
+ (class->flush_async == g_output_stream_real_flush_async &&
+ (class->flush == NULL || class->close_async == g_output_stream_real_close_async)))
+ {
+ class->close_async (stream, io_priority, cancellable,
+ async_ready_close_callback_wrapper, data);
+ }
+ else
+ {
+ /* First do an async flush, then do the async close in the callback
+ wrapper (see async_ready_close_flushed_callback_wrapper) */
+ class->flush_async (stream, io_priority, cancellable,
+ async_ready_close_flushed_callback_wrapper, data);
+ }