From a52811ef275e25d4df29dbee68fee410249d571e Mon Sep 17 00:00:00 2001 From: Lee Salzman Date: Wed, 24 Jul 2024 01:45:54 -0400 Subject: [PATCH] update totalWaitingData when removing an incoming command --- peer.c | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/peer.c b/peer.c index a7ac012..5eddf46 100644 --- a/peer.c +++ b/peer.c @@ -255,7 +255,7 @@ enet_peer_receive (ENetPeer * peer, enet_uint8 * channelID) } static void -enet_peer_reset_outgoing_commands (ENetList * queue) +enet_peer_reset_outgoing_commands (ENetPeer * peer, ENetList * queue) { ENetOutgoingCommand * outgoingCommand; @@ -276,7 +276,7 @@ enet_peer_reset_outgoing_commands (ENetList * queue) } static void -enet_peer_remove_incoming_commands (ENetList * queue, ENetListIterator startCommand, ENetListIterator endCommand, ENetIncomingCommand * excludeCommand) +enet_peer_remove_incoming_commands (ENetPeer * peer, ENetList * queue, ENetListIterator startCommand, ENetListIterator endCommand, ENetIncomingCommand * excludeCommand) { ENetListIterator currentCommand; @@ -295,6 +295,8 @@ enet_peer_remove_incoming_commands (ENetList * queue, ENetListIterator startComm { -- incomingCommand -> packet -> referenceCount; + peer -> totalWaitingData -= incomingCommand -> packet -> dataLength; + if (incomingCommand -> packet -> referenceCount == 0) enet_packet_destroy (incomingCommand -> packet); } @@ -307,9 +309,9 @@ enet_peer_remove_incoming_commands (ENetList * queue, ENetListIterator startComm } static void -enet_peer_reset_incoming_commands (ENetList * queue) +enet_peer_reset_incoming_commands (ENetPeer * peer, ENetList * queue) { - enet_peer_remove_incoming_commands(queue, enet_list_begin (queue), enet_list_end (queue), NULL); + enet_peer_remove_incoming_commands(peer, queue, enet_list_begin (queue), enet_list_end (queue), NULL); } void @@ -327,10 +329,10 @@ enet_peer_reset_queues (ENetPeer * peer) while (! enet_list_empty (& peer -> acknowledgements)) enet_free (enet_list_remove (enet_list_begin (& peer -> acknowledgements))); - enet_peer_reset_outgoing_commands (& peer -> sentReliableCommands); - enet_peer_reset_outgoing_commands (& peer -> outgoingCommands); - enet_peer_reset_outgoing_commands (& peer -> outgoingSendReliableCommands); - enet_peer_reset_incoming_commands (& peer -> dispatchedCommands); + enet_peer_reset_outgoing_commands (peer, & peer -> sentReliableCommands); + enet_peer_reset_outgoing_commands (peer, & peer -> outgoingCommands); + enet_peer_reset_outgoing_commands (peer, & peer -> outgoingSendReliableCommands); + enet_peer_reset_incoming_commands (peer, & peer -> dispatchedCommands); if (peer -> channels != NULL && peer -> channelCount > 0) { @@ -338,8 +340,8 @@ enet_peer_reset_queues (ENetPeer * peer) channel < & peer -> channels [peer -> channelCount]; ++ channel) { - enet_peer_reset_incoming_commands (& channel -> incomingReliableCommands); - enet_peer_reset_incoming_commands (& channel -> incomingUnreliableCommands); + enet_peer_reset_incoming_commands (peer, & channel -> incomingReliableCommands); + enet_peer_reset_incoming_commands (peer, & channel -> incomingUnreliableCommands); } enet_free (peer -> channels); @@ -801,7 +803,7 @@ enet_peer_dispatch_incoming_unreliable_commands (ENetPeer * peer, ENetChannel * droppedCommand = currentCommand; } - enet_peer_remove_incoming_commands (& channel -> incomingUnreliableCommands, enet_list_begin (& channel -> incomingUnreliableCommands), droppedCommand, queuedCommand); + enet_peer_remove_incoming_commands (peer, & channel -> incomingUnreliableCommands, enet_list_begin (& channel -> incomingUnreliableCommands), droppedCommand, queuedCommand); } void