Code

frontend/connection: Try to handle as much as possible in read().
authorSebastian Harl <sh@tokkee.org>
Mon, 11 Nov 2013 08:18:13 +0000 (09:18 +0100)
committerSebastian Harl <sh@tokkee.org>
Mon, 11 Nov 2013 08:18:13 +0000 (09:18 +0100)
Else, we might have to wait for more data before being able to process a
command.

src/frontend/connection.c

index 028f3776966b233ec2371b52653f10ce1752c5c0..75ac8c91c845af15dd89efd74fd5778b82821268 100644 (file)
@@ -111,15 +111,17 @@ sdb_connection_read(sdb_conn_t *conn)
 
        while (42) {
                ssize_t status = connection_read(conn);
+
+               if ((! conn->cmd) && (! conn->cmd_len)
+                               && (sdb_strbuf_len(conn->buf) >= 2 * sizeof(int32_t)))
+                       command_init(conn);
+               if (conn->cmd_len && (sdb_strbuf_len(conn->buf) >= conn->cmd_len))
+                       command_handle(conn);
+
                if (status <= 0)
                        break;
 
                n += status;
-
-               if (conn->cmd_len && (sdb_strbuf_len(conn->buf) >= conn->cmd_len))
-                       command_handle(conn);
-               else if (sdb_strbuf_len(conn->buf) >= 2 * sizeof(int32_t))
-                       command_init(conn);
        }
        return n;
 } /* sdb_connection_read */