ENetUtil: Check return values of ENet functions in SendPacket().

This commit is contained in:
Admiral H. Curtiss 2022-10-09 02:39:38 +02:00
parent 66684a392f
commit bfbc04ef5e
No known key found for this signature in database
GPG Key ID: F051B4C4044F33FB
2 changed files with 17 additions and 3 deletions

View File

@ -4,6 +4,7 @@
#include "Common/ENetUtil.h"
#include "Common/CommonTypes.h"
#include "Common/Logging/Log.h"
namespace ENetUtil
{
@ -36,10 +37,23 @@ int ENET_CALLBACK InterceptCallback(ENetHost* host, ENetEvent* event)
return 0;
}
void SendPacket(ENetPeer* socket, const sf::Packet& packet, u8 channel_id)
bool SendPacket(ENetPeer* socket, const sf::Packet& packet, u8 channel_id)
{
ENetPacket* epac =
enet_packet_create(packet.getData(), packet.getDataSize(), ENET_PACKET_FLAG_RELIABLE);
enet_peer_send(socket, channel_id, epac);
if (!epac)
{
ERROR_LOG_FMT(NETPLAY, "Failed to create ENetPacket ({} bytes).", packet.getDataSize());
return false;
}
const int result = enet_peer_send(socket, channel_id, epac);
if (result != 0)
{
ERROR_LOG_FMT(NETPLAY, "Failed to send ENetPacket (error code {}).", result);
return false;
}
return true;
}
} // namespace ENetUtil

View File

@ -13,5 +13,5 @@ namespace ENetUtil
{
void WakeupThread(ENetHost* host);
int ENET_CALLBACK InterceptCallback(ENetHost* host, ENetEvent* event);
void SendPacket(ENetPeer* socket, const sf::Packet& packet, u8 channel_id);
bool SendPacket(ENetPeer* socket, const sf::Packet& packet, u8 channel_id);
} // namespace ENetUtil