From 085b27f0b8580b6e7d9b0cb73dd6382354be2476 Mon Sep 17 00:00:00 2001 From: Charlotte Meyer Date: Fri, 12 Apr 2019 14:21:08 +0200 Subject: [PATCH] ready for command handling --- kiwmi/frontend.c | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/kiwmi/frontend.c b/kiwmi/frontend.c index 86283c7..9b5a846 100644 --- a/kiwmi/frontend.c +++ b/kiwmi/frontend.c @@ -66,8 +66,10 @@ ipc_connection(int fd, uint32_t mask, void *UNUSED(data)) return 0; } - int c; - while ((c = getc(client_file)) != '\0') { + bool is_reading = true; + while (is_reading) { + int c = getc(client_file); + if (msg_len >= buffer_size) { buffer_size *= 2; char *tmp = realloc(msg, buffer_size); @@ -80,13 +82,20 @@ ipc_connection(int fd, uint32_t mask, void *UNUSED(data)) msg = tmp; } - msg[msg_len++] = c; + 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] = '\0'; - - // TODO: handle properly - fclose(client_file); free(msg);