From 2beb6b93e70bb9bc2e8157051ac6e52a6eff062f Mon Sep 17 00:00:00 2001 From: Nick Krichevsky Date: Mon, 10 Sep 2018 00:23:39 -0400 Subject: [PATCH] Clean up error handling --- server/http_server.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/server/http_server.c b/server/http_server.c index 322c843..b7565b0 100644 --- a/server/http_server.c +++ b/server/http_server.c @@ -28,7 +28,7 @@ int main(int argc, char* argv[]) { char *port = argv[1]; long port_num = strtol(port, NULL, 10); if (port_num < MIN_PORT || port_num > MAX_PORT || errno == ERANGE || errno == EINVAL) { - printf("%s", PORT_ERROR); + printf("%s\n", PORT_ERROR); return 1; } struct sigaction sa = {.sa_handler = &handle_signal, .sa_flags = 0}; @@ -46,6 +46,15 @@ int main(int argc, char* argv[]) { enum socket_result serve_result = serve_one_request(info.sock_fd); if (serve_result != RESULT_OK && errno != EINTR) { printf("Got error code %d when serving a request.\n", serve_result); + if (serve_result == RESULT_MALFORMED) { + printf("\tMalformed request. This may be due to the client closing the socket prematurely.\n"); + } else if (serve_result == RESULT_READ_ERROR) { + printf("\tThere was an error reading from the socket.\n"); + } else if (serve_result == RESULT_PROCESSING_ERROR) { + printf("\tThere was an error while processing the data from the socket."); + } else if (serve_result == RESULT_WRITE_ERROR) { + printf("\tThere was an error writing to the socket"); + } } } close(info.sock_fd);