Codechange: encapsulate reading data from sockets into Packets to prevent packet state modifications outside of the Packet

This commit is contained in:
Rubidium
2021-04-18 09:55:00 +02:00
committed by rubidium42
parent a2051bad50
commit 98aa561cf7
4 changed files with 75 additions and 15 deletions

View File

@@ -119,12 +119,12 @@ void NetworkUDPSocketHandler::ReceivePackets()
struct sockaddr_storage client_addr;
memset(&client_addr, 0, sizeof(client_addr));
Packet p(this);
Packet p(this, SEND_MTU);
socklen_t client_len = sizeof(client_addr);
/* Try to receive anything */
SetNonBlocking(s.second); // Some OSes seem to lose the non-blocking status of the socket
int nbytes = recvfrom(s.second, (char*)p.buffer, SEND_MTU, 0, (struct sockaddr *)&client_addr, &client_len);
ssize_t nbytes = p.TransferIn<int>(recvfrom, s.second, 0, (struct sockaddr *)&client_addr, &client_len);
/* Did we get the bytes for the base header of the packet? */
if (nbytes <= 0) break; // No data, i.e. no packet