From: Victor Toso <m...@victortoso.com>

Moving all the checks leading to early returns first and let the
situation where we are waiting for data availability to be dealt in
the end as this is the only situation that makes we iterate in the
loop.

Related: https://bugs.freedesktop.org/show_bug.cgi?id=96598
Signed-off-by: Victor Toso <victort...@redhat.com>
---
 src/spice-channel.c | 21 ++++++++-------------
 1 file changed, 8 insertions(+), 13 deletions(-)

diff --git a/src/spice-channel.c b/src/spice-channel.c
index c2e8a01..4a105b0 100644
--- a/src/spice-channel.c
+++ b/src/spice-channel.c
@@ -1059,24 +1059,19 @@ static int spice_channel_read_wire(SpiceChannel 
*channel, void *data, size_t len
         }
 
         ret = spice_channel_read_wire_nonblocking(channel, data, len, &cond);
-
-        if (ret == -1) {
-            if (cond != 0) {
-                // TODO: should use 
g_pollable_input/output_stream_create_source() ?
-                g_coroutine_socket_wait(&c->coroutine, c->sock, cond);
-                continue;
-            } else {
-                c->has_error = TRUE;
-                return -errno;
-            }
-        }
-        if (ret == 0) {
+        if (ret > 0) {
+            return ret;
+        } else if (ret == 0) {
             CHANNEL_DEBUG(channel, "Closing the connection: 
spice_channel_read() - ret=0");
             c->has_error = TRUE;
             return 0;
+        } else if (cond == 0) {
+            c->has_error = TRUE;
+            return -errno;
         }
 
-        return ret;
+        // TODO: should use g_pollable_input/output_stream_create_source() ?
+        g_coroutine_socket_wait(&c->coroutine, c->sock, cond);
     }
 }
 
-- 
2.9.3

_______________________________________________
Spice-devel mailing list
Spice-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/spice-devel

Reply via email to