summaryrefslogtreecommitdiff
path: root/modules/enet
diff options
context:
space:
mode:
authorJordan Schidlowsky <jordan@winterpixel.com>2021-09-27 10:09:32 +0200
committerFabio Alessandrelli <fabio.alessandrelli@gmail.com>2021-12-15 14:03:42 +0100
commit397d895fb76d37881933c6e42b6256847ef6f2e6 (patch)
tree989b0f12c05c0b186d84d83166a458995d53c5f2 /modules/enet
parent1930fc8b3150e3084c16557d82dc2c517e3f292b (diff)
[Net] ENetMultiplayerPeer now sends fragmented packets unreliably too.
It used to always send them reliably when transfer mode was unreliable or ordered if the packet size was more then the enet host MTU (1400 bytes by default). This commit also adds a warning when debug is enabled to explain the effects of sending fragmented packets unreliably.
Diffstat (limited to 'modules/enet')
-rw-r--r--modules/enet/enet_multiplayer_peer.cpp10
1 files changed, 8 insertions, 2 deletions
diff --git a/modules/enet/enet_multiplayer_peer.cpp b/modules/enet/enet_multiplayer_peer.cpp
index 2cfae60ad2..5c0a2286d2 100644
--- a/modules/enet/enet_multiplayer_peer.cpp
+++ b/modules/enet/enet_multiplayer_peer.cpp
@@ -441,11 +441,11 @@ Error ENetMultiplayerPeer::put_packet(const uint8_t *p_buffer, int p_buffer_size
} else {
switch (get_transfer_mode()) {
case Multiplayer::TRANSFER_MODE_UNRELIABLE: {
- packet_flags = ENET_PACKET_FLAG_UNSEQUENCED;
+ packet_flags = ENET_PACKET_FLAG_UNSEQUENCED | ENET_PACKET_FLAG_UNRELIABLE_FRAGMENT;
channel = SYSCH_UNRELIABLE;
} break;
case Multiplayer::TRANSFER_MODE_UNRELIABLE_ORDERED: {
- packet_flags = 0;
+ packet_flags = ENET_PACKET_FLAG_UNRELIABLE_FRAGMENT;
channel = SYSCH_UNRELIABLE;
} break;
case Multiplayer::TRANSFER_MODE_RELIABLE: {
@@ -455,6 +455,12 @@ Error ENetMultiplayerPeer::put_packet(const uint8_t *p_buffer, int p_buffer_size
}
}
+#ifdef DEBUG_ENABLED
+ if ((packet_flags & ENET_PACKET_FLAG_UNRELIABLE_FRAGMENT) && p_buffer_size + 8 > ENET_HOST_DEFAULT_MTU) {
+ WARN_PRINT_ONCE(vformat("Sending %d bytes unrealiably which is above the MTU (%d), this will result in higher packet loss", p_buffer_size + 8, ENET_HOST_DEFAULT_MTU));
+ }
+#endif
+
ENetPacket *packet = enet_packet_create(nullptr, p_buffer_size + 8, packet_flags);
encode_uint32(unique_id, &packet->data[0]); // Source ID
encode_uint32(target_peer, &packet->data[4]); // Dest ID