ready for command handling

This commit is contained in:
buffet 2019-04-12 14:21:08 +02:00
parent 80c1e9c1f9
commit 085b27f0b8

View file

@ -66,8 +66,10 @@ ipc_connection(int fd, uint32_t mask, void *UNUSED(data))
return 0; return 0;
} }
int c; bool is_reading = true;
while ((c = getc(client_file)) != '\0') { while (is_reading) {
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);
@ -80,12 +82,19 @@ ipc_connection(int fd, uint32_t mask, void *UNUSED(data))
msg = tmp; 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';
// TODO: handle properly
fclose(client_file); fclose(client_file);
free(msg); free(msg);