From: Alexander Larsson Date: Mon, 23 Nov 2009 14:02:50 +0000 (+0100) Subject: Add g_output_stream_is_closing X-Git-Url: http://git.openbox.org/?a=commitdiff_plain;h=afe3324fcac8ea2a6b6007c938d7974aa923c0d3;p=dana%2Fcg-glib.git Add g_output_stream_is_closing Need this to check how we're flushing when closing a converter output stream. --- diff --git a/gio/goutputstream.c b/gio/goutputstream.c index 3406b291..38d5419c 100644 --- a/gio/goutputstream.c +++ b/gio/goutputstream.c @@ -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, @@ -1041,6 +1047,27 @@ g_output_stream_is_closed (GOutputStream *stream) return stream->priv->closed; } +/** + * 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. diff --git a/gio/goutputstream.h b/gio/goutputstream.h index e9f31601..e28bded8 100644 --- a/gio/goutputstream.h +++ b/gio/goutputstream.h @@ -195,6 +195,7 @@ gboolean g_output_stream_close_finish (GOutputStream *stream, GError **error); gboolean g_output_stream_is_closed (GOutputStream *stream); +gboolean g_output_stream_is_closing (GOutputStream *stream); gboolean g_output_stream_has_pending (GOutputStream *stream); gboolean g_output_stream_set_pending (GOutputStream *stream, GError **error);