gio: use GPollable* to implement fallback read_async/write_async

If a GInputStream does not provide a read_async() implementation, but
does implement GPollableInputStream, then instead of doing
read-synchronously-in-a-thread, just use
g_pollable_input_stream_read_nonblocking() and
g_pollable_input_stream_create_source() to implement an async read in
the same thread. Similarly for GOutputStream.

Remove a bunch of existing read_async()/write_async() implementations
that are basically equivalent to the new fallback method.

https://bugzilla.gnome.org/show_bug.cgi?id=673997
This commit is contained in:
Dan Winship
2012-02-04 16:46:29 -05:00
parent 82ec4dcaed
commit 00ee06e6a3
10 changed files with 153 additions and 892 deletions

View File

@@ -70,16 +70,6 @@ static gssize g_memory_input_stream_skip (GInputStream *stream
static gboolean g_memory_input_stream_close (GInputStream *stream,
GCancellable *cancellable,
GError **error);
static void g_memory_input_stream_read_async (GInputStream *stream,
void *buffer,
gsize count,
int io_priority,
GCancellable *cancellable,
GAsyncReadyCallback callback,
gpointer user_data);
static gssize g_memory_input_stream_read_finish (GInputStream *stream,
GAsyncResult *result,
GError **error);
static void g_memory_input_stream_skip_async (GInputStream *stream,
gsize count,
int io_priority,
@@ -143,8 +133,6 @@ g_memory_input_stream_class_init (GMemoryInputStreamClass *klass)
istream_class->skip = g_memory_input_stream_skip;
istream_class->close_fn = g_memory_input_stream_close;
istream_class->read_async = g_memory_input_stream_read_async;
istream_class->read_finish = g_memory_input_stream_read_finish;
istream_class->skip_async = g_memory_input_stream_skip_async;
istream_class->skip_finish = g_memory_input_stream_skip_finish;
istream_class->close_async = g_memory_input_stream_close_async;
@@ -352,51 +340,6 @@ g_memory_input_stream_close (GInputStream *stream,
return TRUE;
}
static void
g_memory_input_stream_read_async (GInputStream *stream,
void *buffer,
gsize count,
int io_priority,
GCancellable *cancellable,
GAsyncReadyCallback callback,
gpointer user_data)
{
GSimpleAsyncResult *simple;
GError *error = NULL;
gssize nread;
nread = G_INPUT_STREAM_GET_CLASS (stream)->read_fn (stream,
buffer,
count,
cancellable,
&error);
simple = g_simple_async_result_new (G_OBJECT (stream),
callback,
user_data,
g_memory_input_stream_read_async);
if (error)
g_simple_async_result_take_error (simple, error);
else
g_simple_async_result_set_op_res_gssize (simple, nread);
g_simple_async_result_complete_in_idle (simple);
g_object_unref (simple);
}
static gssize
g_memory_input_stream_read_finish (GInputStream *stream,
GAsyncResult *result,
GError **error)
{
GSimpleAsyncResult *simple;
gssize nread;
simple = G_SIMPLE_ASYNC_RESULT (result);
g_warn_if_fail (g_simple_async_result_get_source_tag (simple) == g_memory_input_stream_read_async);
nread = g_simple_async_result_get_op_res_gssize (simple);
return nread;
}
static void
g_memory_input_stream_skip_async (GInputStream *stream,
gsize count,