diff --git a/.vscode/settings.json b/.vscode/settings.json index b150ea6f976f9dd21546919f46ada75737339e79..654eb2c0f8b9510552852d113b8e022f1ee3257a 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -10,6 +10,7 @@ "type_traits": "c", "xstring": "c", "xutility": "c", - "stdio.h": "c" + "stdio.h": "c", + "stat.h": "c" } } \ No newline at end of file diff --git a/makefile b/makefile index 08090383a27e1469d329d926e43f140507eef6d2..b8b253ac6dc7b5e319294b7639a2362d150530a3 100644 --- a/makefile +++ b/makefile @@ -1,6 +1,7 @@ server: server.c get.c - gcc -o server server.c get.c - + gcc -o server server.c get.c -lpthread +debug: server.c get.c + gcc -o server server.c get.c -lpthread -g client: client.c gcc -o client client.c diff --git a/server.c b/server.c index dc2e82a47d66ae37dcdc6ec725fa882b4e65c03f..28ebbf64c0709366bbd54f9b415cf1a663684105 100644 --- a/server.c +++ b/server.c @@ -61,39 +61,37 @@ int main(int argc, char *argv[]) incoming connection requests will be queued */ listen(sockfd,5); clilen = sizeof(cli_addr); - - /* Accept a connection - block until a connection is ready to - be accepted. Get back a new file descriptor to communicate on. */ - newsockfd = accept( sockfd, (struct sockaddr *) &cli_addr, - &clilen); - if (newsockfd < 0) { - perror("ERROR on accept"); - exit(1); - } - - bzero(buffer,BUF); - /* Read characters from the connection, - then process */ - n = read(newsockfd,buffer,BUF-1); - - /* ******************************************************************************** */ - /* ******************************************************************************** */ - /* ******************************************************************************** */ char* root = argv[2]; - // Extract just the file path from the request message into the char array 'path'. - parse_request_and_send_response(root, buffer, newsockfd); - - - // printf("Here is the message: %s\n",buffer); - // printf("Here is the path calculated: %s + %s = %s\n", root, path, full_path); + while(1) { + /* Accept a connection - block until a connection is ready to + be accepted. Get back a new file descriptor to communicate on. */ + newsockfd = accept( sockfd, (struct sockaddr *) &cli_addr, + &clilen); + if (newsockfd < 0) { + perror("ERROR on accept"); + // exit(1); + continue; + } + if (!fork()) { + close(sockfd); + printf("closed sockfd\n"); + // bzero(buffer,BUF); + /* Read characters from the connection, then process */ + n = read(newsockfd,buffer,BUF-1); + parse_request_and_send_response(root, buffer, newsockfd); + close(newsockfd); + printf("closed newsockfd\n"); + } + close(newsockfd); + printf("closed sockfd in parent\n"); + } if (n < 0) { perror("ERROR writing to socket"); exit(1); } - /* close socket */ - close(sockfd); + // close(sockfd); return 0; }