diff options
Diffstat (limited to 'acccre-server.c')
-rw-r--r-- | acccre-server.c | 22 |
1 files changed, 15 insertions, 7 deletions
diff --git a/acccre-server.c b/acccre-server.c index a3c1896..a645b93 100644 --- a/acccre-server.c +++ b/acccre-server.c @@ -1,5 +1,6 @@ #ifdef __unix__ #include "acccre-server.h" +#include "acccre-cmdparser.c" #include <memory.h> #include <netdb.h> @@ -10,6 +11,7 @@ #include <signal.h> #include <stdio.h> #include <stdlib.h> +#include <string.h> #include <strings.h> #include <sys/socket.h> #include <sys/types.h> @@ -24,17 +26,21 @@ volatile sig_atomic_t sig_flag = 0; static void sig_handler(int signo) { char *sig_name = strsignal(signo); char *sig_msg = " signal is caught\n"; - write(STDOUT_FILENO, sig_name, strlen(sig_name)); - write(STDOUT_FILENO, sig_msg, strlen(sig_msg)); + char *msg = malloc(strlen(sig_name) + strlen(sig_msg) + 1); + strcat(strcpy(msg, sig_name), sig_msg); + write(STDOUT_FILENO, msg, strlen(msg)); + free(msg); + //write(STDOUT_FILENO, sig_name, strlen(sig_name)); + //write(STDOUT_FILENO, sig_msg, strlen(sig_msg)); sig_flag = 1; } -void *process(void *arg) { +static void *process(void *arg) { int client_fd = *((int *)arg); char *buf = malloc(sizeof(acccre_size_t)); /* TODO: make a protocol */ - while (sig_flag == 0) { + //while (sig_flag == 0) { if (recv(client_fd, buf, sizeof(acccre_size_t), 0) > 0) { /* Now, parse the request... */ acccre_size_t msg_len = *buf; @@ -42,8 +48,10 @@ void *process(void *arg) { buf = realloc(buf, msg_len); recv(client_fd, buf, msg_len, 0); - char *msg = buf; - printf("%s\n", msg); + + int response = parse(buf); + send(client_fd, &response, sizeof(response), 0); + /* printf("%s\n", msg); */ /* ... char *response = (char *)malloc(BUFFER_SIZE * sizeof(char)); @@ -52,7 +60,7 @@ void *process(void *arg) { size_t response_len;*/ /* ... */ } - } + //} close(client_fd); free(arg); |