From: Sebastian Harl Date: Mon, 11 Nov 2013 08:18:13 +0000 (+0100) Subject: frontend/connection: Try to handle as much as possible in read(). X-Git-Tag: sysdb-0.1.0~336^2~14 X-Git-Url: https://git.tokkee.org/?p=sysdb.git;a=commitdiff_plain;h=c6c39d0721a53ee2a85bf1324a4092eea5ba04a3 frontend/connection: Try to handle as much as possible in read(). Else, we might have to wait for more data before being able to process a command. --- diff --git a/src/frontend/connection.c b/src/frontend/connection.c index 028f377..75ac8c9 100644 --- a/src/frontend/connection.c +++ b/src/frontend/connection.c @@ -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 */