From 54aed2330b161bc040f2c40a00c4bad4cf54447b Mon Sep 17 00:00:00 2001 From: ENGO150 Date: Tue, 20 Feb 2024 13:27:09 +0100 Subject: [PATCH] fixed bad socket read in some cases idk just reading it by bytes now and it seems to work --- src/chat/misc.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/chat/misc.c b/src/chat/misc.c index a6e42c7..949189b 100644 --- a/src/chat/misc.c +++ b/src/chat/misc.c @@ -145,9 +145,15 @@ char *read_socket_raw(int socket) content_buffer = why2_calloc(content_size + 1, sizeof(char)); //READ JSON MESSAGE - if (recv(socket, content_buffer, content_size, 0) != content_size - 2) fprintf(stderr, "Socket probably read wrongly!\n"); + for (int i = 0; strncmp(content_buffer + strlen(content_buffer) - 2, "\"}", 2) != 0; i++) + { + if (recv(socket, content_buffer + i, 1, 0) != 1) //READ THE MESSAGE BY CHARACTERS + { + fprintf(stderr, "Socket probably read wrongly!\n"); + } + } - content_buffer[content_size - 1] = '\0'; //TODO: Possible problems + content_buffer[content_size - 1] = '\0'; return content_buffer; }