#include "http_server.h" #include "../common/socket_helper.h" #include "socket_server.h" #include #include #include #include #include #include #include #include bool running = true; void handle_signal(int signal) { running = false; } int main(int argc, char* argv[]) { if (argc != 2) { printf("%s", USAGE_STRING); } 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); return 1; } struct sigaction sa = {.sa_handler = &handle_signal, .sa_flags = 0}; sigemptyset(&sa.sa_mask); sigaction(SIGINT, &sa, NULL); sigaction(SIGTERM, &sa, NULL); struct server_info info = setup(port_num); if (info.status == STATUS_ERROR) { printf("%s\n", strerror(errno)); return 1; } while (running) { 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); } } close(info.sock_fd); }