read first, then do all commands

This commit is contained in:
buffet 2019-04-13 15:30:49 +02:00
parent 23a7d189f1
commit 8b2d2bcd50

View file

@ -66,10 +66,8 @@ ipc_connection(int fd, uint32_t mask, void *UNUSED(data))
return 0; return 0;
} }
bool is_reading = true; int c;
while (is_reading) { while ((c = getc(client_file)) != '\0') {
int c = getc(client_file);
if (msg_len >= buffer_size) { if (msg_len >= buffer_size) {
buffer_size *= 2; buffer_size *= 2;
char *tmp = realloc(msg, buffer_size); char *tmp = realloc(msg, buffer_size);
@ -82,18 +80,13 @@ ipc_connection(int fd, uint32_t mask, void *UNUSED(data))
msg = tmp; msg = tmp;
} }
switch (c) { msg[msg_len++] = c;
case '\0': }
is_reading = false;
// FALLTHROUGH msg[msg_len] = '\0';
case '\n':
msg[msg_len] = '\0'; for (const char *cmd = strtok(msg, "\n"); cmd; cmd = strtok(NULL, "\n")) {
msg_len = 0; // TODO: handle client command
// TODO: handle command
break;
default:
msg[msg_len++] = c;
}
} }
fclose(client_file); fclose(client_file);