From 38a708d712ac0e4de03fdb87854f6deabdb581ba Mon Sep 17 00:00:00 2001 From: buffet Date: Thu, 18 Oct 2018 22:20:17 +0200 Subject: [PATCH] Read message --- src/kiwmi/main.c | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/src/kiwmi/main.c b/src/kiwmi/main.c index 422056c..857c012 100644 --- a/src/kiwmi/main.c +++ b/src/kiwmi/main.c @@ -6,6 +6,7 @@ #include #include #include +#include #include #include @@ -84,7 +85,18 @@ main(int argc, char *argv[]) select(max_fd, &file_descriptors, NULL, NULL, NULL); if (FD_ISSET(g_sock_fd, &file_descriptors)) { - // TODO: handle client event + int client_fd; + char msg[BUFSIZ]; + int msg_len; + + client_fd = accept(g_sock_fd, NULL, 0); + + if (!(client_fd < 0) && (msg_len = read(client_fd, msg, sizeof(msg))) > 0) { + // client sent something + msg[msg_len] = '\0'; + // TODO: handle event + close(client_fd); + } } } }