[glib] GInputStream: fix default g_input_stream_skip_async() logic



commit 1738d5f1ef7ade40445aeb296911f9ef59da8a19
Author: Dan Winship <danw gnome org>
Date:   Sat Jan 12 17:39:37 2013 -0500

    GInputStream: fix default g_input_stream_skip_async() logic
    
    g_input_stream_real_skip_async() wants to use read_async() normally,
    but will use skip() in a thread instead if it sees that read_async()
    will end up using threads. Except that the test for "will read_async()
    use threads" never got updated to know about the GPollableInputStream
    support in read_async(), so it was doing the wrong thing in that case.
    Fix.
    
    Also remove a small bit of pre-GTask cruft noticed nearby.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=691489

 gio/ginputstream.c |   15 ++++++++-------
 1 files changed, 8 insertions(+), 7 deletions(-)
---
diff --git a/gio/ginputstream.c b/gio/ginputstream.c
index 33decd1..f7006cb 100644
--- a/gio/ginputstream.c
+++ b/gio/ginputstream.c
@@ -1136,6 +1136,11 @@ read_async_pollable (GPollableInputStream *stream,
   /* g_input_stream_real_read_async() unrefs task */
 }
 
+#define CAN_DO_NONBLOCKING_READS(stream) \
+  (G_IS_POLLABLE_INPUT_STREAM (stream) && \
+   g_pollable_input_stream_can_poll (G_POLLABLE_INPUT_STREAM (stream)))
+
+
 static void
 g_input_stream_real_read_async (GInputStream        *stream,
 				void                *buffer,
@@ -1155,8 +1160,7 @@ g_input_stream_real_read_async (GInputStream        *stream,
   op->buffer = buffer;
   op->count = count;
 
-  if (G_IS_POLLABLE_INPUT_STREAM (stream) &&
-      g_pollable_input_stream_can_poll (G_POLLABLE_INPUT_STREAM (stream)))
+  if (CAN_DO_NONBLOCKING_READS (stream))
     read_async_pollable (G_POLLABLE_INPUT_STREAM (stream), task);
   else
     g_task_run_in_thread (task, read_async_thread);
@@ -1200,8 +1204,6 @@ typedef struct {
   char buffer[8192];
   gsize count;
   gsize count_skipped;
-  gpointer user_data;
-  GAsyncReadyCallback callback;
 } SkipFallbackAsyncData;
 
 static void
@@ -1266,7 +1268,8 @@ g_input_stream_real_skip_async (GInputStream        *stream,
   task = g_task_new (stream, cancellable, callback, user_data);
   g_task_set_priority (task, io_priority);
 
-  if (class->read_async == g_input_stream_real_read_async)
+  if (class->read_async == g_input_stream_real_read_async &&
+      !CAN_DO_NONBLOCKING_READS (stream))
     {
       /* Read is thread-using async fallback.
        * Make skip use threads too, so that we can use a possible sync skip
@@ -1284,8 +1287,6 @@ g_input_stream_real_skip_async (GInputStream        *stream,
       data = g_new (SkipFallbackAsyncData, 1);
       data->count = count;
       data->count_skipped = 0;
-      data->callback = callback;
-      data->user_data = user_data;
       g_task_set_task_data (task, data, g_free);
       g_task_set_check_cancellable (task, FALSE);
       class->read_async (stream, data->buffer, MIN (8192, count), io_priority, cancellable,



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]