use thread_local static buffer to receive into, null term manually

This commit is contained in:
Lion Kortlepel 2024-06-19 16:53:17 +02:00
parent 17e887442c
commit 8b0f4f99f6
No known key found for this signature in database
GPG Key ID: 4322FF2B4C71259B

View File

@ -63,13 +63,13 @@ void UDPRcv() {
socklen_t clientLength = sizeof(FromServer);
#endif
ZeroMemory(&FromServer, clientLength);
std::array<char, 10240> Ret {};
Ret.fill(0);
static thread_local std::array<char, 10240> Ret {};
if (UDPSock == -1)
return;
int32_t Rcv = recvfrom(UDPSock, Ret.data(), Ret.size(), 0, (sockaddr*)&FromServer, &clientLength);
int32_t Rcv = recvfrom(UDPSock, Ret.data(), Ret.size() - 1, 0, (sockaddr*)&FromServer, &clientLength);
if (Rcv == SOCKET_ERROR)
return;
Ret[Rcv] = 0;
UDPParser(std::string_view(Ret.data(), Rcv));
}
void UDPClientMain(const std::string& IP, int Port) {