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

27 lines
709 B
C
Raw Normal View History

2018-09-03 22:54:02 +00:00
#include "http_server.h"
#include "../common/socket_helper.h"
2018-09-08 21:26:34 +00:00
#include "socket_server.h"
2018-09-03 22:54:02 +00:00
#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
2018-09-09 23:51:51 +00:00
#include <string.h>
2018-09-08 21:26:34 +00:00
#include <sys/socket.h>
#include <unistd.h>
2018-09-03 22:54:02 +00:00
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);
}
2018-09-08 21:26:34 +00:00
struct server_info info = setup(port_num);
2018-09-09 23:51:51 +00:00
if (info.status == STATUS_ERROR) {
printf("%s\n", strerror(errno));
}
2018-09-08 21:26:34 +00:00
serve_one_request(info.sock_fd);
close(info.sock_fd);
2018-09-03 22:54:02 +00:00
}