From 574947fd40d9de64e8271fec03cec216f31a0e00 Mon Sep 17 00:00:00 2001 From: Lee Salzman Date: Mon, 31 Jan 2011 08:39:44 +0000 Subject: [PATCH] fix bug with tracking reliable data in transit git-svn-id: svn://svn.code.sf.net/p/actiongame/code/trunk/ac@6054 e016b1c5-ed68-44aa-a2f7-31cac88cffde --- source/enet/ChangeLog | 1 + source/enet/protocol.c | 88 ++++++++++++++++++++++------------------- source/lib/enet.lib | Bin 44848 -> 44896 bytes 3 files changed, 49 insertions(+), 40 deletions(-) diff --git a/source/enet/ChangeLog b/source/enet/ChangeLog index 553c03d7..3b1249d1 100644 --- a/source/enet/ChangeLog +++ b/source/enet/ChangeLog @@ -1,5 +1,6 @@ ENet CVS (January 31, 2011): +* fixed bug in tracking of reliable data in transit * reliable data window size now scales with the throttle * fixed bug in fragment length calculation when checksums are used diff --git a/source/enet/protocol.c b/source/enet/protocol.c index 3c4347da..2237ba84 100755 --- a/source/enet/protocol.c +++ b/source/enet/protocol.c @@ -172,6 +172,7 @@ enet_protocol_remove_sent_reliable_command (ENetPeer * peer, enet_uint16 reliabl ENetOutgoingCommand * outgoingCommand; ENetListIterator currentCommand; ENetProtocolCommand commandNumber; + int wasSent = 1; for (currentCommand = enet_list_begin (& peer -> sentReliableCommands); currentCommand != enet_list_end (& peer -> sentReliableCommands); @@ -201,6 +202,8 @@ enet_protocol_remove_sent_reliable_command (ENetPeer * peer, enet_uint16 reliabl if (currentCommand == enet_list_end (& peer -> outgoingReliableCommands)) return ENET_PROTOCOL_COMMAND_NONE; + + wasSent = 0; } if (channelID < peer -> channelCount) @@ -221,7 +224,8 @@ enet_protocol_remove_sent_reliable_command (ENetPeer * peer, enet_uint16 reliabl if (outgoingCommand -> packet != NULL) { - peer -> reliableDataInTransit -= outgoingCommand -> fragmentLength; + if (wasSent) + peer -> reliableDataInTransit -= outgoingCommand -> fragmentLength; -- outgoingCommand -> packet -> referenceCount; @@ -1252,7 +1256,7 @@ enet_protocol_check_timeouts (ENetHost * host, ENetPeer * peer, ENetEvent * even return 0; } -static void +static int enet_protocol_send_reliable_outgoing_commands (ENetHost * host, ENetPeer * peer) { ENetProtocol * command = & host -> commands [host -> commandCount]; @@ -1262,7 +1266,7 @@ enet_protocol_send_reliable_outgoing_commands (ENetHost * host, ENetPeer * peer) ENetChannel *channel; enet_uint16 reliableWindow; size_t commandSize; - int windowExceeded = 0; + int windowExceeded = 0, windowWrap = 0, canPing = 1; currentCommand = enet_list_begin (& peer -> outgoingReliableCommands); @@ -1272,51 +1276,54 @@ enet_protocol_send_reliable_outgoing_commands (ENetHost * host, ENetPeer * peer) channel = outgoingCommand -> command.header.channelID < peer -> channelCount ? & peer -> channels [outgoingCommand -> command.header.channelID] : NULL; reliableWindow = outgoingCommand -> reliableSequenceNumber / ENET_PEER_RELIABLE_WINDOW_SIZE; - if (channel != NULL && - outgoingCommand -> sendAttempts < 1 && - ! (outgoingCommand -> reliableSequenceNumber % ENET_PEER_RELIABLE_WINDOW_SIZE) && - (channel -> reliableWindows [(reliableWindow + ENET_PEER_RELIABLE_WINDOWS - 1) % ENET_PEER_RELIABLE_WINDOWS] >= ENET_PEER_RELIABLE_WINDOW_SIZE || - channel -> usedReliableWindows & ((((1 << ENET_PEER_FREE_RELIABLE_WINDOWS) - 1) << reliableWindow) | - (((1 << ENET_PEER_FREE_RELIABLE_WINDOWS) - 1) >> (ENET_PEER_RELIABLE_WINDOW_SIZE - reliableWindow))))) - break; - - if (windowExceeded && outgoingCommand -> packet != NULL) + if (channel != NULL) { - currentCommand = enet_list_next (currentCommand); - - continue; + if (! windowWrap && + outgoingCommand -> sendAttempts < 1 && + ! (outgoingCommand -> reliableSequenceNumber % ENET_PEER_RELIABLE_WINDOW_SIZE) && + (channel -> reliableWindows [(reliableWindow + ENET_PEER_RELIABLE_WINDOWS - 1) % ENET_PEER_RELIABLE_WINDOWS] >= ENET_PEER_RELIABLE_WINDOW_SIZE || + channel -> usedReliableWindows & ((((1 << ENET_PEER_FREE_RELIABLE_WINDOWS) - 1) << reliableWindow) | + (((1 << ENET_PEER_FREE_RELIABLE_WINDOWS) - 1) >> (ENET_PEER_RELIABLE_WINDOW_SIZE - reliableWindow))))) + windowWrap = 1; + if (windowWrap) + { + currentCommand = enet_list_next (currentCommand); + + continue; + } } + + if (outgoingCommand -> packet != NULL) + { + if (! windowExceeded) + { + enet_uint32 windowSize = (peer -> packetThrottle * peer -> windowSize) / ENET_PEER_PACKET_THROTTLE_SCALE; + + if (peer -> reliableDataInTransit + outgoingCommand -> fragmentLength > ENET_MAX (windowSize, peer -> mtu)) + windowExceeded = 1; + } + if (windowExceeded) + { + currentCommand = enet_list_next (currentCommand); + + continue; + } + } + + canPing = 0; commandSize = commandSizes [outgoingCommand -> command.header.command & ENET_PROTOCOL_COMMAND_MASK]; if (command >= & host -> commands [sizeof (host -> commands) / sizeof (ENetProtocol)] || buffer + 1 >= & host -> buffers [sizeof (host -> buffers) / sizeof (ENetBuffer)] || - peer -> mtu - host -> packetSize < commandSize) + peer -> mtu - host -> packetSize < commandSize || + (outgoingCommand -> packet != NULL && + (enet_uint16) (peer -> mtu - host -> packetSize) < (enet_uint16) (commandSize + outgoingCommand -> fragmentLength))) { host -> continueSending = 1; break; } - if (outgoingCommand -> packet != NULL) - { - enet_uint32 windowSize = (peer -> packetThrottle * peer -> windowSize) / ENET_PEER_PACKET_THROTTLE_SCALE; - - if (peer -> reliableDataInTransit + outgoingCommand -> fragmentLength > ENET_MAX (windowSize, peer -> mtu)) - { - windowExceeded = 1; - currentCommand = enet_list_next (currentCommand); - - continue; - } - - if ((enet_uint16) (peer -> mtu - host -> packetSize) < (enet_uint16) (commandSize + outgoingCommand -> fragmentLength)) - { - host -> continueSending = 1; - - break; - } - } - currentCommand = enet_list_next (currentCommand); if (channel != NULL && outgoingCommand -> sendAttempts < 1) @@ -1369,6 +1376,8 @@ enet_protocol_send_reliable_outgoing_commands (ENetHost * host, ENetPeer * peer) host -> commandCount = command - host -> commands; host -> bufferCount = buffer - host -> buffers; + + return canPing; } static int @@ -1406,10 +1415,9 @@ enet_protocol_send_outgoing_commands (ENetHost * host, ENetEvent * event, int ch enet_protocol_check_timeouts (host, currentPeer, event) == 1) return 1; - if (! enet_list_empty (& currentPeer -> outgoingReliableCommands)) - enet_protocol_send_reliable_outgoing_commands (host, currentPeer); - else - if (enet_list_empty (& currentPeer -> sentReliableCommands) && + if ((enet_list_empty (& currentPeer -> outgoingReliableCommands) || + enet_protocol_send_reliable_outgoing_commands (host, currentPeer)) && + enet_list_empty (& currentPeer -> sentReliableCommands) && ENET_TIME_DIFFERENCE (host -> serviceTime, currentPeer -> lastReceiveTime) >= ENET_PEER_PING_INTERVAL && currentPeer -> mtu - host -> packetSize >= sizeof (ENetProtocolPing)) { diff --git a/source/lib/enet.lib b/source/lib/enet.lib index 36af4f9784d6d73c79c0150a95ce582de6405d52..27877ab34d972b6df4c1eaebd376b5ccc78538b6 100644 GIT binary patch delta 5046 zcmbtYdr(tX8ow73M5Nw`C?JTS7bGoh0bgW^ZXgjNqK$%&Dzw&Wq_)-v3AIHG;U>W4 zh|;~f*18?F<96EZbB5a0*>0DhBffSPbZxus)TgT$r9Npe z?b7_poqSBUYZN->>}1^IUs-R3RPz_RDD(5bJBP4K~+baLf z`xOnLJOtyS)G0`Pg44UBI4UFv&COsxPIGaBGa$-$0C{Oe9qKU zTZ)jFX-J&yBw5|BKOT{VwzS|7=p>oOk1`BgC3Vrcx1E9SVx2HNTeI)>w|#(hF1Hgk zgnba5zX4O(<`MIuC*Fi$3(^6qtU}B|DH)`$XoS~pIwwetl#F~a-{do7g~iwdiF~1X z16#rlT?tNOFI45r=g7ho{*2SqB{bUUakZ?Y5WXREd1y&Cc$hL`%B zqlE*)swqvwxP3kE4&I6;O z;bP*7eqe6ZqmJb&fVv!zQ%E7*lO0Z&<&s!MK zmq@2o!*YG4j44Vkhn6?>F_`xsq>x4xks&2Hq}0Hlk>@*tlf$VUVeGc3xtBVNVLaOy z2;9-N>14Spa81Ye;7hr^VXQf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