Code

frontend: Always reset the current command after handling it.
authorSebastian Harl <sh@tokkee.org>
Wed, 23 Apr 2014 21:08:19 +0000 (23:08 +0200)
committerSebastian Harl <sh@tokkee.org>
Wed, 23 Apr 2014 21:08:19 +0000 (23:08 +0200)
That is, also reset it after an authentication error.

src/frontend/connection.c

index 6b785392a1255311d5fae116a1bfb334186534db..b4f170bb1d759c2289148d2ce31e8006277110eb 100644 (file)
@@ -267,10 +267,6 @@ command_handle(sdb_conn_t *conn)
                const char *errmsg = "Authentication required";
                sdb_connection_send(conn, CONNECTION_ERROR,
                                (uint32_t)strlen(errmsg), errmsg);
-
-               /* remove the command from the buffer */
-               if (conn->cmd_len)
-                       sdb_strbuf_skip(conn->buf, 0, conn->cmd_len);
                return -1;
        }
 
@@ -363,12 +359,6 @@ command_handle(sdb_conn_t *conn)
                sdb_connection_send(conn, CONNECTION_ERROR,
                                (uint32_t)sdb_strbuf_len(conn->errbuf),
                                sdb_strbuf_string(conn->errbuf));
-
-       /* remove the command from the buffer */
-       if (conn->cmd_len)
-               sdb_strbuf_skip(conn->buf, 0, conn->cmd_len);
-       conn->cmd = CONNECTION_IDLE;
-       conn->cmd_len = 0;
        return status;
 } /* command_handle */
 
@@ -472,9 +462,16 @@ sdb_connection_read(sdb_conn_t *conn)
                                && (sdb_strbuf_len(conn->buf) >= 2 * sizeof(int32_t)))
                        command_init(conn);
                if ((conn->cmd != CONNECTION_IDLE)
-                               && (sdb_strbuf_len(conn->buf) >= conn->cmd_len))
+                               && (sdb_strbuf_len(conn->buf) >= conn->cmd_len)) {
                        command_handle(conn);
 
+                       /* remove the command from the buffer */
+                       if (conn->cmd_len)
+                               sdb_strbuf_skip(conn->buf, 0, conn->cmd_len);
+                       conn->cmd = CONNECTION_IDLE;
+                       conn->cmd_len = 0;
+               }
+
                if (status <= 0)
                        break;