[Spice-devel] [PATCH spice-gtk 2/6] Make sure spice_channel_iterate_write() always flushes *all* pending writes

Hans de Goede hdegoede at redhat.com
Thu Dec 1 07:48:52 PST 2011


This patch changes 1 line, and fixes 2 bugs in this one line:
1) We keep the xmit_buffer around for reuse (re-filling) later, so checking
   if we've a xmit_buffer to determine wether we should do a write is wrong,
   instead we should check if the xmit_buffer has data in it.
2) If the write blocks, and we switch to another co-routine context, this
   context may queue more writes, we check for this and throw away the
   buffer we've been consuming when this happens, since the other context
   will then have allocated a new buffer. But when this happens, we do *not*
   consume the new buffer. So the queued data will not get transmitted
   until the co-routine gets woken up by either another write, or by
   receiving data to read.
   This patch fixes this by changing the if to a while.

Note that the code in question gets completely removed by the next patch in
this series. As I noticed this while rewriting the code in question, still
I decided to do a separate patch to fix this to:
1) Document this issue in the old code
2) Otherwise the move from the if to the while will happen in the new code
   which may confuse readers of that patch.

Signed-off-by: Hans de Goede <hdegoede at redhat.com>
---
 gtk/spice-channel.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)

diff --git a/gtk/spice-channel.c b/gtk/spice-channel.c
index 7a57630..9e2aee0 100644
--- a/gtk/spice-channel.c
+++ b/gtk/spice-channel.c
@@ -1805,7 +1805,7 @@ static void spice_channel_iterate_write(SpiceChannel *channel)
 {
     SpiceChannelPrivate *c = channel->priv;
 
-    if (c->xmit_buffer) {
+    while (c->xmit_buffer_size) {
         /*
          * Take ownership of the buffer, so that if spice_channel_write calls
          * g_io_wait and thus yields to the main context, and that then calls
-- 
1.7.7.4



More information about the Spice-devel mailing list