<div dir="ltr"><br><div class="gmail_extra"><br><div class="gmail_quote">On Wed, Jun 3, 2015 at 11:33 AM, Victor Toso <span dir="ltr"><<a href="mailto:victortoso@redhat.com" target="_blank">victortoso@redhat.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><span class="">PipeInputStream and PipeOutputStream should not fail when creating<br>
GPollableStream source as this currently does not work with default<br>
write_all and read_all functions;<br>
<br>
In order to avoid creating zombie GSource in create_source of both<br>
PipeInputStream and PipeOutputStream, we track all created GSources and<br>
set them to be dispatched when data is available to read/write. It is<br>
worth to mention that concurrent write/read is not possible with current<br>
giopipe and only the last created GSource will read the data as it is<br>
dispatched first.<br>
---<br>
</span> gtk/giopipe.c | 63 +++++++++++++++++++++++++++++++----------------------------<br>
1 file changed, 33 insertions(+), 30 deletions(-)<br>
<br>
diff --git a/gtk/giopipe.c b/gtk/giopipe.c<br>
index 50edb5b..a96783f 100644<br>
<span class="">--- a/gtk/giopipe.c<br>
+++ b/gtk/giopipe.c<br>
@@ -44,7 +44,7 @@ struct _PipeInputStream<br>
* closing.<br>
*/<br>
gboolean peer_closed;<br>
- GSource *source;<br>
+ GList *sources;<br>
};<br>
<br>
struct _PipeInputStreamClass<br>
@@ -69,7 +69,7 @@ struct _PipeOutputStream<br>
const gchar *buffer;<br>
gsize count;<br>
gboolean peer_closed;<br>
- GSource *source;<br>
+ GList *sources;<br>
};<br>
<br>
struct _PipeOutputStreamClass<br>
</span>@@ -120,12 +120,32 @@ pipe_input_stream_read (GInputStream *stream,<br>
<div><div class="h5"> return count;<br>
}<br>
<br>
+static GList *<br>
+set_all_sources_ready (GList *sources)<br>
+{<br>
+ GList *it = sources;<br>
+ while (it != NULL) {<br>
+ GSource *s = it->data;<br>
+ GList *next = it->next;<br>
+<br>
+ if (s == NULL || g_source_is_destroyed(s)) {<br>
+ /* remove */<br>
+ sources = g_list_delete_link(sources, it);<br>
+ g_clear_pointer(&s, g_source_unref);<br></div></div></blockquote><div><br></div><div>I'd just use g_source_unref() here.<br></div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div><div class="h5">
+ } else {<br>
+ /* dispatch */<br>
+ g_source_set_ready_time(s, 0);<br>
+ }<br>
+ it = next;<br>
+ }<br>
+ return sources;<br>
+}<br>
+<br>
static void<br>
pipe_input_stream_check_source (PipeInputStream *self)<br>
{<br>
- if (self->source && !g_source_is_destroyed(self->source) &&<br>
- g_pollable_input_stream_is_readable(G_POLLABLE_INPUT_STREAM(self)))<br>
- g_source_set_ready_time(self->source, 0);<br>
</div></div><span class="">+ if (g_pollable_input_stream_is_readable(G_POLLABLE_INPUT_STREAM(self)))<br>
+ self->sources = set_all_sources_ready(self->sources);<br>
}<br>
<br>
static gboolean<br>
</span>@@ -193,10 +213,8 @@ pipe_input_stream_dispose(GObject *object)<br>
<span class=""> self->peer = NULL;<br>
}<br>
<br>
- if (self->source) {<br>
- g_source_unref(self->source);<br>
- self->source = NULL;<br>
- }<br>
+ g_list_free_full (self->sources, (GDestroyNotify) g_source_unref);<br>
+ self->sources = NULL;<br>
<br>
G_OBJECT_CLASS(pipe_input_stream_parent_class)->dispose (object);<br>
}<br>
</span>@@ -234,14 +252,8 @@ pipe_input_stream_create_source (GPollableInputStream *stream,<br>
<span class=""> PipeInputStream *self = PIPE_INPUT_STREAM(stream);<br>
GSource *pollable_source;<br>
<br>
- g_return_val_if_fail (self->source == NULL ||<br>
- g_source_is_destroyed (self->source), NULL);<br>
-<br>
- if (self->source && g_source_is_destroyed (self->source))<br>
- g_source_unref (self->source);<br>
-<br>
pollable_source = g_pollable_source_new_full (self, NULL, cancellable);<br>
- self->source = g_source_ref (pollable_source);<br>
+ self->sources = g_list_prepend (self->sources, g_source_ref (pollable_source));<br>
<br>
return pollable_source;<br>
}<br>
</span>@@ -319,10 +331,8 @@ pipe_output_stream_dispose(GObject *object)<br>
<span class=""> self->peer = NULL;<br>
}<br>
<br>
- if (self->source) {<br>
- g_source_unref(self->source);<br>
- self->source = NULL;<br>
- }<br>
+ g_list_free_full (self->sources, (GDestroyNotify) g_source_unref);<br>
+ self->sources = NULL;<br>
<br>
G_OBJECT_CLASS(pipe_output_stream_parent_class)->dispose (object);<br>
}<br>
</span>@@ -330,9 +340,8 @@ pipe_output_stream_dispose(GObject *object)<br>
<span class=""> static void<br>
pipe_output_stream_check_source (PipeOutputStream *self)<br>
{<br>
- if (self->source && !g_source_is_destroyed(self->source) &&<br>
- g_pollable_output_stream_is_writable(G_POLLABLE_OUTPUT_STREAM(self)))<br>
- g_source_set_ready_time(self->source, 0);<br>
</span><span class="">+ if (g_pollable_output_stream_is_writable(G_POLLABLE_OUTPUT_STREAM(self)))<br>
+ self->sources = set_all_sources_ready(self->sources);<br>
}<br>
<br>
static gboolean<br>
</span>@@ -416,14 +425,8 @@ pipe_output_stream_create_source (GPollableOutputStream *stream,<br>
<div class="HOEnZb"><div class="h5"> PipeOutputStream *self = PIPE_OUTPUT_STREAM(stream);<br>
GSource *pollable_source;<br>
<br>
- g_return_val_if_fail (self->source == NULL ||<br>
- g_source_is_destroyed (self->source), NULL);<br>
-<br>
- if (self->source && g_source_is_destroyed (self->source))<br>
- g_source_unref (self->source);<br>
-<br>
pollable_source = g_pollable_source_new_full (self, NULL, cancellable);<br>
- self->source = g_source_ref (pollable_source);<br>
+ self->sources = g_list_prepend (self->sources, g_source_ref (pollable_source));<br>
<br>
return pollable_source;<br>
}<br>
--<br>
2.4.2<br>
<br>
_______________________________________________<br>
Spice-devel mailing list<br>
<a href="mailto:Spice-devel@lists.freedesktop.org">Spice-devel@lists.freedesktop.org</a><br>
<a href="http://lists.freedesktop.org/mailman/listinfo/spice-devel" target="_blank">http://lists.freedesktop.org/mailman/listinfo/spice-devel</a><br>
</div></div></blockquote></div><br><br clear="all"><br>-- <br><div class="gmail_signature">Marc-André Lureau</div>
</div></div>