From cabddcb18574682224a015316f765195e8d88e90 Mon Sep 17 00:00:00 2001 From: Tiiffi Date: Thu, 27 Nov 2025 06:55:06 +0200 Subject: [PATCH] Add a net_recv_all() function to ensure complete receives at all times --- mcrcon.c | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/mcrcon.c b/mcrcon.c index 801e3d3..67d389a 100755 --- a/mcrcon.c +++ b/mcrcon.c @@ -84,6 +84,7 @@ void net_init_WSA(void); void net_close(int sd); int net_connect(const char *host, const char *port); bool net_send_packet(int sd, rc_packet *packet); +ssize_t net_recv_all(int sockfd, void *buf, size_t len); rc_packet* net_recv_packet(int sd); // Misc stuff @@ -422,6 +423,18 @@ bool net_send_packet(int sd, rc_packet *packet) return true; } +ssize_t net_recv_all(int sockfd, void *buf, size_t len) +{ + size_t total = 0; + + while (total < len) { + ssize_t n = recv(sockfd, (char*) buf + total, len - total, 0); + if (n <= 0) return n; // error or closed + total += n; + } + + return total; +} // TODO: Fix the wonky behaviour when server quit/exit/stop/close // command is issued. Client should close gracefully without errors.