gio: implement GPollableInput/OutputStream in more stream types

Implement GPollableInputStream in GMemoryInputStream and
GConverterInputStream, and likewise implement GPollableOutputStream in
the corresponding output streams.

https://bugzilla.gnome.org/show_bug.cgi?id=673997
This commit is contained in:
Dan Winship
2012-02-06 15:08:08 -05:00
parent 111ba203c2
commit 82ec4dcaed
5 changed files with 508 additions and 36 deletions

View File

@@ -25,6 +25,7 @@
#include "config.h"
#include "gmemoryoutputstream.h"
#include "goutputstream.h"
#include "gpollableoutputstream.h"
#include "gseekable.h"
#include "gsimpleasyncresult.h"
#include "gioerror.h"
@@ -41,6 +42,8 @@
* #GMemoryOutputStream is a class for using arbitrary
* memory chunks as output for GIO streaming output operations.
*
* As of GLib 2.34, #GMemoryOutputStream implements
* #GPollableOutputStream.
*/
#define MIN_ARRAY_SIZE 16
@@ -119,9 +122,17 @@ static gboolean g_memory_output_stream_truncate (GSeekable *see
GCancellable *cancellable,
GError **error);
static gboolean g_memory_output_stream_is_writable (GPollableOutputStream *stream);
static GSource *g_memory_output_stream_create_source (GPollableOutputStream *stream,
GCancellable *cancellable);
static void g_memory_output_stream_pollable_iface_init (GPollableOutputStreamInterface *iface);
G_DEFINE_TYPE_WITH_CODE (GMemoryOutputStream, g_memory_output_stream, G_TYPE_OUTPUT_STREAM,
G_IMPLEMENT_INTERFACE (G_TYPE_SEEKABLE,
g_memory_output_stream_seekable_iface_init))
g_memory_output_stream_seekable_iface_init);
G_IMPLEMENT_INTERFACE (G_TYPE_POLLABLE_OUTPUT_STREAM,
g_memory_output_stream_pollable_iface_init))
static void
@@ -224,6 +235,13 @@ g_memory_output_stream_class_init (GMemoryOutputStreamClass *klass)
G_PARAM_STATIC_STRINGS));
}
static void
g_memory_output_stream_pollable_iface_init (GPollableOutputStreamInterface *iface)
{
iface->is_writable = g_memory_output_stream_is_writable;
iface->create_source = g_memory_output_stream_create_source;
}
static void
g_memory_output_stream_set_property (GObject *object,
guint prop_id,
@@ -800,3 +818,23 @@ g_memory_output_stream_truncate (GSeekable *seekable,
return TRUE;
}
static gboolean
g_memory_output_stream_is_writable (GPollableOutputStream *stream)
{
return TRUE;
}
static GSource *
g_memory_output_stream_create_source (GPollableOutputStream *stream,
GCancellable *cancellable)
{
GSource *base_source, *pollable_source;
base_source = g_timeout_source_new (0);
pollable_source = g_pollable_source_new_full (stream, base_source,
cancellable);
g_source_unref (base_source);
return pollable_source;
}