From 6f03022646bc400ae02ba9d4ec863646cf1ae063 Mon Sep 17 00:00:00 2001 From: Romain Vimont Date: Thu, 15 Jul 2021 18:16:26 +0200 Subject: [PATCH] Fix net_send_all() On partial writes, the final result was the number of bytes written by the last send() rather than the total. --- app/src/util/net.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/app/src/util/net.c b/app/src/util/net.c index bbf57bbc..75daef8b 100644 --- a/app/src/util/net.c +++ b/app/src/util/net.c @@ -99,16 +99,18 @@ net_send(socket_t socket, const void *buf, size_t len) { ssize_t net_send_all(socket_t socket, const void *buf, size_t len) { + size_t copied = 0; ssize_t w = 0; while (len > 0) { w = send(socket, buf, len, 0); if (w == -1) { - return -1; + return copied ? (ssize_t) copied : -1; } len -= w; buf = (char *) buf + w; + copied += w; } - return w; + return copied; } bool -- GitLab