repeat sendfile() until all data is sent

This commit is contained in:
Lion Kortlepel 2024-07-14 17:01:24 +02:00
parent 8b753ab6ea
commit 82a6d4af60
No known key found for this signature in database
GPG Key ID: 4322FF2B4C71259B

View File

@ -831,13 +831,17 @@ 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);
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
std::ifstream f(Name.c_str(), std::ios::binary);