[Spice-devel] [spice-gtk v3 3/6] spice_channel_read_wire: prefer while(TRUE) instead of goto

Victor Toso victortoso at redhat.com
Tue Feb 28 11:21:48 UTC 2017


From: Victor Toso <me at victortoso.com>

Although this should be a single loop iteration [based on the
implementation of g_coroutine_socket_wait()], using goto to reiterate
in the code should be avoided.

This patch changes:
 * The reread label with a while(TRUE);
 * The goto keyword with continue;

All other changes are only related to new indentation.

Signed-off-by: Victor Toso <victortoso at redhat.com>
---
 src/spice-channel.c | 35 ++++++++++++++++++-----------------
 1 file changed, 18 insertions(+), 17 deletions(-)

diff --git a/src/spice-channel.c b/src/spice-channel.c
index 999c615..f2d1b8a 100644
--- a/src/spice-channel.c
+++ b/src/spice-channel.c
@@ -1051,29 +1051,30 @@ static int spice_channel_read_wire(SpiceChannel *channel, void *data, size_t len
     GIOCondition cond;
     gssize ret;
 
-reread:
+    while (TRUE) {
 
-    if (c->has_error) return 0; /* has_error is set by disconnect(), return no error */
+        if (c->has_error) return 0; /* has_error is set by disconnect(), return no error */
 
-    ret = spice_channel_read_wire_nonblocking(channel, data, len, &cond);
+        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);
-            goto reread;
-        } else {
+        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) {
+            CHANNEL_DEBUG(channel, "Closing the connection: spice_channel_read() - ret=0");
             c->has_error = TRUE;
-            return -errno;
+            return 0;
         }
-    }
-    if (ret == 0) {
-        CHANNEL_DEBUG(channel, "Closing the connection: spice_channel_read() - ret=0");
-        c->has_error = TRUE;
-        return 0;
-    }
 
-    return ret;
+        return ret;
+    }
 }
 
 #ifdef HAVE_SASL
-- 
2.9.3



More information about the Spice-devel mailing list