Expand Up
@@ -66,7 +66,7 @@ enet_peer_throttle (ENetPeer * peer, enet_uint32 rtt)
peer -> packetThrottle = peer -> packetThrottleLimit;
}
else
if (rtt < peer -> lastRoundTripTime)
if (rtt <= peer -> lastRoundTripTime)
{
peer -> packetThrottle += peer -> packetThrottleAcceleration;
Expand All
@@ -90,6 +90,13 @@ enet_peer_throttle (ENetPeer * peer, enet_uint32 rtt)
}
/* * Queues a packet to be sent.
On success, ENet will assume ownership of the packet, and so enet_packet_destroy
should not be called on it thereafter. On failure, the caller still must destroy
the packet on its own as ENet has not queued the packet. The caller can also
check the packet's referenceCount field after sending to check if ENet queued
the packet and thus incremented the referenceCount.
@param peer destination for the packet
@param channelID channel on which to send
@param packet packet to send
Expand All
@@ -99,7 +106,7 @@ enet_peer_throttle (ENetPeer * peer, enet_uint32 rtt)
int
enet_peer_send (ENetPeer * peer, enet_uint8 channelID, ENetPacket * packet)
{
ENetChannel * channel = & peer -> channels [channelID] ;
ENetChannel * channel;
ENetProtocol command;
size_t fragmentLength;
Expand All
@@ -108,6 +115,7 @@ enet_peer_send (ENetPeer * peer, enet_uint8 channelID, ENetPacket * packet)
packet -> dataLength > peer -> host -> maximumPacketSize)
return -1 ;
channel = & peer -> channels [channelID];
fragmentLength = peer -> mtu - sizeof (ENetProtocolHeader) - sizeof (ENetProtocolSendFragment);
if (peer -> host -> checksum != NULL )
fragmentLength -= sizeof (enet_uint32);
Expand Down
Expand Up
@@ -268,7 +276,7 @@ enet_peer_reset_outgoing_commands (ENetList * queue)
}
static void
enet_peer_remove_incoming_commands (ENetList * queue, ENetListIterator startCommand, ENetListIterator endCommand)
enet_peer_remove_incoming_commands (ENetList * queue, ENetListIterator startCommand, ENetListIterator endCommand, ENetIncomingCommand * excludeCommand )
{
ENetListIterator currentCommand;
Expand All
@@ -278,6 +286,9 @@ enet_peer_remove_incoming_commands (ENetList * queue, ENetListIterator startComm
currentCommand = enet_list_next (currentCommand);
if (incomingCommand == excludeCommand)
continue ;
enet_list_remove (& incomingCommand -> incomingCommandList);
if (incomingCommand -> packet != NULL )
Expand All
@@ -298,28 +309,27 @@ 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), NULL );
}
void
enet_peer_reset_queues (ENetPeer * peer)
{
ENetChannel * channel;
if (peer -> needsDispatch )
if (peer -> flags & ENET_PEER_FLAG_NEEDS_DISPATCH )
{
enet_list_remove (& peer -> dispatchList);
peer -> needsDispatch = 0 ;
peer -> flags &= ~ ENET_PEER_FLAG_NEEDS_DISPATCH ;
}
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 -> sentUnreliableCommands);
enet_peer_reset_outgoing_commands (& peer -> outgoingReliableCommands);
enet_peer_reset_outgoing_commands (& peer -> outgoingUnreliableCommands);
enet_peer_reset_outgoing_commands (& peer -> outgoingCommands);
enet_peer_reset_outgoing_commands (& peer -> outgoingSendReliableCommands);
enet_peer_reset_incoming_commands (& peer -> dispatchedCommands);
if (peer -> channels != NULL && peer -> channelCount > 0 )
Expand Down
Expand Up
@@ -418,6 +428,7 @@ enet_peer_reset (ENetPeer * peer)
peer -> outgoingUnsequencedGroup = 0 ;
peer -> eventData = 0 ;
peer -> totalWaitingData = 0 ;
peer -> flags = 0 ;
memset (peer -> unsequencedWindow, 0 , sizeof (peer -> unsequencedWindow));
Expand Down
Expand Up
@@ -560,6 +571,17 @@ enet_peer_disconnect (ENetPeer * peer, enet_uint32 data)
}
}
int
enet_peer_has_outgoing_commands (ENetPeer * peer)
{
if (enet_list_empty (& peer -> outgoingCommands) &&
enet_list_empty (& peer -> outgoingSendReliableCommands) &&
enet_list_empty (& peer -> sentReliableCommands))
return 0 ;
return 1 ;
}
/* * Request a disconnection from a peer, but only after all queued outgoing packets are sent.
@param peer peer to request a disconnection
@param data data describing the disconnection
Expand All
@@ -570,9 +592,7 @@ void
enet_peer_disconnect_later (ENetPeer * peer, enet_uint32 data)
{
if ((peer -> state == ENET_PEER_STATE_CONNECTED || peer -> state == ENET_PEER_STATE_DISCONNECT_LATER) &&
! (enet_list_empty (& peer -> outgoingReliableCommands) &&
enet_list_empty (& peer -> outgoingUnreliableCommands) &&
enet_list_empty (& peer -> sentReliableCommands)))
enet_peer_has_outgoing_commands (peer))
{
peer -> state = ENET_PEER_STATE_DISCONNECT_LATER;
peer -> eventData = data;
Expand Down
Expand Up
@@ -616,8 +636,6 @@ enet_peer_queue_acknowledgement (ENetPeer * peer, const ENetProtocol * command,
void
enet_peer_setup_outgoing_command (ENetPeer * peer, ENetOutgoingCommand * outgoingCommand)
{
ENetChannel * channel = & peer -> channels [outgoingCommand -> command.header .channelID ];
peer -> outgoingDataTotal += enet_protocol_command_size (outgoingCommand -> command.header .command ) + outgoingCommand -> fragmentLength;
if (outgoingCommand -> command.header .channelID == 0xFF )
Expand All
@@ -628,36 +646,40 @@ enet_peer_setup_outgoing_command (ENetPeer * peer, ENetOutgoingCommand * outgoin
outgoingCommand -> unreliableSequenceNumber = 0 ;
}
else
if (outgoingCommand -> command.header .command & ENET_PROTOCOL_COMMAND_FLAG_ACKNOWLEDGE)
{
++ channel -> outgoingReliableSequenceNumber;
channel -> outgoingUnreliableSequenceNumber = 0 ;
ENetChannel * channel = & peer -> channels [outgoingCommand -> command.header .channelID ];
outgoingCommand -> reliableSequenceNumber = channel -> outgoingReliableSequenceNumber;
outgoingCommand -> unreliableSequenceNumber = 0 ;
}
else
if (outgoingCommand -> command.header .command & ENET_PROTOCOL_COMMAND_FLAG_UNSEQUENCED)
{
++ peer -> outgoingUnsequencedGroup;
if (outgoingCommand -> command.header .command & ENET_PROTOCOL_COMMAND_FLAG_ACKNOWLEDGE)
{
++ channel -> outgoingReliableSequenceNumber;
channel -> outgoingUnreliableSequenceNumber = 0 ;
outgoingCommand -> reliableSequenceNumber = 0 ;
outgoingCommand -> unreliableSequenceNumber = 0 ;
}
else
{
if (outgoingCommand -> fragmentOffset == 0 )
++ channel -> outgoingUnreliableSequenceNumber;
outgoingCommand -> reliableSequenceNumber = channel -> outgoingReliableSequenceNumber;
outgoingCommand -> unreliableSequenceNumber = channel -> outgoingUnreliableSequenceNumber;
outgoingCommand -> reliableSequenceNumber = channel -> outgoingReliableSequenceNumber;
outgoingCommand -> unreliableSequenceNumber = 0 ;
}
else
if (outgoingCommand -> command.header .command & ENET_PROTOCOL_COMMAND_FLAG_UNSEQUENCED)
{
++ peer -> outgoingUnsequencedGroup;
outgoingCommand -> reliableSequenceNumber = 0 ;
outgoingCommand -> unreliableSequenceNumber = 0 ;
}
else
{
if (outgoingCommand -> fragmentOffset == 0 )
++ channel -> outgoingUnreliableSequenceNumber;
outgoingCommand -> reliableSequenceNumber = channel -> outgoingReliableSequenceNumber;
outgoingCommand -> unreliableSequenceNumber = channel -> outgoingUnreliableSequenceNumber;
}
}
outgoingCommand -> sendAttempts = 0 ;
outgoingCommand -> sentTime = 0 ;
outgoingCommand -> roundTripTimeout = 0 ;
outgoingCommand -> roundTripTimeoutLimit = 0 ;
outgoingCommand -> command.header .reliableSequenceNumber = ENET_HOST_TO_NET_16 (outgoingCommand -> reliableSequenceNumber);
outgoingCommand -> queueTime = ++ peer -> host -> totalQueued;
switch (outgoingCommand -> command.header .command & ENET_PROTOCOL_COMMAND_MASK)
{
Expand All
@@ -668,15 +690,16 @@ 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 ;
}
if (outgoingCommand -> command.header .command & ENET_PROTOCOL_COMMAND_FLAG_ACKNOWLEDGE)
enet_list_insert (enet_list_end (& peer -> outgoingReliableCommands), outgoingCommand);
if ((outgoingCommand -> command.header .command & ENET_PROTOCOL_COMMAND_FLAG_ACKNOWLEDGE) != 0 &&
outgoingCommand -> packet != NULL )
enet_list_insert (enet_list_end (& peer -> outgoingSendReliableCommands), outgoingCommand);
else
enet_list_insert (enet_list_end (& peer -> outgoingUnreliableCommands ), outgoingCommand);
enet_list_insert (enet_list_end (& peer -> outgoingCommands ), outgoingCommand);
}
ENetOutgoingCommand *
Expand All
@@ -699,7 +722,7 @@ enet_peer_queue_outgoing_command (ENetPeer * peer, const ENetProtocol * command,
}
void
enet_peer_dispatch_incoming_unreliable_commands (ENetPeer * peer, ENetChannel * channel)
enet_peer_dispatch_incoming_unreliable_commands (ENetPeer * peer, ENetChannel * channel, ENetIncomingCommand * queuedCommand )
{
ENetListIterator droppedCommand, startCommand, currentCommand;
Expand All
@@ -724,11 +747,11 @@ enet_peer_dispatch_incoming_unreliable_commands (ENetPeer * peer, ENetChannel *
{
enet_list_move (enet_list_end (& peer -> dispatchedCommands), startCommand, enet_list_previous (currentCommand));
if (! peer -> needsDispatch )
if (! ( peer -> flags & ENET_PEER_FLAG_NEEDS_DISPATCH) )
{
enet_list_insert (enet_list_end (& peer -> host -> dispatchQueue), & peer -> dispatchList);
peer -> needsDispatch = 1 ;
peer -> flags |= ENET_PEER_FLAG_NEEDS_DISPATCH ;
}
droppedCommand = currentCommand;
Expand All
@@ -752,11 +775,11 @@ enet_peer_dispatch_incoming_unreliable_commands (ENetPeer * peer, ENetChannel *
{
enet_list_move (enet_list_end (& peer -> dispatchedCommands), startCommand, enet_list_previous (currentCommand));
if (! peer -> needsDispatch )
if (! ( peer -> flags & ENET_PEER_FLAG_NEEDS_DISPATCH) )
{
enet_list_insert (enet_list_end (& peer -> host -> dispatchQueue), & peer -> dispatchList);
peer -> needsDispatch = 1 ;
peer -> flags |= ENET_PEER_FLAG_NEEDS_DISPATCH ;
}
}
}
Expand All
@@ -768,21 +791,21 @@ enet_peer_dispatch_incoming_unreliable_commands (ENetPeer * peer, ENetChannel *
{
enet_list_move (enet_list_end (& peer -> dispatchedCommands), startCommand, enet_list_previous (currentCommand));
if (! peer -> needsDispatch )
if (! ( peer -> flags & ENET_PEER_FLAG_NEEDS_DISPATCH) )
{
enet_list_insert (enet_list_end (& peer -> host -> dispatchQueue), & peer -> dispatchList);
peer -> needsDispatch = 1 ;
peer -> flags |= ENET_PEER_FLAG_NEEDS_DISPATCH ;
}
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)
enet_peer_dispatch_incoming_reliable_commands (ENetPeer * peer, ENetChannel * channel, ENetIncomingCommand * queuedCommand )
{
ENetListIterator currentCommand;
Expand All
@@ -809,15 +832,15 @@ enet_peer_dispatch_incoming_reliable_commands (ENetPeer * peer, ENetChannel * ch
enet_list_move (enet_list_end (& peer -> dispatchedCommands), enet_list_begin (& channel -> incomingReliableCommands), enet_list_previous (currentCommand));
if (! peer -> needsDispatch )
if (! ( peer -> flags & ENET_PEER_FLAG_NEEDS_DISPATCH) )
{
enet_list_insert (enet_list_end (& peer -> host -> dispatchQueue), & peer -> dispatchList);
peer -> needsDispatch = 1 ;
peer -> flags |= ENET_PEER_FLAG_NEEDS_DISPATCH ;
}
if (! enet_list_empty (& channel -> incomingUnreliableCommands))
enet_peer_dispatch_incoming_unreliable_commands (peer, channel);
enet_peer_dispatch_incoming_unreliable_commands (peer, channel, queuedCommand );
}
ENetIncomingCommand *
Expand Down
Expand Up
@@ -975,11 +998,11 @@ enet_peer_queue_incoming_command (ENetPeer * peer, const ENetProtocol * command,
{
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