diff options
author | Lee Salzman <[email protected]> | 2023-02-04 22:48:18 -0500 |
---|---|---|
committer | Lee Salzman <[email protected]> | 2023-02-04 22:48:18 -0500 |
commit | ca18dfb8f8f442808add71464f893c9da40afc56 (patch) | |
tree | b4767ead6a8358b1997794de755d30730c1997a6 | |
parent | d7e5470cf7dd4858a9da90aa92a79ea82754ffde (diff) | |
download | enet-ca18dfb8f8f442808add71464f893c9da40afc56.tar.gz enet-ca18dfb8f8f442808add71464f893c9da40afc56.zip |
avoid revisiting peers when continuing to send
-rw-r--r-- | include/enet/enet.h | 6 | ||||
-rw-r--r-- | protocol.c | 29 |
2 files changed, 19 insertions, 16 deletions
diff --git a/include/enet/enet.h b/include/enet/enet.h index 0dd7589..b52a629 100644 --- a/include/enet/enet.h +++ b/include/enet/enet.h @@ -254,7 +254,8 @@ typedef struct _ENetChannel 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; /** @@ -378,7 +379,7 @@ typedef struct _ENetHost size_t channelLimit; /**< maximum number of channels allowed for connected peers */ enet_uint32 serviceTime; ENetList dispatchQueue; - int continueSending; + enet_uint32 totalQueued; size_t packetSize; enet_uint16 headerFlags; 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 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 */ - enet_uint32 totalQueued; } ENetHost; /** @@ -1304,7 +1304,7 @@ enet_protocol_send_acknowledgements (ENetHost * host, ENetPeer * peer) buffer >= & host -> buffers [sizeof (host -> buffers) / sizeof (ENetBuffer)] || peer -> mtu - host -> packetSize < sizeof (ENetProtocolAcknowledge)) { - host -> continueSending = 1; + peer -> flags |= ENET_PEER_FLAG_CONTINUE_SENDING; break; } @@ -1479,8 +1479,8 @@ enet_protocol_check_outgoing_commands (ENetHost * host, ENetPeer * peer) (outgoingCommand -> packet != NULL && (enet_uint16) (peer -> mtu - host -> packetSize) < (enet_uint16) (commandSize + outgoingCommand -> fragmentLength))) { - host -> continueSending = 1; - + peer -> flags |= ENET_PEER_FLAG_CONTINUE_SENDING; + break; } @@ -1596,22 +1596,21 @@ enet_protocol_send_outgoing_commands (ENetHost * host, ENetEvent * event, int ch { enet_uint8 headerData [sizeof (ENetProtocolHeader) + sizeof (enet_uint32)]; ENetProtocolHeader * header = (ENetProtocolHeader *) headerData; - ENetPeer * currentPeer; - int sentLength; + int continueSending = 0, sentLength = 0; size_t shouldCompress = 0; - - host -> continueSending = 1; - while (host -> continueSending) - for (host -> continueSending = 0, - currentPeer = host -> peers; + for (int sendPass = 0; sendPass <= continueSending; ++ sendPass) + for (ENetPeer * currentPeer = host -> peers; currentPeer < & host -> peers [host -> peerCount]; ++ currentPeer) { 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; + currentPeer -> flags &= ~ ENET_PEER_FLAG_CONTINUE_SENDING; + host -> headerFlags = 0; host -> commandCount = 0; 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) return 1; else - continue; + goto nextPeer; } 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) - continue; + goto nextPeer; if (currentPeer -> packetLossEpoch == 0) currentPeer -> packetLossEpoch = host -> serviceTime; @@ -1723,6 +1722,10 @@ enet_protocol_send_outgoing_commands (ENetHost * host, ENetEvent * event, int ch host -> totalSentData += sentLength; host -> totalSentPackets ++; + + nextPeer: + if (currentPeer -> flags & ENET_PEER_FLAG_CONTINUE_SENDING) + continueSending = sendPass + 1; } return 0; |