<div dir="ltr"><br><div class="gmail_extra"><br><div class="gmail_quote">On Tue, Jun 2, 2015 at 6:00 PM, 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:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">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>
This patch removes the g_return_val_if_fail but keeps a g_debug in order<br>
to track problems;<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>
 gtk/giopipe.c | 60 +++++++++++++++++++++++++++++++++++++----------------------<br>
 1 file changed, 38 insertions(+), 22 deletions(-)<br>
<br>
diff --git a/gtk/giopipe.c b/gtk/giopipe.c<br>
index 50edb5b..cdfa070 100644<br>
--- a/gtk/giopipe.c<br>
+++ b/gtk/giopipe.c<br>
@@ -45,6 +45,7 @@ struct _PipeInputStream<br>
      */<br>
     gboolean peer_closed;<br>
     GSource *source;<br>
+    GList *created_sources;<br>
 };<br>
<br>
 struct _PipeInputStreamClass<br>
@@ -70,6 +71,7 @@ struct _PipeOutputStream<br>
     gsize count;<br>
     gboolean peer_closed;<br>
     GSource *source;<br>
+    GList *created_sources;<br>
 };<br>
<br>
 struct _PipeOutputStreamClass<br>
@@ -121,11 +123,26 @@ pipe_input_stream_read (GInputStream  *stream,<br>
 }<br>
<br>
 static void<br>
+set_all_sources_ready (GList *sources)<br>
+{<br>
+    GList *it;<br>
+    for (it = sources; it != NULL; it = it->next) {<br>
+        GSource *s = it->data;<br>
+        if (s != NULL && !g_source_is_destroyed(s))<br>
+            g_source_set_ready_time(s, 0);<br>
+    }<br>
+    g_list_free_full (sources, (GDestroyNotify) g_source_unref);<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>
+        g_pollable_input_stream_is_readable(G_POLLABLE_INPUT_STREAM(self))) {<br>
+        set_all_sources_ready(self->created_sources);<br>
+        self->created_sources = NULL;<br>
+        self->source = NULL;<br></blockquote><div><br></div><div>Why do you free the sources? Only the destroyed one should be enough. The rest should still remain "dispatchable" <br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
+    }<br>
 }<br>
<br>
 static gboolean<br>
@@ -193,10 +210,9 @@ pipe_input_stream_dispose(GObject *object)<br>
         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->created_sources, (GDestroyNotify) g_source_unref);<br>
+    self->created_sources = NULL;<br>
+    self->source = NULL;<br>
<br>
     G_OBJECT_CLASS(pipe_input_stream_parent_class)->dispose (object);<br>
 }<br>
@@ -234,14 +250,13 @@ pipe_input_stream_create_source (GPollableInputStream *stream,<br>
     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>
+    if (self->source != NULL && !g_source_is_destroyed (self->source))<br>
+        g_debug ("%s: GPollableSource already exists %p - This could lead to data loss (%ld)",<br>
+                 G_STRFUNC, self->source, self->read);<br></blockquote><div><br></div><div>You may remove this debug now that you track all created sources <br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
<br>
     pollable_source = g_pollable_source_new_full (self, NULL, cancellable);<br>
     self->source = g_source_ref (pollable_source);<br>
+    self->created_sources = g_list_prepend (self->created_sources, self->source);<br></blockquote><div><br></div><div>furthermore, you may just get rid of  self->source, it's just one of the many now. <br><br></div><div>then, I think "created_sources" should be named simply "sources"<br><br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
<br>
     return pollable_source;<br>
 }<br>
@@ -319,10 +334,9 @@ pipe_output_stream_dispose(GObject *object)<br>
         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->created_sources, (GDestroyNotify) g_source_unref);<br>
+    self->created_sources = NULL;<br>
+    self->source = NULL;<br>
<br>
     G_OBJECT_CLASS(pipe_output_stream_parent_class)->dispose (object);<br>
 }<br>
@@ -331,8 +345,11 @@ 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>
+        g_pollable_output_stream_is_writable(G_POLLABLE_OUTPUT_STREAM(self))) {<br>
+        set_all_sources_ready(self->created_sources);<br>
+        self->created_sources = NULL;<br>
+        self->source = NULL;<br>
+    }<br>
 }<br>
<br>
 static gboolean<br>
@@ -416,14 +433,13 @@ pipe_output_stream_create_source (GPollableOutputStream *stream,<br>
     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>
+    if (self->source != NULL && !g_source_is_destroyed (self->source))<br>
+        g_debug ("%s: GPollableSource already exists %p - This could lead to data loss (%ld)",<br>
+                 G_STRFUNC, self->source, self->count);<br>
<br>
     pollable_source = g_pollable_source_new_full (self, NULL, cancellable);<br>
     self->source = g_source_ref (pollable_source);<br>
+    self->created_sources = g_list_prepend (self->created_sources, self->source);<br>
<br></blockquote><div><br></div><div>idem<br> <br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
     return pollable_source;<br>
 }<br>
<span class=""><font color="#888888">--<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-</a></font></span> </blockquote><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><span class=""><font color="#888888"><a href="http://lists.freedesktop.org/mailman/listinfo/spice-devel" target="_blank">devel</a><br>
</font></span></blockquote></div><br>looks good otherwise<br></div><div class="gmail_extra"><br clear="all"><br>-- <br><div class="gmail_signature">Marc-André Lureau</div>
</div></div>