From 6581d7470e7810c18726fa6fb8dde087983b76b9 Mon Sep 17 00:00:00 2001 From: buffet Date: Sat, 13 Apr 2019 15:30:49 +0200 Subject: [PATCH] read first, then do all commands --- kiwmi/frontend.c | 25 +++++++++---------------- 1 file changed, 9 insertions(+), 16 deletions(-) diff --git a/kiwmi/frontend.c b/kiwmi/frontend.c index 1ffa2fa..472c8e8 100644 --- a/kiwmi/frontend.c +++ b/kiwmi/frontend.c @@ -66,10 +66,8 @@ ipc_connection(int fd, uint32_t mask, void *UNUSED(data)) return 0; } - bool is_reading = true; - while (is_reading) { - int c = getc(client_file); - + int c; + while ((c = getc(client_file)) != '\0') { if (msg_len >= buffer_size) { buffer_size *= 2; char *tmp = realloc(msg, buffer_size); @@ -82,18 +80,13 @@ ipc_connection(int fd, uint32_t mask, void *UNUSED(data)) msg = tmp; } - switch (c) { - case '\0': - is_reading = false; - // FALLTHROUGH - case '\n': - msg[msg_len] = '\0'; - msg_len = 0; - // TODO: handle command - break; - default: - msg[msg_len++] = c; - } + msg[msg_len++] = c; + } + + msg[msg_len] = '\0'; + + for (const char *cmd = strtok(msg, "\n"); cmd; cmd = strtok(NULL, "\n")) { + // TODO: handle client command } fclose(client_file);