mirror of
https://github.com/lsalzman/enet
synced 2024-11-21 14:29:05 -07:00
unreliable fragment fixes
This commit is contained in:
parent
f38c177db0
commit
cfb05d051b
2 changed files with 56 additions and 62 deletions
69
peer.c
69
peer.c
|
@ -262,14 +262,18 @@ enet_peer_reset_outgoing_commands (ENetList * queue)
|
|||
}
|
||||
|
||||
static void
|
||||
enet_peer_reset_incoming_commands (ENetList * queue)
|
||||
enet_peer_remove_incoming_commands (ENetList * queue, ENetListIterator startCommand, ENetListIterator endCommand)
|
||||
{
|
||||
ENetIncomingCommand * incomingCommand;
|
||||
|
||||
while (! enet_list_empty (queue))
|
||||
ENetListIterator currentCommand;
|
||||
|
||||
for (currentCommand = startCommand; currentCommand != endCommand; )
|
||||
{
|
||||
incomingCommand = (ENetIncomingCommand *) enet_list_remove (enet_list_begin (queue));
|
||||
ENetIncomingCommand * incomingCommand = (ENetIncomingCommand *) currentCommand;
|
||||
|
||||
currentCommand = enet_list_next (currentCommand);
|
||||
|
||||
enet_list_remove (& incomingCommand -> incomingCommandList);
|
||||
|
||||
if (incomingCommand -> packet != NULL)
|
||||
{
|
||||
-- incomingCommand -> packet -> referenceCount;
|
||||
|
@ -285,6 +289,12 @@ enet_peer_reset_incoming_commands (ENetList * queue)
|
|||
}
|
||||
}
|
||||
|
||||
static void
|
||||
enet_peer_reset_incoming_commands (ENetList * queue)
|
||||
{
|
||||
enet_peer_remove_incoming_commands(queue, enet_list_begin (queue), enet_list_end(queue));
|
||||
}
|
||||
|
||||
void
|
||||
enet_peer_reset_queues (ENetPeer * peer)
|
||||
{
|
||||
|
@ -577,7 +587,7 @@ enet_peer_setup_outgoing_command (ENetPeer * peer, ENetOutgoingCommand * outgoin
|
|||
case ENET_PROTOCOL_COMMAND_SEND_UNSEQUENCED:
|
||||
outgoingCommand -> command.sendUnsequenced.unsequencedGroup = ENET_HOST_TO_NET_16 (peer -> outgoingUnsequencedGroup);
|
||||
break;
|
||||
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
@ -610,9 +620,9 @@ enet_peer_queue_outgoing_command (ENetPeer * peer, const ENetProtocol * command,
|
|||
void
|
||||
enet_peer_dispatch_incoming_unreliable_commands (ENetPeer * peer, ENetChannel * channel)
|
||||
{
|
||||
ENetListIterator startCommand, currentCommand;
|
||||
ENetListIterator droppedCommand, startCommand, currentCommand;
|
||||
|
||||
for (startCommand = currentCommand = enet_list_begin (& channel -> incomingUnreliableCommands);
|
||||
for (droppedCommand = startCommand = currentCommand = enet_list_begin (& channel -> incomingUnreliableCommands);
|
||||
currentCommand != enet_list_end (& channel -> incomingUnreliableCommands);
|
||||
currentCommand = enet_list_next (currentCommand))
|
||||
{
|
||||
|
@ -627,21 +637,20 @@ enet_peer_dispatch_incoming_unreliable_commands (ENetPeer * peer, ENetChannel *
|
|||
if (incomingCommand -> fragmentsRemaining <= 0)
|
||||
channel -> incomingUnreliableSequenceNumber = incomingCommand -> unreliableSequenceNumber;
|
||||
else
|
||||
if (startCommand == currentCommand)
|
||||
startCommand = enet_list_next (currentCommand);
|
||||
else
|
||||
{
|
||||
if (startCommand != currentCommand)
|
||||
enet_list_move (enet_list_end (& peer -> dispatchedCommands), startCommand, enet_list_previous (currentCommand));
|
||||
|
||||
if (! peer -> needsDispatch)
|
||||
{
|
||||
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;
|
||||
}
|
||||
enet_list_insert (enet_list_end (& peer -> host -> dispatchQueue), & peer -> dispatchList);
|
||||
|
||||
peer -> needsDispatch = 1;
|
||||
}
|
||||
|
||||
startCommand = enet_list_next (currentCommand);
|
||||
|
||||
droppedCommand = startCommand = enet_list_next (currentCommand);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -655,27 +664,11 @@ enet_peer_dispatch_incoming_unreliable_commands (ENetPeer * peer, ENetChannel *
|
|||
|
||||
peer -> needsDispatch = 1;
|
||||
}
|
||||
|
||||
droppedCommand = startCommand = enet_list_next (currentCommand);
|
||||
}
|
||||
|
||||
while (currentCommand != enet_list_begin (& channel -> incomingUnreliableCommands))
|
||||
{
|
||||
ENetIncomingCommand * incomingCommand = (ENetIncomingCommand *) enet_list_previous (currentCommand);
|
||||
|
||||
enet_list_remove (& incomingCommand -> incomingCommandList);
|
||||
|
||||
if (incomingCommand -> packet != NULL)
|
||||
{
|
||||
-- incomingCommand -> packet -> referenceCount;
|
||||
|
||||
if (incomingCommand -> packet -> referenceCount == 0)
|
||||
enet_packet_destroy (incomingCommand -> packet);
|
||||
}
|
||||
|
||||
if (incomingCommand -> fragments != NULL)
|
||||
enet_free (incomingCommand -> fragments);
|
||||
|
||||
enet_free (incomingCommand);
|
||||
}
|
||||
enet_peer_remove_incoming_commands (& channel -> incomingUnreliableCommands, enet_list_begin (& channel -> incomingUnreliableCommands), droppedCommand);
|
||||
}
|
||||
|
||||
void
|
||||
|
|
49
protocol.c
49
protocol.c
|
@ -575,12 +575,6 @@ enet_protocol_handle_send_fragment (ENetHost * host, ENetPeer * peer, const ENet
|
|||
return -1;
|
||||
|
||||
hostCommand.header.reliableSequenceNumber = startSequenceNumber;
|
||||
hostCommand.sendFragment.startSequenceNumber = startSequenceNumber;
|
||||
hostCommand.sendFragment.dataLength = fragmentLength;
|
||||
hostCommand.sendFragment.fragmentNumber = fragmentNumber;
|
||||
hostCommand.sendFragment.fragmentCount = fragmentCount;
|
||||
hostCommand.sendFragment.fragmentOffset = fragmentOffset;
|
||||
hostCommand.sendFragment.totalLength = totalLength;
|
||||
|
||||
startCommand = enet_peer_queue_incoming_command (peer, & hostCommand, packet, fragmentCount);
|
||||
if (startCommand == NULL)
|
||||
|
@ -696,19 +690,11 @@ enet_protocol_handle_send_unreliable_fragment (ENetHost * host, ENetPeer * peer,
|
|||
|
||||
if (startCommand == NULL)
|
||||
{
|
||||
ENetProtocol hostCommand = * command;
|
||||
ENetPacket * packet = enet_packet_create (NULL, totalLength, ENET_PACKET_FLAG_UNRELIABLE_FRAGMENT);
|
||||
if (packet == NULL)
|
||||
return -1;
|
||||
|
||||
hostCommand.sendFragment.startSequenceNumber = startSequenceNumber;
|
||||
hostCommand.sendFragment.dataLength = fragmentLength;
|
||||
hostCommand.sendFragment.fragmentNumber = fragmentNumber;
|
||||
hostCommand.sendFragment.fragmentCount = fragmentCount;
|
||||
hostCommand.sendFragment.fragmentOffset = fragmentOffset;
|
||||
hostCommand.sendFragment.totalLength = totalLength;
|
||||
|
||||
startCommand = enet_peer_queue_incoming_command (peer, & hostCommand, packet, fragmentCount);
|
||||
startCommand = enet_peer_queue_incoming_command (peer, command, packet, fragmentCount);
|
||||
if (startCommand == NULL)
|
||||
return -1;
|
||||
}
|
||||
|
@ -1272,7 +1258,7 @@ enet_protocol_send_unreliable_outgoing_commands (ENetHost * host, ENetPeer * pee
|
|||
buffer + 1 >= & host -> buffers [sizeof (host -> buffers) / sizeof (ENetBuffer)] ||
|
||||
peer -> mtu - host -> packetSize < commandSize ||
|
||||
(outgoingCommand -> packet != NULL &&
|
||||
peer -> mtu - host -> packetSize < commandSize + outgoingCommand -> packet -> dataLength))
|
||||
peer -> mtu - host -> packetSize < commandSize + outgoingCommand -> fragmentLength))
|
||||
{
|
||||
host -> continueSending = 1;
|
||||
|
||||
|
@ -1281,20 +1267,35 @@ enet_protocol_send_unreliable_outgoing_commands (ENetHost * host, ENetPeer * pee
|
|||
|
||||
currentCommand = enet_list_next (currentCommand);
|
||||
|
||||
if (outgoingCommand -> packet != NULL)
|
||||
if (outgoingCommand -> packet != NULL && outgoingCommand -> fragmentOffset == 0)
|
||||
{
|
||||
peer -> packetThrottleCounter += ENET_PEER_PACKET_THROTTLE_COUNTER;
|
||||
peer -> packetThrottleCounter %= ENET_PEER_PACKET_THROTTLE_SCALE;
|
||||
|
||||
if (peer -> packetThrottleCounter > peer -> packetThrottle)
|
||||
{
|
||||
-- outgoingCommand -> packet -> referenceCount;
|
||||
enet_uint16 reliableSequenceNumber = outgoingCommand -> reliableSequenceNumber,
|
||||
unreliableSequenceNumber = outgoingCommand -> unreliableSequenceNumber;
|
||||
for (;;)
|
||||
{
|
||||
-- outgoingCommand -> packet -> referenceCount;
|
||||
|
||||
if (outgoingCommand -> packet -> referenceCount == 0)
|
||||
enet_packet_destroy (outgoingCommand -> packet);
|
||||
if (outgoingCommand -> packet -> referenceCount == 0)
|
||||
enet_packet_destroy (outgoingCommand -> packet);
|
||||
|
||||
enet_list_remove (& outgoingCommand -> outgoingCommandList);
|
||||
enet_free (outgoingCommand);
|
||||
enet_list_remove (& outgoingCommand -> outgoingCommandList);
|
||||
enet_free (outgoingCommand);
|
||||
|
||||
if (currentCommand == enet_list_end (& peer -> outgoingUnreliableCommands))
|
||||
break;
|
||||
|
||||
outgoingCommand = (ENetOutgoingCommand *) currentCommand;
|
||||
if (outgoingCommand -> reliableSequenceNumber != reliableSequenceNumber ||
|
||||
outgoingCommand -> unreliableSequenceNumber != unreliableSequenceNumber)
|
||||
break;
|
||||
|
||||
currentCommand = enet_list_next (currentCommand);
|
||||
}
|
||||
|
||||
continue;
|
||||
}
|
||||
|
@ -1313,8 +1314,8 @@ enet_protocol_send_unreliable_outgoing_commands (ENetHost * host, ENetPeer * pee
|
|||
{
|
||||
++ buffer;
|
||||
|
||||
buffer -> data = outgoingCommand -> packet -> data;
|
||||
buffer -> dataLength = outgoingCommand -> packet -> dataLength;
|
||||
buffer -> data = outgoingCommand -> packet -> data + outgoingCommand -> fragmentOffset;
|
||||
buffer -> dataLength = outgoingCommand -> fragmentLength;
|
||||
|
||||
host -> packetSize += buffer -> dataLength;
|
||||
|
||||
|
|
Loading…
Reference in a new issue