summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorLee Salzman <[email protected]>2012-07-31 16:10:40 +0300
committerLee Salzman <[email protected]>2012-07-31 16:10:40 +0300
commit158955c86b43435a2eae2a4afac33af5964bb9f9 (patch)
treec72ea7314bfdeda03b8162dbb58734216fe57da7
parent22f1236079dec3a4ab18e2307063d1a4a8bcc5c5 (diff)
downloadenet-158955c86b43435a2eae2a4afac33af5964bb9f9.tar.gz
enet-158955c86b43435a2eae2a4afac33af5964bb9f9.zip
unreliable fragment queuing fixes
-rw-r--r--peer.c79
1 files changed, 55 insertions, 24 deletions
diff --git a/peer.c b/peer.c
index 25db03a..56a93f6 100644
--- a/peer.c
+++ b/peer.c
@@ -296,7 +296,7 @@ enet_peer_remove_incoming_commands (ENetList * queue, ENetListIterator startComm
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));
}
void
@@ -678,42 +678,71 @@ enet_peer_dispatch_incoming_unreliable_commands (ENetPeer * peer, ENetChannel *
if ((incomingCommand -> command.header.command & ENET_PROTOCOL_COMMAND_MASK) == ENET_PROTOCOL_COMMAND_SEND_UNSEQUENCED)
continue;
- else
- if (incomingCommand -> reliableSequenceNumber != channel -> incomingReliableSequenceNumber)
- break;
- else
- if (incomingCommand -> fragmentsRemaining <= 0)
- channel -> incomingUnreliableSequenceNumber = incomingCommand -> unreliableSequenceNumber;
- else
- if (startCommand == currentCommand)
- startCommand = enet_list_next (currentCommand);
- else
+
+ if (incomingCommand -> reliableSequenceNumber == channel -> incomingReliableSequenceNumber)
{
- enet_list_move (enet_list_end (& peer -> dispatchedCommands), startCommand, enet_list_previous (currentCommand));
+ if (incomingCommand -> fragmentsRemaining <= 0)
+ {
+ channel -> incomingUnreliableSequenceNumber = incomingCommand -> unreliableSequenceNumber;
+ continue;
+ }
- if (! peer -> needsDispatch)
- {
+ if (startCommand != currentCommand)
+ {
+ enet_list_move (enet_list_end (& peer -> dispatchedCommands), startCommand, enet_list_previous (currentCommand));
+
+ if (! peer -> needsDispatch)
+ {
enet_list_insert (enet_list_end (& peer -> host -> dispatchQueue), & peer -> dispatchList);
peer -> needsDispatch = 1;
- }
+ }
+
+ droppedCommand = currentCommand;
+ }
+ else
+ if (droppedCommand != currentCommand)
+ droppedCommand = enet_list_previous (currentCommand);
+ }
+ else
+ {
+ enet_uint16 reliableWindow = incomingCommand -> reliableSequenceNumber / ENET_PEER_RELIABLE_WINDOW_SIZE,
+ currentWindow = channel -> incomingReliableSequenceNumber / ENET_PEER_RELIABLE_WINDOW_SIZE;
+ if (incomingCommand -> reliableSequenceNumber < channel -> incomingReliableSequenceNumber)
+ reliableWindow += ENET_PEER_RELIABLE_WINDOWS;
+ if (reliableWindow >= currentWindow && reliableWindow < currentWindow + ENET_PEER_FREE_RELIABLE_WINDOWS - 1)
+ break;
+
+ droppedCommand = enet_list_next (currentCommand);
+
+ if (startCommand != currentCommand)
+ {
+ enet_list_move (enet_list_end (& peer -> dispatchedCommands), startCommand, enet_list_previous (currentCommand));
- droppedCommand = startCommand = enet_list_next (currentCommand);
+ if (! peer -> needsDispatch)
+ {
+ enet_list_insert (enet_list_end (& peer -> host -> dispatchQueue), & peer -> dispatchList);
+
+ peer -> needsDispatch = 1;
+ }
+ }
}
+
+ startCommand = enet_list_next (currentCommand);
}
if (startCommand != currentCommand)
{
- enet_list_move (enet_list_end (& peer -> dispatchedCommands), startCommand, enet_list_previous (currentCommand));
+ enet_list_move (enet_list_end (& peer -> dispatchedCommands), startCommand, enet_list_previous (currentCommand));
- if (! peer -> needsDispatch)
- {
- enet_list_insert (enet_list_end (& peer -> host -> dispatchQueue), & peer -> dispatchList);
+ if (! peer -> needsDispatch)
+ {
+ enet_list_insert (enet_list_end (& peer -> host -> dispatchQueue), & peer -> dispatchList);
- peer -> needsDispatch = 1;
- }
+ peer -> needsDispatch = 1;
+ }
- droppedCommand = startCommand = enet_list_next (currentCommand);
+ droppedCommand = currentCommand;
}
enet_peer_remove_incoming_commands (& channel -> incomingUnreliableCommands, enet_list_begin (& channel -> incomingUnreliableCommands), droppedCommand);
@@ -722,6 +751,7 @@ enet_peer_dispatch_incoming_unreliable_commands (ENetPeer * peer, ENetChannel *
void
enet_peer_dispatch_incoming_reliable_commands (ENetPeer * peer, ENetChannel * channel)
{
+ enet_uint16 oldReliableSequenceNumber = channel -> incomingReliableSequenceNumber;
ENetListIterator currentCommand;
for (currentCommand = enet_list_begin (& channel -> incomingReliableCommands);
@@ -754,7 +784,8 @@ enet_peer_dispatch_incoming_reliable_commands (ENetPeer * peer, ENetChannel * ch
peer -> needsDispatch = 1;
}
- enet_peer_dispatch_incoming_unreliable_commands (peer, channel);
+ if (! enet_list_empty (& channel -> incomingUnreliableCommands))
+ enet_peer_dispatch_incoming_unreliable_commands (peer, channel);
}
ENetIncomingCommand *