From f132844419b4dd943b07967945f30eebcb780d60 Mon Sep 17 00:00:00 2001 From: ENGO150 Date: Thu, 9 Feb 2023 19:18:46 +0100 Subject: [PATCH] implemented why2_die in chat-server --- src/chat/server/main.c | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/src/chat/server/main.c b/src/chat/server/main.c index ec0bfb4..7e03f28 100644 --- a/src/chat/server/main.c +++ b/src/chat/server/main.c @@ -18,7 +18,6 @@ along with this program. If not, see . #include -void die(char *exit_message); char *read_socket(int socket); int main(void) @@ -27,7 +26,7 @@ int main(void) int accepted; char *received = NULL; - if (listen_socket < 0) die("Failed creating socket."); + if (listen_socket < 0) why2_die("Failed creating socket."); //DEFINE SERVER ADDRESS struct sockaddr_in server_addr; @@ -36,17 +35,17 @@ int main(void) server_addr.sin_addr.s_addr = INADDR_ANY; //BIND SOCKET - if (bind(listen_socket, (SA *) &server_addr, sizeof(server_addr)) < 0) die("Failed binding socket."); + if (bind(listen_socket, (SA *) &server_addr, sizeof(server_addr)) < 0) why2_die("Failed binding socket."); //LISTEN - if (listen(listen_socket, 1) < 0) die("Binding failed."); + if (listen(listen_socket, 1) < 0) why2_die("Binding failed."); //LOOP ACCEPT while (getchar() != '\n') //END WHEN ENTER IS PRESSED { accepted = accept(listen_socket, (SA *) NULL, NULL); //ACCEPT NEW SOCKET //TODO: CLOSE - if (accepted == -1) die("Accepting socket failed!"); + if (accepted == -1) why2_die("Accepting socket failed!"); received = read_socket(accepted); @@ -75,7 +74,7 @@ char *read_socket(int socket) //ALLOCATE content = why2_calloc(content_size, sizeof(char)); - if (fread(content, content_size, 1, opened) != 1) die("Reading socket failed!"); + if (fread(content, content_size, 1, opened) != 1) why2_die("Reading socket failed!"); //DEALLOCATION why2_deallocate(opened);