From 0e9b5df58cd2c5139b723c2acb8286612d0269bb Mon Sep 17 00:00:00 2001 From: ENGO150 Date: Fri, 2 Feb 2024 10:59:22 +0100 Subject: [PATCH] made send_to_all not run in a thread --- src/chat/misc.c | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) diff --git a/src/chat/misc.c b/src/chat/misc.c index c05ce76..0b2508b 100644 --- a/src/chat/misc.c +++ b/src/chat/misc.c @@ -69,18 +69,18 @@ char *get_string_from_json_string(char *json, char *string) return returning; } -void *send_to_all(void *json) +void send_to_all(char *json) { why2_node_t _first_node = (why2_node_t) { NULL, connection_list.head }; why2_node_t *node_buffer = &_first_node; connection_node_t connection_buffer; //PARSE - struct json_object *json_obj = json_tokener_parse((char*) json); + struct json_object *json_obj = json_tokener_parse(json); char *message = get_string_from_json(json_obj, "message"); char *username = get_string_from_json(json_obj, "username"); - if (json_obj == NULL) return NULL; //EXIT IF INVALID SYNTAX WAS SENT + if (json_obj == NULL) return; //EXIT IF INVALID SYNTAX WAS SENT while (node_buffer -> next != NULL) //SEND TO ALL CONNECTIONS { @@ -93,8 +93,6 @@ void *send_to_all(void *json) //DEALLOCATION json_object_put(json_obj); - - return NULL; } void append(char **destination, char *key, char *value) @@ -462,7 +460,6 @@ void *why2_communicate_thread(void *arg) raw = why2_strdup(""); char *raw_output; - pthread_t thread_buffer; char *connection_message = why2_malloc(strlen(username) + 11); //BUILD connection_message @@ -479,8 +476,7 @@ void *why2_communicate_thread(void *arg) add_brackets(&raw); json_object_put(json); - pthread_create(&thread_buffer, NULL, send_to_all, raw); //SEND - pthread_join(thread_buffer, NULL); + send_to_all(raw); //FUCKING SEND TO ALL YOU TWAT why2_deallocate(raw); why2_deallocate(connection_message); @@ -529,8 +525,7 @@ void *why2_communicate_thread(void *arg) } add_brackets(&raw_output); - pthread_create(&thread_buffer, NULL, send_to_all, raw_output); - pthread_join(thread_buffer, NULL); + send_to_all(raw_output); //e deallocation: