cs-3516-assignment-1/server/http_server.c

24 lines
642 B
C

#include "http_server.h"
#include "../common/socket_helper.h"
#include "socket_server.h"
#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
#include <sys/socket.h>
#include <unistd.h>
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);
}
struct server_info info = setup(port_num);
serve_one_request(info.sock_fd);
shutdown(info.sock_fd, SHUT_RDWR);
close(info.sock_fd);
}