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

Hopefully ok exit works now

parent f3d702a5
No related branches found
No related tags found
No related merge requests found
......@@ -221,6 +221,7 @@ int boot_server(char *ifaces, int port) {
int process_cli_requests(int svr_socket) {
int cli_socket;
pthread_t thread_id;
void *thread_ret;
printf("SERVER: Waiting for client connections...\n");
......@@ -239,16 +240,18 @@ int process_cli_requests(int svr_socket) {
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");
// Wait for the thread to finish and check its return value
pthread_join(thread_id, &thread_ret);
if (thread_ret == (void *)OK_EXIT) {
printf("SERVER: Received stop-server command. Shutting down...\n");
break; // Exit the loop and shut down the server
}
}
return OK;
}
/*
* exec_client_requests(cli_socket)
* cli_socket: The server-side socket that is connected to the client
......@@ -291,7 +294,6 @@ int process_cli_requests(int svr_socket) {
* or receive errors.
*/
void *exec_client_requests(void *socket_handle) {
int cli_socket = *((int *)socket_handle);
char cmd_buff[RDSH_COMM_BUFF_SZ];
......@@ -308,6 +310,13 @@ void *exec_client_requests(void *socket_handle) {
cmd_buff[recv_bytes] = '\0';
printf("SERVER: Received command: %s\n", cmd_buff);
// Check for stop-server command
if (strcmp(cmd_buff, "stop-server") == 0) {
printf("SERVER: Received stop-server command. Shutting down...\n");
close(cli_socket);
pthread_exit((void *)OK_EXIT); // Signal server to stop
}
// Execute the command
if (strstr(cmd_buff, "|") != NULL) {
// Handle pipeline commands
......@@ -387,6 +396,7 @@ void *exec_client_requests(void *socket_handle) {
pthread_exit(NULL);
}
/*
* send_message_eof(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