Update to 14.0-beta1
This commit is contained in:
@@ -10,9 +10,9 @@
|
||||
*/
|
||||
|
||||
#include "../../stdafx.h"
|
||||
#include "../../date_func.h"
|
||||
#include "../../timer/timer_game_calendar.h"
|
||||
#include "../../debug.h"
|
||||
#include "game_info.h"
|
||||
#include "network_game_info.h"
|
||||
#include "udp.h"
|
||||
|
||||
#include "../../safeguards.h"
|
||||
@@ -50,7 +50,7 @@ bool NetworkUDPSocketHandler::Listen()
|
||||
addr.Listen(SOCK_DGRAM, &this->sockets);
|
||||
}
|
||||
|
||||
return this->sockets.size() != 0;
|
||||
return !this->sockets.empty();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -59,7 +59,7 @@ bool NetworkUDPSocketHandler::Listen()
|
||||
void NetworkUDPSocketHandler::CloseSocket()
|
||||
{
|
||||
for (auto &s : this->sockets) {
|
||||
closesocket(s.second);
|
||||
closesocket(s.first);
|
||||
}
|
||||
this->sockets.clear();
|
||||
}
|
||||
@@ -73,7 +73,7 @@ void NetworkUDPSocketHandler::CloseSocket()
|
||||
*/
|
||||
void NetworkUDPSocketHandler::SendPacket(Packet *p, NetworkAddress *recv, bool all, bool broadcast)
|
||||
{
|
||||
if (this->sockets.size() == 0) this->Listen();
|
||||
if (this->sockets.empty()) this->Listen();
|
||||
|
||||
for (auto &s : this->sockets) {
|
||||
/* Make a local copy because if we resolve it we cannot
|
||||
@@ -81,20 +81,20 @@ void NetworkUDPSocketHandler::SendPacket(Packet *p, NetworkAddress *recv, bool a
|
||||
NetworkAddress send(*recv);
|
||||
|
||||
/* Not the same type */
|
||||
if (!send.IsFamily(s.first.GetAddress()->ss_family)) continue;
|
||||
if (!send.IsFamily(s.second.GetAddress()->ss_family)) continue;
|
||||
|
||||
p->PrepareToSend();
|
||||
|
||||
if (broadcast) {
|
||||
/* Enable broadcast */
|
||||
unsigned long val = 1;
|
||||
if (setsockopt(s.second, SOL_SOCKET, SO_BROADCAST, (char *) &val, sizeof(val)) < 0) {
|
||||
if (setsockopt(s.first, SOL_SOCKET, SO_BROADCAST, (char *) &val, sizeof(val)) < 0) {
|
||||
Debug(net, 1, "Setting broadcast mode failed: {}", NetworkError::GetLast().AsString());
|
||||
}
|
||||
}
|
||||
|
||||
/* Send the buffer */
|
||||
ssize_t res = p->TransferOut<int>(sendto, s.second, 0, (const struct sockaddr *)send.GetAddress(), send.GetAddressLength());
|
||||
ssize_t res = p->TransferOut<int>(sendto, s.first, 0, (const struct sockaddr *)send.GetAddress(), send.GetAddressLength());
|
||||
Debug(net, 7, "sendto({})", send.GetAddressAsString());
|
||||
|
||||
/* Check for any errors, but ignore it otherwise */
|
||||
@@ -119,8 +119,8 @@ void NetworkUDPSocketHandler::ReceivePackets()
|
||||
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
|
||||
ssize_t nbytes = p.TransferIn<int>(recvfrom, s.second, 0, (struct sockaddr *)&client_addr, &client_len);
|
||||
SetNonBlocking(s.first); // Some OSes seem to lose the non-blocking status of the socket
|
||||
ssize_t nbytes = p.TransferIn<int>(recvfrom, s.first, 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
|
||||
@@ -183,5 +183,5 @@ void NetworkUDPSocketHandler::ReceiveInvalidPacket(PacketUDPType type, NetworkAd
|
||||
Debug(net, 0, "[udp] Received packet type {} on wrong port from {}", type, client_addr->GetAddressAsString());
|
||||
}
|
||||
|
||||
void NetworkUDPSocketHandler::Receive_CLIENT_FIND_SERVER(Packet *p, NetworkAddress *client_addr) { this->ReceiveInvalidPacket(PACKET_UDP_CLIENT_FIND_SERVER, client_addr); }
|
||||
void NetworkUDPSocketHandler::Receive_SERVER_RESPONSE(Packet *p, NetworkAddress *client_addr) { this->ReceiveInvalidPacket(PACKET_UDP_SERVER_RESPONSE, client_addr); }
|
||||
void NetworkUDPSocketHandler::Receive_CLIENT_FIND_SERVER(Packet *, NetworkAddress *client_addr) { this->ReceiveInvalidPacket(PACKET_UDP_CLIENT_FIND_SERVER, client_addr); }
|
||||
void NetworkUDPSocketHandler::Receive_SERVER_RESPONSE(Packet *, NetworkAddress *client_addr) { this->ReceiveInvalidPacket(PACKET_UDP_SERVER_RESPONSE, client_addr); }
|
||||
|
||||
Reference in New Issue
Block a user