From 82a6d4af609013391c0a92506d96c7b5b763c77a Mon Sep 17 00:00:00 2001 From: Lion Kortlepel Date: Sun, 14 Jul 2024 17:01:24 +0200 Subject: [PATCH] repeat sendfile() until all data is sent --- src/TNetwork.cpp | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/src/TNetwork.cpp b/src/TNetwork.cpp index 431e859..6ea08a7 100644 --- a/src/TNetwork.cpp +++ b/src/TNetwork.cpp @@ -831,12 +831,16 @@ void TNetwork::SplitLoad(TClient& c, size_t Offset, size_t End, bool D, const st // native handle, needed in order to make native syscalls with it int socket = D ? c.GetDownSock().native_handle() : c.GetTCPSock().native_handle(); - auto SysOffset = off_t(Offset); - - ssize_t ret = sendfile64(socket, fd, &SysOffset, End - Offset); - if (ret < 0) { - beammp_errorf("Failed to send mod '{}' to client {}: {}", Name, c.GetID(), std::strerror(errno)); - return; + ssize_t ret = 0; + auto ToSendTotal = End - Offset; + auto Start = Offset; + while (ret < ssize_t(ToSendTotal)) { + auto SysOffset = off_t(Start + size_t(ret)); + ret = sendfile(socket, fd, &SysOffset, ToSendTotal - size_t(ret)); + if (ret < 0) { + beammp_errorf("Failed to send mod '{}' to client {}: {}", Name, c.GetID(), std::strerror(errno)); + return; + } } #else