Skip to content

Commit

Permalink
Fix command queuing
Browse files Browse the repository at this point in the history
  • Loading branch information
nxrighthere authored Aug 23, 2020
1 parent c044725 commit 8db4523
Showing 1 changed file with 15 additions and 12 deletions.
27 changes: 15 additions & 12 deletions Source/Native/enet.h
Original file line number Diff line number Diff line change
Expand Up @@ -776,8 +776,8 @@ extern "C" {
extern ENetOutgoingCommand* enet_peer_queue_outgoing_command(ENetPeer*, const ENetProtocol*, ENetPacket*, uint32_t, uint16_t);
extern ENetIncomingCommand* enet_peer_queue_incoming_command(ENetPeer*, const ENetProtocol*, const void*, size_t, uint32_t, uint32_t);
extern ENetAcknowledgement* enet_peer_queue_acknowledgement(ENetPeer*, const ENetProtocol*, uint16_t);
extern void enet_peer_dispatch_incoming_unreliable_commands(ENetPeer*, ENetChannel*);
extern void enet_peer_dispatch_incoming_reliable_commands(ENetPeer*, ENetChannel*);
extern void enet_peer_dispatch_incoming_unreliable_commands(ENetPeer*, ENetChannel*, ENetIncomingCommand*);
extern void enet_peer_dispatch_incoming_reliable_commands(ENetPeer*, ENetChannel*, ENetIncomingCommand*);
extern void enet_peer_on_connect(ENetPeer*);
extern void enet_peer_on_disconnect(ENetPeer*);

Expand Down Expand Up @@ -1916,7 +1916,7 @@ extern "C" {
memcpy(startCommand->packet->data + fragmentOffset, (uint8_t*)command + sizeof(ENetProtocolSendFragment), fragmentLength);

if (startCommand->fragmentsRemaining <= 0)
enet_peer_dispatch_incoming_reliable_commands(peer, channel);
enet_peer_dispatch_incoming_reliable_commands(peer, channel, NULL);
}

return 0;
Expand Down Expand Up @@ -2007,7 +2007,7 @@ extern "C" {
memcpy(startCommand->packet->data + fragmentOffset, (uint8_t*)command + sizeof(ENetProtocolSendFragment), fragmentLength);

if (startCommand->fragmentsRemaining <= 0)
enet_peer_dispatch_incoming_unreliable_commands(peer, channel);
enet_peer_dispatch_incoming_unreliable_commands(peer, channel, NULL);
}

return 0;
Expand Down Expand Up @@ -3110,13 +3110,16 @@ extern "C" {
}
}

static void enet_peer_remove_incoming_commands(ENetList* queue, ENetListIterator startCommand, ENetListIterator endCommand) {
static void enet_peer_remove_incoming_commands(ENetList* queue, ENetListIterator startCommand, ENetListIterator endCommand, ENetIncomingCommand* excludeCommand) {
ENetListIterator currentCommand;

for (currentCommand = startCommand; currentCommand != endCommand;) {
ENetIncomingCommand* incomingCommand = (ENetIncomingCommand*)currentCommand;
currentCommand = enet_list_next(currentCommand);

if (incomingCommand == excludeCommand)
continue;

enet_list_remove(&incomingCommand->incomingCommandList);

if (incomingCommand->packet != NULL) {
Expand All @@ -3134,7 +3137,7 @@ extern "C" {
}

static void enet_peer_reset_incoming_commands(ENetList* queue) {
enet_peer_remove_incoming_commands(queue, enet_list_begin(queue), enet_list_end(queue));
enet_peer_remove_incoming_commands(queue, enet_list_begin(queue), enet_list_end(queue), NULL);
}

void enet_peer_reset_queues(ENetPeer* peer) {
Expand Down Expand Up @@ -3414,7 +3417,7 @@ extern "C" {
return outgoingCommand;
}

void enet_peer_dispatch_incoming_unreliable_commands(ENetPeer* peer, ENetChannel* channel) {
void enet_peer_dispatch_incoming_unreliable_commands(ENetPeer* peer, ENetChannel* channel, ENetIncomingCommand* queuedCommand) {
ENetListIterator droppedCommand, startCommand, currentCommand;

for (droppedCommand = startCommand = currentCommand = enet_list_begin(&channel->incomingUnreliableCommands); currentCommand != enet_list_end(&channel->incomingUnreliableCommands); currentCommand = enet_list_next(currentCommand)) {
Expand Down Expand Up @@ -3481,10 +3484,10 @@ extern "C" {
droppedCommand = currentCommand;
}

enet_peer_remove_incoming_commands(&channel->incomingUnreliableCommands, enet_list_begin(&channel->incomingUnreliableCommands), droppedCommand);
enet_peer_remove_incoming_commands(&channel->incomingUnreliableCommands, enet_list_begin(&channel->incomingUnreliableCommands), droppedCommand, queuedCommand);
}

void enet_peer_dispatch_incoming_reliable_commands(ENetPeer* peer, ENetChannel* channel) {
void enet_peer_dispatch_incoming_reliable_commands(ENetPeer* peer, ENetChannel* channel, ENetIncomingCommand* queuedCommand) {
ENetListIterator currentCommand;

for (currentCommand = enet_list_begin(&channel->incomingReliableCommands); currentCommand != enet_list_end(&channel->incomingReliableCommands); currentCommand = enet_list_next(currentCommand)) {
Expand Down Expand Up @@ -3513,7 +3516,7 @@ extern "C" {
}

if (!enet_list_empty(&channel->incomingUnreliableCommands))
enet_peer_dispatch_incoming_unreliable_commands(peer, channel);
enet_peer_dispatch_incoming_unreliable_commands(peer, channel, queuedCommand);
}

ENetIncomingCommand* enet_peer_queue_incoming_command(ENetPeer* peer, const ENetProtocol* command, const void* data, size_t dataLength, uint32_t flags, uint32_t fragmentCount) {
Expand Down Expand Up @@ -3656,12 +3659,12 @@ extern "C" {
switch (command->header.command & ENET_PROTOCOL_COMMAND_MASK) {
case ENET_PROTOCOL_COMMAND_SEND_FRAGMENT:
case ENET_PROTOCOL_COMMAND_SEND_RELIABLE:
enet_peer_dispatch_incoming_reliable_commands(peer, channel);
enet_peer_dispatch_incoming_reliable_commands(peer, channel, incomingCommand);

break;

default:
enet_peer_dispatch_incoming_unreliable_commands(peer, channel);
enet_peer_dispatch_incoming_unreliable_commands(peer, channel, incomingCommand);

break;
}
Expand Down

0 comments on commit 8db4523

Please sign in to comment.