summaryrefslogtreecommitdiff
path: root/Source/Core
diff options
context:
space:
mode:
authorAdmiral H. Curtiss <pikachu025@gmail.com>2022-10-09 02:39:38 +0200
committerAdmiral H. Curtiss <pikachu025@gmail.com>2022-10-09 02:39:38 +0200
commitbfbc04ef5ec6bc51a931108456e174ec2f291155 (patch)
tree10ecc5343ff59ce096f9450d55fd7a1396efe5f8 /Source/Core
parent66684a392f15344845368e880cfbe421f6e9af38 (diff)
ENetUtil: Check return values of ENet functions in SendPacket().
Diffstat (limited to 'Source/Core')
-rw-r--r--Source/Core/Common/ENetUtil.cpp18
-rw-r--r--Source/Core/Common/ENetUtil.h2
2 files changed, 17 insertions, 3 deletions
diff --git a/Source/Core/Common/ENetUtil.cpp b/Source/Core/Common/ENetUtil.cpp
index e450ee65d1..d06de7c82a 100644
--- a/Source/Core/Common/ENetUtil.cpp
+++ b/Source/Core/Common/ENetUtil.cpp
@@ -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
diff --git a/Source/Core/Common/ENetUtil.h b/Source/Core/Common/ENetUtil.h
index 11a45a4e05..5b06e5a007 100644
--- a/Source/Core/Common/ENetUtil.h
+++ b/Source/Core/Common/ENetUtil.h
@@ -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