1
0
Fork 0

(svn r24532) -Change: try to read more UDP packets per game loop

release/1.3
rubidium 2012-09-19 15:15:49 +00:00
parent 461fc1e268
commit 7251fbb514
1 changed files with 13 additions and 10 deletions

View File

@ -117,6 +117,7 @@ void NetworkUDPSocketHandler::SendPacket(Packet *p, NetworkAddress *recv, bool a
void NetworkUDPSocketHandler::ReceivePackets() void NetworkUDPSocketHandler::ReceivePackets()
{ {
for (SocketList::iterator s = this->sockets.Begin(); s != this->sockets.End(); s++) { for (SocketList::iterator s = this->sockets.Begin(); s != this->sockets.End(); s++) {
for (int i = 0; i < 1000; i++) { // Do not infinitely loop when DoSing with UDP
struct sockaddr_storage client_addr; struct sockaddr_storage client_addr;
memset(&client_addr, 0, sizeof(client_addr)); memset(&client_addr, 0, sizeof(client_addr));
@ -127,8 +128,10 @@ void NetworkUDPSocketHandler::ReceivePackets()
SetNonBlocking(s->second); // Some OSes seem to lose the non-blocking status of the socket 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); int nbytes = recvfrom(s->second, (char*)p.buffer, SEND_MTU, 0, (struct sockaddr *)&client_addr, &client_len);
/* We got some bytes for the base header of the packet. */ /* Did we get the bytes for the base header of the packet? */
if (nbytes > 2) { if (nbytes <= 0) break; // No data, i.e. no packet
if (nbytes <= 2) continue; // Invalid data; try next packet
NetworkAddress address(client_addr, client_len); NetworkAddress address(client_addr, client_len);
p.PrepareToRead(); p.PrepareToRead();
@ -136,7 +139,7 @@ void NetworkUDPSocketHandler::ReceivePackets()
* Otherwise it will be marked as corrupted later on. */ * Otherwise it will be marked as corrupted later on. */
if (nbytes != p.size) { if (nbytes != p.size) {
DEBUG(net, 1, "received a packet with mismatching size from %s", address.GetAddressAsString()); DEBUG(net, 1, "received a packet with mismatching size from %s", address.GetAddressAsString());
return; continue;
} }
/* Handle the packet */ /* Handle the packet */