From 1af6cf45a12bfdec4ca99fd4570ec68488346217 Mon Sep 17 00:00:00 2001 From: ENGO150 Date: Thu, 20 Apr 2023 09:49:16 +0200 Subject: [PATCH] optimalyzed send_to_all loop --- src/chat/misc.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/chat/misc.c b/src/chat/misc.c index 63a4f36..0735c71 100644 --- a/src/chat/misc.c +++ b/src/chat/misc.c @@ -71,6 +71,8 @@ void *send_to_all(void *json) //PARSE struct json_object *json_obj = json_tokener_parse((char*) 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 @@ -80,7 +82,7 @@ void *send_to_all(void *json) connection_buffer = *(connection_node_t*) node_buffer -> value; - why2_send_socket(get_string_from_json(json_obj, "message"), get_string_from_json(json_obj, "username"), connection_buffer.connection); //SEND TO CLIENT + why2_send_socket(message, username, connection_buffer.connection); //SEND TO CLIENT } //DEALLOCATION