X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=gio%2Fgiostream.c;h=cd177acf0faa0a040c886fdf1728fdb13eb3a956;hb=7fd6f07d498063470903a886b4805a13bd333908;hp=49bca9bad70b2c436a02a2d052a82c89d638824b;hpb=669505e354a843efb2e198d4b56e310fa6a69b9a;p=platform%2Fupstream%2Fglib.git diff --git a/gio/giostream.c b/gio/giostream.c index 49bca9b..cd177ac 100644 --- a/gio/giostream.c +++ b/gio/giostream.c @@ -14,9 +14,7 @@ * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General - * Public License along with this library; if not, write to the - * Free Software Foundation, Inc., 59 Temple Place, Suite 330, - * Boston, MA 02111-1307, USA. + * Public License along with this library; if not, see . * * Authors: Ryan Lortie * Alexander Larsson @@ -30,8 +28,6 @@ #include "gasyncresult.h" #include "gtask.h" -G_DEFINE_ABSTRACT_TYPE (GIOStream, g_io_stream, G_TYPE_OBJECT); - /** * SECTION:giostream * @short_description: Base class for implementing read/write streams @@ -59,9 +55,9 @@ G_DEFINE_ABSTRACT_TYPE (GIOStream, g_io_stream, G_TYPE_OBJECT); * To close a stream use g_io_stream_close() which will close the common * stream object and also the individual substreams. You can also close * the substreams themselves. In most cases this only marks the - * substream as closed, so further I/O on it fails. However, some streams - * may support "half-closed" states where one direction of the stream - * is actually shut down. + * substream as closed, so further I/O on it fails but common state in the + * #GIOStream may still be open. However, some streams may support + * "half-closed" states where one direction of the stream is actually shut down. * * Since: 2.22 */ @@ -77,7 +73,6 @@ enum struct _GIOStreamPrivate { guint closed : 1; guint pending : 1; - GAsyncReadyCallback outstanding_callback; }; static gboolean g_io_stream_real_close (GIOStream *stream, @@ -92,11 +87,7 @@ static gboolean g_io_stream_real_close_finish (GIOStream *stream, GAsyncResult *result, GError **error); -static void -g_io_stream_finalize (GObject *object) -{ - G_OBJECT_CLASS (g_io_stream_parent_class)->finalize (object); -} +G_DEFINE_ABSTRACT_TYPE_WITH_PRIVATE (GIOStream, g_io_stream, G_TYPE_OBJECT) static void g_io_stream_dispose (GObject *object) @@ -114,9 +105,7 @@ g_io_stream_dispose (GObject *object) static void g_io_stream_init (GIOStream *stream) { - stream->priv = G_TYPE_INSTANCE_GET_PRIVATE (stream, - G_TYPE_IO_STREAM, - GIOStreamPrivate); + stream->priv = g_io_stream_get_instance_private (stream); } static void @@ -151,9 +140,6 @@ g_io_stream_class_init (GIOStreamClass *klass) { GObjectClass *gobject_class = G_OBJECT_CLASS (klass); - g_type_class_add_private (klass, sizeof (GIOStreamPrivate)); - - gobject_class->finalize = g_io_stream_finalize; gobject_class->dispose = g_io_stream_dispose; gobject_class->get_property = g_io_stream_get_property; @@ -275,7 +261,7 @@ g_io_stream_has_pending (GIOStream *stream) * already set or @stream is closed, it will return %FALSE and set * @error. * - * Return value: %TRUE if pending was previously unset and is now set. + * Returns: %TRUE if pending was previously unset and is now set. * * Since: 2.22 */ @@ -383,7 +369,7 @@ g_io_stream_real_close (GIOStream *stream, * The default implementation of this method just calls close on the * individual input/output streams. * - * Return value: %TRUE on success, %FALSE on failure + * Returns: %TRUE on success, %FALSE on failure * * Since: 2.22 */ @@ -427,12 +413,25 @@ async_ready_close_callback_wrapper (GObject *source_object, gpointer user_data) { GIOStream *stream = G_IO_STREAM (source_object); + GIOStreamClass *klass = G_IO_STREAM_GET_CLASS (stream); + GTask *task = user_data; + GError *error = NULL; + gboolean success; stream->priv->closed = TRUE; g_io_stream_clear_pending (stream); - if (stream->priv->outstanding_callback) - (*stream->priv->outstanding_callback) (source_object, res, user_data); - g_object_unref (stream); + + if (g_async_result_legacy_propagate_error (res, &error)) + success = FALSE; + else + success = klass->close_finish (stream, res, &error); + + if (error) + g_task_return_error (task, error); + else + g_task_return_boolean (task, success); + + g_object_unref (task); } /** @@ -465,15 +464,14 @@ g_io_stream_close_async (GIOStream *stream, { GIOStreamClass *class; GError *error = NULL; + GTask *task; g_return_if_fail (G_IS_IO_STREAM (stream)); + task = g_task_new (stream, cancellable, callback, user_data); + if (stream->priv->closed) { - GTask *task; - - task = g_task_new (stream, cancellable, callback, user_data); - g_task_set_source_tag (task, g_io_stream_close_async); g_task_return_boolean (task, TRUE); g_object_unref (task); return; @@ -481,17 +479,15 @@ g_io_stream_close_async (GIOStream *stream, if (!g_io_stream_set_pending (stream, &error)) { - g_task_report_error (stream, callback, user_data, - g_io_stream_close_async, - error); + g_task_return_error (task, error); + g_object_unref (task); return; } class = G_IO_STREAM_GET_CLASS (stream); - stream->priv->outstanding_callback = callback; - g_object_ref (stream); + class->close_async (stream, io_priority, cancellable, - async_ready_close_callback_wrapper, user_data); + async_ready_close_callback_wrapper, task); } /** @@ -512,18 +508,10 @@ g_io_stream_close_finish (GIOStream *stream, GAsyncResult *result, GError **error) { - GIOStreamClass *class; - g_return_val_if_fail (G_IS_IO_STREAM (stream), FALSE); - g_return_val_if_fail (G_IS_ASYNC_RESULT (result), FALSE); - - if (g_async_result_legacy_propagate_error (result, error)) - return FALSE; - else if (g_async_result_is_tagged (result, g_io_stream_close_async)) - return g_task_propagate_boolean (G_TASK (result), error); + g_return_val_if_fail (g_task_is_valid (result, stream), FALSE); - class = G_IO_STREAM_GET_CLASS (stream); - return class->close_finish (stream, result, error); + return g_task_propagate_boolean (G_TASK (result), error); }