[Spice-devel] [PATCH spice-server 22/30] Group common error code

Frediano Ziglio fziglio at redhat.com
Mon Nov 21 12:52:09 UTC 2016


---
 server/websocket.c | 25 +++++++++++--------------
 1 file changed, 11 insertions(+), 14 deletions(-)

diff --git a/server/websocket.c b/server/websocket.c
index 99d7fb4..09d72c8 100644
--- a/server/websocket.c
+++ b/server/websocket.c
@@ -261,13 +261,7 @@ int websocket_read(RedsWebSocket *ws, guchar *buf, size_t size)
         if (!frame->frame_ready) {
             rc = read_cb(ws->raw_stream, frame->header + frame->header_pos, frame_bytes_needed(frame));
             if (rc <= 0) {
-                if (n > 0 && rc == -1 && (errno == EINTR || errno == EAGAIN)) {
-                    return n;
-                }
-                if (rc == 0) {
-                    ws->closed = TRUE;
-                }
-                return rc;
+                goto read_error;
             }
             frame->header_pos += rc;
 
@@ -280,13 +274,7 @@ int websocket_read(RedsWebSocket *ws, guchar *buf, size_t size)
         } else if (frame->type == BINARY_FRAME) {
             rc = read_cb(opaque, buf, MIN(size, frame->expected_len - frame->relayed));
             if (rc <= 0) {
-                if (n > 0 && rc == -1 && (errno == EINTR || errno == EAGAIN)) {
-                    return n;
-                }
-                if (rc == 0) {
-                    ws->closed = TRUE;
-                }
-                return rc;
+                goto read_error;
             }
 
             rc = relay_data(buf, rc, frame);
@@ -305,6 +293,15 @@ int websocket_read(RedsWebSocket *ws, guchar *buf, size_t size)
     }
 
     return n;
+
+read_error:
+    if (n > 0 && rc == -1 && (errno == EINTR || errno == EAGAIN)) {
+        return n;
+    }
+    if (rc == 0) {
+        ws->closed = TRUE;
+    }
+    return rc;
 }
 
 static int fill_header(guint8 *header, guint64 len)
-- 
2.7.4



More information about the Spice-devel mailing list