Skip to content
Snippets Groups Projects
Commit a7b4c2ec authored by Joey Le's avatar Joey Le
Browse files

Ok I forgot to call make the entire time wtf

parent 9ebef86a
No related branches found
No related tags found
No related merge requests found
......@@ -8,6 +8,7 @@
#include <sys/un.h>
#include <fcntl.h>
#include <errno.h>
#include <pthread.h>
//INCLUDES for extra credit
//#include <signal.h>
......@@ -73,6 +74,8 @@
}
/*
* stop_server(svr_socket)
* svr_socket: The socket that was created in the boot_server()
......@@ -172,41 +175,6 @@ int stop_server(int svr_socket) {
return svr_socket;
}
/*
* process_cli_requests(svr_socket)
*/
int process_cli_requests(int svr_socket) {
int cli_socket;
pthread_t thread_id;
printf("SERVER: Waiting for client connections...\n");
while (1) {
printf("SERVER: Waiting for a client to connect...\n");
cli_socket = accept(svr_socket, NULL, NULL);
if (cli_socket == -1) {
perror("SERVER: accept failed");
return ERR_RDSH_COMMUNICATION;
}
printf("SERVER: Client connected. Socket: %d\n", cli_socket);
if (pthread_create(&thread_id, NULL, exec_client_requests, (void *)&cli_socket) < 0) {
perror("SERVER: Failed to create thread");
close(cli_socket);
return ERR_RDSH_COMMUNICATION;
}
printf("SERVER: Thread created for client. Thread ID: %lu\n", (unsigned long)thread_id);
pthread_detach(thread_id);
printf("SERVER: Thread detached.\n");
}
return OK;
}
/*
* process_cli_requests(svr_socket)
* svr_socket: The server socket that was obtained from boot_server()
......@@ -248,6 +216,8 @@ int process_cli_requests(int svr_socket) {
* connections, and negative values terminate the server.
*
*/
int process_cli_requests(int svr_socket) {
int cli_socket;
pthread_t thread_id;
......@@ -255,29 +225,30 @@ int process_cli_requests(int svr_socket) {
printf("SERVER: Waiting for client connections...\n");
while (1) {
// Accept a client connection
printf("SERVER: Waiting for a client to connect...\n");
cli_socket = accept(svr_socket, NULL, NULL);
if (cli_socket == -1) {
perror("SERVER: accept failed");
return ERR_RDSH_COMMUNICATION;
}
printf("SERVER: Client connected. Socket: %d\n", cli_socket);
// Create a new thread to handle the client
if (pthread_create(&thread_id, NULL, exec_client_requests, (void *)&cli_socket) < 0) {
perror("SERVER: Failed to create thread");
close(cli_socket);
return ERR_RDSH_COMMUNICATION;
}
printf("SERVER: Thread created for client. Thread ID: %lu\n", (unsigned long)thread_id);
// Detach the thread to allow it to clean up automatically
pthread_detach(thread_id);
printf("SERVER: Thread detached.\n");
}
return OK;
}
/*
* exec_client_requests(cli_socket)
* cli_socket: The server-side socket that is connected to the client
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment