Skip to content

Commit

Permalink
Fix packets flagged as unthrottled
Browse files Browse the repository at this point in the history
  • Loading branch information
nxrighthere committed Aug 29, 2020
1 parent 5cb73c4 commit 5b0194d
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 7 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ Definitions of a flags for `Peer.Send()` function:

`PacketFlags.Instant` a packet will not be bundled with other packets at a next service iteration and sent instantly instead. This delivery type trades multiplexing efficiency in favor of latency. The same packet can't be used for multiple `Peer.Send()` calls.

`PacketFlags.Crucial` a packet that was enqueued for sending unreliably should not be dropped due to throttling and sent if possible.
`PacketFlags.Unthrottled` a packet that was enqueued for sending unreliably should not be dropped due to throttling and sent if possible.

`PacketFlags.Sent` a packet was sent from all queues it has entered.

Expand Down
4 changes: 2 additions & 2 deletions Source/Managed/ENet.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public enum PacketFlags {
NoAllocate = 1 << 2,
UnreliableFragmented = 1 << 3,
Instant = 1 << 4,
Crucial = 1 << 5,
Unthrottled = 1 << 5,
Sent = 1 << 8
}

Expand Down Expand Up @@ -928,7 +928,7 @@ public static class Library {
public const uint timeoutLimit = 32;
public const uint timeoutMinimum = 5000;
public const uint timeoutMaximum = 30000;
public const uint version = (2 << 16) | (4 << 8) | (1);
public const uint version = (2 << 16) | (4 << 8) | (2);

public static bool Initialize() {
if (Native.enet_linked_version() != version)
Expand Down
8 changes: 4 additions & 4 deletions Source/Native/enet.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@

#define ENET_VERSION_MAJOR 2
#define ENET_VERSION_MINOR 4
#define ENET_VERSION_PATCH 1
#define ENET_VERSION_PATCH 2
#define ENET_VERSION_CREATE(major, minor, patch) (((major) << 16) | ((minor) << 8) | (patch))
#define ENET_VERSION_GET_MAJOR(version) (((version) >> 16) & 0xFF)
#define ENET_VERSION_GET_MINOR(version) (((version) >> 8) & 0xFF)
Expand Down Expand Up @@ -443,7 +443,7 @@ extern "C" {
ENET_PACKET_FLAG_NO_ALLOCATE = (1 << 2),
ENET_PACKET_FLAG_UNRELIABLE_FRAGMENTED = (1 << 3),
ENET_PACKET_FLAG_INSTANT = (1 << 4),
ENET_PACKET_FLAG_CRUCIAL = (1 << 5),
ENET_PACKET_FLAG_UNTHROTTLED = (1 << 5),
ENET_PACKET_FLAG_SENT = (1 << 8)
} ENetPacketFlag;

Expand Down Expand Up @@ -2652,7 +2652,7 @@ extern "C" {
host->headerFlags |= ENET_PROTOCOL_HEADER_FLAG_SENT_TIME;
peer->reliableDataInTransit += outgoingCommand->fragmentLength;
} else {
if (outgoingCommand->packet != NULL && outgoingCommand->fragmentOffset == 0) {
if (outgoingCommand->packet != NULL && outgoingCommand->fragmentOffset == 0 && !(outgoingCommand->packet->flags & (ENET_PACKET_FLAG_UNTHROTTLED))) {
peer->packetThrottleCounter += ENET_PEER_PACKET_THROTTLE_COUNTER;
peer->packetThrottleCounter %= ENET_PEER_PACKET_THROTTLE_SCALE;

Expand Down Expand Up @@ -2953,7 +2953,7 @@ extern "C" {
int enet_peer_throttle(ENetPeer* peer, uint32_t rtt) {
if (peer->lastRoundTripTime <= peer->lastRoundTripTimeVariance) {
peer->packetThrottle = peer->packetThrottleLimit;
} else if (rtt < peer->lastRoundTripTime + (peer -> lastRoundTripTimeVariance + 1) / 2) {
} else if (rtt < peer->lastRoundTripTime + (peer->lastRoundTripTimeVariance + 1) / 2) {
peer->packetThrottle += peer->packetThrottleAcceleration;

if (peer->packetThrottle > peer->packetThrottleLimit)
Expand Down

0 comments on commit 5b0194d

Please sign in to comment.