Path: blob/master/concurrency-webserver/src/wserver.c
909 views
#include <stdio.h>1#include "request.h"2#include "io_helper.h"34char default_root[] = ".";56//7// ./wserver [-d <basedir>] [-p <portnum>]8//9int main(int argc, char *argv[]) {10int c;11char *root_dir = default_root;12int port = 10000;1314while ((c = getopt(argc, argv, "d:p:")) != -1)15switch (c) {16case 'd':17root_dir = optarg;18break;19case 'p':20port = atoi(optarg);21break;22default:23fprintf(stderr, "usage: wserver [-d basedir] [-p port]\n");24exit(1);25}2627// run out of this directory28chdir_or_die(root_dir);2930// now, get to work31int listen_fd = open_listen_fd_or_die(port);32while (1) {33struct sockaddr_in client_addr;34int client_len = sizeof(client_addr);35int conn_fd = accept_or_die(listen_fd, (sockaddr_t *) &client_addr, (socklen_t *) &client_len);36request_handle(conn_fd);37close_or_die(conn_fd);38}39return 0;40}414243444546474849