added message thread cleanup for server
also swaped the function names cause I am so smart
This commit is contained in:
parent
5fdd267907
commit
ddbe899071
@ -25,7 +25,8 @@ void why2_send_socket(char *text, char *username, int socket); //send socket....
|
|||||||
char *why2_read_socket(int socket); //read lol
|
char *why2_read_socket(int socket); //read lol
|
||||||
void *why2_communicate_thread(void *arg); //COMMUNICATION THREAD
|
void *why2_communicate_thread(void *arg); //COMMUNICATION THREAD
|
||||||
void *why2_accept_thread(void *socket); //LOOP ACCEPTING CONNECTIONS
|
void *why2_accept_thread(void *socket); //LOOP ACCEPTING CONNECTIONS
|
||||||
void why2_clean_threads(void); //CLOSE EVERY RUNNING THREAD
|
void why2_clean_connections(void); //CLOSE EVERY CONNECTION
|
||||||
|
void why2_clean_threads(void); //CLOSE EVERY RUNNING MESSAGE THREAD
|
||||||
void *why2_listen_server(void *socket); //LISTEN FOR OTHER's USERS MESSAGES
|
void *why2_listen_server(void *socket); //LISTEN FOR OTHER's USERS MESSAGES
|
||||||
void *why2_getline_thread(WHY2_UNUSED void* arg); //START getline IN SEPARATE THREAD
|
void *why2_getline_thread(WHY2_UNUSED void* arg); //START getline IN SEPARATE THREAD
|
||||||
|
|
||||||
|
@ -70,8 +70,11 @@ int main(void)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//QUIT COMMUNICATION
|
||||||
|
why2_clean_connections(); //STOP LISTENING; DISCONNECT ALL USERS
|
||||||
|
why2_clean_threads(); //STOP WAITING FOR MESSAGES
|
||||||
|
|
||||||
//DEALLOCATION
|
//DEALLOCATION
|
||||||
why2_clean_threads();
|
|
||||||
free(line_buffer);
|
free(line_buffer);
|
||||||
close(listen_socket);
|
close(listen_socket);
|
||||||
pthread_cancel(thread);
|
pthread_cancel(thread);
|
||||||
|
@ -452,25 +452,45 @@ void *why2_accept_thread(void *socket)
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
void why2_clean_threads(void)
|
void why2_clean_connections(void)
|
||||||
{
|
{
|
||||||
if (connection_list.head == NULL) return; //EMPTY LIST
|
why2_node_t *head = connection_list.head;
|
||||||
|
if (head == NULL) return; //EMPTY LIST
|
||||||
|
|
||||||
why2_node_t *node_buffer;
|
why2_node_t *node_buffer = head;
|
||||||
|
why2_node_t *node_buffer_2;
|
||||||
connection_node_t connection_buffer;
|
connection_node_t connection_buffer;
|
||||||
|
|
||||||
do //GO TROUGH LIST
|
do //GO TROUGH LIST
|
||||||
{
|
{
|
||||||
node_buffer = connection_list.head;
|
node_buffer_2 = node_buffer;
|
||||||
|
node_buffer = node_buffer -> next;
|
||||||
|
|
||||||
connection_buffer = *(connection_node_t*) node_buffer -> value;
|
connection_buffer = *(connection_node_t*) node_buffer_2 -> value; // TODO: TADY SE TO SERE
|
||||||
|
|
||||||
why2_send_socket(WHY2_CHAT_CODE_SSQC, WHY2_CHAT_SERVER_USERNAME, connection_buffer.connection);
|
why2_send_socket(WHY2_CHAT_CODE_SSQC, WHY2_CHAT_SERVER_USERNAME, connection_buffer.connection);
|
||||||
|
|
||||||
close(connection_buffer.connection);
|
close(connection_buffer.connection);
|
||||||
|
why2_list_remove(&connection_list, node_buffer_2); //REMOVE
|
||||||
|
} while (node_buffer != NULL);
|
||||||
|
}
|
||||||
|
|
||||||
why2_list_remove(&connection_list, node_buffer); //REMOVE
|
void why2_clean_threads(void)
|
||||||
} while (connection_list.head != NULL);
|
{
|
||||||
|
why2_node_t *head = waiting_list.head;
|
||||||
|
if (head == NULL) return; //EMPTY LIST
|
||||||
|
|
||||||
|
why2_node_t *node_buffer = head;
|
||||||
|
why2_node_t *node_buffer_2;
|
||||||
|
|
||||||
|
do //GO TROUGH LIST
|
||||||
|
{
|
||||||
|
node_buffer_2 = node_buffer;
|
||||||
|
node_buffer = node_buffer -> next;
|
||||||
|
|
||||||
|
pthread_cancel(**(pthread_t**)(node_buffer_2 -> value));
|
||||||
|
why2_list_remove(&waiting_list, node_buffer_2); //REMOVE
|
||||||
|
} while (node_buffer != NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
void *why2_listen_server(void *socket)
|
void *why2_listen_server(void *socket)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user