Clean up error handling

master
Nick Krichevsky 2018-09-10 00:23:39 -04:00
parent c1621c5b06
commit 2beb6b93e7
1 changed files with 10 additions and 1 deletions

View File

@ -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);