Add g_output_stream_is_closing
[dana/cg-glib.git] / gio / goutputstream.c
index 3406b29..38d5419 100644 (file)
@@ -51,6 +51,7 @@ G_DEFINE_TYPE (GOutputStream, g_output_stream, G_TYPE_OBJECT);
 struct _GOutputStreamPrivate {
   guint closed : 1;
   guint pending : 1;
+  guint closing : 1;
   GAsyncReadyCallback outstanding_callback;
 };
 
@@ -520,6 +521,8 @@ g_output_stream_close (GOutputStream  *stream,
   if (!g_output_stream_set_pending (stream, error))
     return FALSE;
 
+  stream->priv->closing = TRUE;
+
   if (cancellable)
     g_cancellable_push_current (cancellable);
 
@@ -545,7 +548,8 @@ g_output_stream_close (GOutputStream  *stream,
   
   if (cancellable)
     g_cancellable_pop_current (cancellable);
-  
+
+  stream->priv->closing = FALSE;
   stream->priv->closed = TRUE;
   g_output_stream_clear_pending (stream);
   
@@ -572,6 +576,7 @@ async_ready_close_callback_wrapper (GObject      *source_object,
 {
   GOutputStream *stream = G_OUTPUT_STREAM (source_object);
 
+  stream->priv->closing = FALSE;
   stream->priv->closed = TRUE;
   g_output_stream_clear_pending (stream);
   if (stream->priv->outstanding_callback)
@@ -982,6 +987,7 @@ g_output_stream_close_async (GOutputStream       *stream,
     }
   
   class = G_OUTPUT_STREAM_GET_CLASS (stream);
+  stream->priv->closing = TRUE;
   stream->priv->outstanding_callback = callback;
   g_object_ref (stream);
   class->close_async (stream, io_priority, cancellable,
@@ -1042,6 +1048,27 @@ g_output_stream_is_closed (GOutputStream *stream)
 }
 
 /**
+ * g_output_stream_is_closing:
+ * @stream: a #GOutputStream.
+ *
+ * Checks if an output stream is being closed. This can be
+ * used inside e.g. a flush implementation to see if the
+ * flush (or other i/o operation) is called from within
+ * the closing operation.
+ *
+ * Returns: %TRUE if @stream is being closed. %FALSE otherwise.
+ *
+ * Since: 2.24
+ **/
+gboolean
+g_output_stream_is_closing (GOutputStream *stream)
+{
+  g_return_val_if_fail (G_IS_OUTPUT_STREAM (stream), TRUE);
+
+  return stream->priv->closing;
+}
+
+/**
  * g_output_stream_has_pending:
  * @stream: a #GOutputStream.
  *