summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorThorbjørn Lindeijer <bjorn@lindeijer.nl>2022-05-25 12:40:13 +0200
committerThorbjørn Lindeijer <bjorn@lindeijer.nl>2022-05-25 12:43:44 +0200
commit9249af970f91adf2d05d52076a54c2cf3ac6dacb (patch)
tree739a089c800234e704118c4ff750ed0ee3a8ff50 /src
parentca16e8d37629cf2d80bb9fb5a134ea17595de7ce (diff)
downloadmanaserv-9249af970f91adf2d05d52076a54c2cf3ac6dacb.tar.gz
manaserv-9249af970f91adf2d05d52076a54c2cf3ac6dacb.tar.bz2
manaserv-9249af970f91adf2d05d52076a54c2cf3ac6dacb.tar.xz
manaserv-9249af970f91adf2d05d52076a54c2cf3ac6dacb.zip
Check return value for enet_peer_send
If it fails, we will need to destroy the packet ourselves rather than relying on enet to eventually destroy it.
Diffstat (limited to 'src')
-rw-r--r--src/net/connection.cpp18
-rw-r--r--src/net/netcomputer.cpp6
2 files changed, 18 insertions, 6 deletions
diff --git a/src/net/connection.cpp b/src/net/connection.cpp
index c54c0dbb..b2bc7cef 100644
--- a/src/net/connection.cpp
+++ b/src/net/connection.cpp
@@ -31,8 +31,8 @@
#endif
Connection::Connection():
- mRemote(0),
- mLocal(0)
+ mRemote(nullptr),
+ mLocal(nullptr)
{
}
@@ -86,8 +86,8 @@ void Connection::stop()
if (mLocal)
enet_host_destroy(mLocal);
- mRemote = 0;
- mLocal = 0;
+ mRemote = nullptr;
+ mLocal = nullptr;
}
bool Connection::isConnected() const
@@ -110,9 +110,17 @@ void Connection::send(const MessageOut &msg, bool reliable, unsigned channel)
reliable ? ENET_PACKET_FLAG_RELIABLE : 0);
if (packet)
- enet_peer_send(mRemote, channel, packet);
+ {
+ if (enet_peer_send(mRemote, channel, packet) < 0)
+ {
+ LOG_ERROR("Failure to send packet!");
+ enet_packet_destroy(packet);
+ }
+ }
else
+ {
LOG_ERROR("Failure to create packet!");
+ }
}
void Connection::process()
diff --git a/src/net/netcomputer.cpp b/src/net/netcomputer.cpp
index 5d86f13a..f2d9607b 100644
--- a/src/net/netcomputer.cpp
+++ b/src/net/netcomputer.cpp
@@ -70,7 +70,11 @@ void NetComputer::send(const MessageOut &msg, bool reliable,
if (packet)
{
- enet_peer_send(mPeer, channel, packet);
+ if (enet_peer_send(mPeer, channel, packet) < 0)
+ {
+ LOG_ERROR("Failure to send packet!");
+ enet_packet_destroy(packet);
+ }
}
else
{