avoid revisiting peers when continuing to send

This commit is contained in:
Lee Salzman 2023-02-04 22:48:18 -05:00
parent d7e5470cf7
commit ca18dfb8f8
2 changed files with 19 additions and 16 deletions

View file

@ -254,7 +254,8 @@ typedef struct _ENetChannel
typedef enum _ENetPeerFlag typedef enum _ENetPeerFlag
{ {
ENET_PEER_FLAG_NEEDS_DISPATCH = (1 << 0) ENET_PEER_FLAG_NEEDS_DISPATCH = (1 << 0),
ENET_PEER_FLAG_CONTINUE_SENDING = (1 << 1)
} ENetPeerFlag; } ENetPeerFlag;
/** /**
@ -378,7 +379,7 @@ typedef struct _ENetHost
size_t channelLimit; /**< maximum number of channels allowed for connected peers */ size_t channelLimit; /**< maximum number of channels allowed for connected peers */
enet_uint32 serviceTime; enet_uint32 serviceTime;
ENetList dispatchQueue; ENetList dispatchQueue;
int continueSending; enet_uint32 totalQueued;
size_t packetSize; size_t packetSize;
enet_uint16 headerFlags; enet_uint16 headerFlags;
ENetProtocol commands [ENET_PROTOCOL_MAXIMUM_PACKET_COMMANDS]; ENetProtocol commands [ENET_PROTOCOL_MAXIMUM_PACKET_COMMANDS];
@ -401,7 +402,6 @@ typedef struct _ENetHost
size_t duplicatePeers; /**< optional number of allowed peers from duplicate IPs, defaults to ENET_PROTOCOL_MAXIMUM_PEER_ID */ size_t duplicatePeers; /**< optional number of allowed peers from duplicate IPs, defaults to ENET_PROTOCOL_MAXIMUM_PEER_ID */
size_t maximumPacketSize; /**< the maximum allowable packet size that may be sent or received on a peer */ size_t maximumPacketSize; /**< the maximum allowable packet size that may be sent or received on a peer */
size_t maximumWaitingData; /**< the maximum aggregate amount of buffer space a peer may use waiting for packets to be delivered */ size_t maximumWaitingData; /**< the maximum aggregate amount of buffer space a peer may use waiting for packets to be delivered */
enet_uint32 totalQueued;
} ENetHost; } ENetHost;
/** /**

View file

@ -1304,7 +1304,7 @@ enet_protocol_send_acknowledgements (ENetHost * host, ENetPeer * peer)
buffer >= & host -> buffers [sizeof (host -> buffers) / sizeof (ENetBuffer)] || buffer >= & host -> buffers [sizeof (host -> buffers) / sizeof (ENetBuffer)] ||
peer -> mtu - host -> packetSize < sizeof (ENetProtocolAcknowledge)) peer -> mtu - host -> packetSize < sizeof (ENetProtocolAcknowledge))
{ {
host -> continueSending = 1; peer -> flags |= ENET_PEER_FLAG_CONTINUE_SENDING;
break; break;
} }
@ -1479,8 +1479,8 @@ enet_protocol_check_outgoing_commands (ENetHost * host, ENetPeer * peer)
(outgoingCommand -> packet != NULL && (outgoingCommand -> packet != NULL &&
(enet_uint16) (peer -> mtu - host -> packetSize) < (enet_uint16) (commandSize + outgoingCommand -> fragmentLength))) (enet_uint16) (peer -> mtu - host -> packetSize) < (enet_uint16) (commandSize + outgoingCommand -> fragmentLength)))
{ {
host -> continueSending = 1; peer -> flags |= ENET_PEER_FLAG_CONTINUE_SENDING;
break; break;
} }
@ -1596,22 +1596,21 @@ enet_protocol_send_outgoing_commands (ENetHost * host, ENetEvent * event, int ch
{ {
enet_uint8 headerData [sizeof (ENetProtocolHeader) + sizeof (enet_uint32)]; enet_uint8 headerData [sizeof (ENetProtocolHeader) + sizeof (enet_uint32)];
ENetProtocolHeader * header = (ENetProtocolHeader *) headerData; ENetProtocolHeader * header = (ENetProtocolHeader *) headerData;
ENetPeer * currentPeer; int continueSending = 0, sentLength = 0;
int sentLength;
size_t shouldCompress = 0; size_t shouldCompress = 0;
host -> continueSending = 1;
while (host -> continueSending) for (int sendPass = 0; sendPass <= continueSending; ++ sendPass)
for (host -> continueSending = 0, for (ENetPeer * currentPeer = host -> peers;
currentPeer = host -> peers;
currentPeer < & host -> peers [host -> peerCount]; currentPeer < & host -> peers [host -> peerCount];
++ currentPeer) ++ currentPeer)
{ {
if (currentPeer -> state == ENET_PEER_STATE_DISCONNECTED || if (currentPeer -> state == ENET_PEER_STATE_DISCONNECTED ||
currentPeer -> state == ENET_PEER_STATE_ZOMBIE) currentPeer -> state == ENET_PEER_STATE_ZOMBIE ||
(sendPass > 0 && ! (currentPeer -> flags & ENET_PEER_FLAG_CONTINUE_SENDING)))
continue; continue;
currentPeer -> flags &= ~ ENET_PEER_FLAG_CONTINUE_SENDING;
host -> headerFlags = 0; host -> headerFlags = 0;
host -> commandCount = 0; host -> commandCount = 0;
host -> bufferCount = 1; host -> bufferCount = 1;
@ -1628,7 +1627,7 @@ enet_protocol_send_outgoing_commands (ENetHost * host, ENetEvent * event, int ch
if (event != NULL && event -> type != ENET_EVENT_TYPE_NONE) if (event != NULL && event -> type != ENET_EVENT_TYPE_NONE)
return 1; return 1;
else else
continue; goto nextPeer;
} }
if (((enet_list_empty (& currentPeer -> outgoingCommands) && if (((enet_list_empty (& currentPeer -> outgoingCommands) &&
@ -1643,7 +1642,7 @@ enet_protocol_send_outgoing_commands (ENetHost * host, ENetEvent * event, int ch
} }
if (host -> commandCount == 0) if (host -> commandCount == 0)
continue; goto nextPeer;
if (currentPeer -> packetLossEpoch == 0) if (currentPeer -> packetLossEpoch == 0)
currentPeer -> packetLossEpoch = host -> serviceTime; currentPeer -> packetLossEpoch = host -> serviceTime;
@ -1723,6 +1722,10 @@ enet_protocol_send_outgoing_commands (ENetHost * host, ENetEvent * event, int ch
host -> totalSentData += sentLength; host -> totalSentData += sentLength;
host -> totalSentPackets ++; host -> totalSentPackets ++;
nextPeer:
if (currentPeer -> flags & ENET_PEER_FLAG_CONTINUE_SENDING)
continueSending = sendPass + 1;
} }
return 0; return 0;