[Spice-devel,spice-gtk,v1,4/4] spice-channel: small rework on spice_channel_flush_wire()

Submitted by Victor Toso on Feb. 3, 2017, 2:24 p.m.

Details

Message ID 20170203142451.14104-5-victortoso@redhat.com
State New
Headers show
Series "spice-channel read/flush wire functions" ( rev: 1 ) in Spice

Not browsing as part of any series.

Commit Message

Victor Toso Feb. 3, 2017, 2:24 p.m.
From: Victor Toso <me@victortoso.com>

* Keeping compatibility with spice_channel_read_wire() where we keep
  the possible context switch of g_coroutine_socket_wait() in the end
  of loop and dealing with the return of the _flush_wire_nonblocking()
  case by case.

Signed-off-by: Victor Toso <victortoso@redhat.com>
---
 src/spice-channel.c | 26 ++++++++++++++------------
 1 file changed, 14 insertions(+), 12 deletions(-)

Patch hide | download patch | download mbox

diff --git a/src/spice-channel.c b/src/spice-channel.c
index e3ff75c..310eb7b 100644
--- a/src/spice-channel.c
+++ b/src/spice-channel.c
@@ -832,26 +832,28 @@  static void spice_channel_flush_wire(SpiceChannel *channel,
     while (offset < datalen) {
         gssize ret;
 
-        if (c->has_error) return;
+        if (c->has_error)
+            return;
 
         ret = spice_channel_flush_wire_nonblocking(channel, ptr+offset, datalen-offset, &cond);
-        if (ret == -1) {
-            if (cond != 0) {
-                // TODO: should use g_pollable_input/output_stream_create_source() in 2.28 ?
-                g_coroutine_socket_wait(&c->coroutine, c->sock, cond);
-                continue;
-            } else {
-                CHANNEL_DEBUG(channel, "Closing the channel: spice_channel_flush %d", errno);
-                c->has_error = TRUE;
-                return;
-            }
+        if (ret > 0) {
+            offset += ret;
+            continue;
         }
+
         if (ret == 0) {
             CHANNEL_DEBUG(channel, "Closing the connection: spice_channel_flush");
             c->has_error = TRUE;
             return;
         }
-        offset += ret;
+
+        if (cond == 0) {
+            CHANNEL_DEBUG(channel, "Closing the channel: spice_channel_flush %d", errno);
+            c->has_error = TRUE;
+            return;
+        }
+        // TODO: should use g_pollable_input/output_stream_create_source() in 2.28 ?
+        g_coroutine_socket_wait(&c->coroutine, c->sock, cond);
     }
 }