Skip to content

Commit

Permalink
update totalWaitingData when removing an incoming command
Browse files Browse the repository at this point in the history
  • Loading branch information
lsalzman committed Jul 24, 2024
1 parent 0b924c7 commit a52811e
Showing 1 changed file with 13 additions and 11 deletions.
24 changes: 13 additions & 11 deletions peer.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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;

Expand All @@ -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);
}
Expand All @@ -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
Expand All @@ -327,19 +329,19 @@ 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)
{
for (channel = peer -> channels;
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);
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit a52811e

Please sign in to comment.