You've already forked lidgren-network-gen3
mirror of
https://github.com/lidgren/lidgren-network-gen3.git
synced 2026-05-19 00:26:30 +09:00
Receiving an ack for a reliable message sent less than two seconds ago will postpone timeout
This commit is contained in:
@@ -106,6 +106,11 @@ namespace Lidgren.Network
|
|||||||
m_remoteEndPoint = endPoint;
|
m_remoteEndPoint = endPoint;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
internal void ResetTimeout(double now)
|
||||||
|
{
|
||||||
|
m_timeoutDeadline = now + m_peerConfiguration.m_connectionTimeout;
|
||||||
|
}
|
||||||
|
|
||||||
internal void SetStatus(NetConnectionStatus status, string reason)
|
internal void SetStatus(NetConnectionStatus status, string reason)
|
||||||
{
|
{
|
||||||
// user or library thread
|
// user or library thread
|
||||||
|
|||||||
@@ -135,9 +135,14 @@ namespace Lidgren.Network
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void DestoreMessage(int storeIndex)
|
private void DestoreMessage(double now, int storeIndex, out bool resetTimeout)
|
||||||
{
|
{
|
||||||
NetOutgoingMessage storedMessage = m_storedMessages[storeIndex].Message;
|
// reset timeout if we receive ack within kThreshold of sending it
|
||||||
|
const double kThreshold = 2.0;
|
||||||
|
var srm = m_storedMessages[storeIndex];
|
||||||
|
resetTimeout = (srm.NumSent == 1) && (now - srm.LastSent < kThreshold);
|
||||||
|
|
||||||
|
var storedMessage = srm.Message;
|
||||||
|
|
||||||
// on each destore; reduce recyclingcount so that when all instances are destored, the outgoing message can be recycled
|
// on each destore; reduce recyclingcount so that when all instances are destored, the outgoing message can be recycled
|
||||||
Interlocked.Decrement(ref storedMessage.m_recyclingCount);
|
Interlocked.Decrement(ref storedMessage.m_recyclingCount);
|
||||||
@@ -177,8 +182,9 @@ namespace Lidgren.Network
|
|||||||
// ack arrived right on time
|
// ack arrived right on time
|
||||||
NetException.Assert(seqNr == m_windowStart);
|
NetException.Assert(seqNr == m_windowStart);
|
||||||
|
|
||||||
|
bool resetTimeout;
|
||||||
m_receivedAcks[m_windowStart] = false;
|
m_receivedAcks[m_windowStart] = false;
|
||||||
DestoreMessage(m_windowStart % m_windowSize);
|
DestoreMessage(now, m_windowStart % m_windowSize, out resetTimeout);
|
||||||
m_windowStart = (m_windowStart + 1) % NetConstants.NumSequenceNumbers;
|
m_windowStart = (m_windowStart + 1) % NetConstants.NumSequenceNumbers;
|
||||||
|
|
||||||
// advance window if we already have early acks
|
// advance window if we already have early acks
|
||||||
@@ -186,13 +192,16 @@ namespace Lidgren.Network
|
|||||||
{
|
{
|
||||||
//m_connection.m_peer.LogDebug("Using early ack for #" + m_windowStart + "...");
|
//m_connection.m_peer.LogDebug("Using early ack for #" + m_windowStart + "...");
|
||||||
m_receivedAcks[m_windowStart] = false;
|
m_receivedAcks[m_windowStart] = false;
|
||||||
DestoreMessage(m_windowStart % m_windowSize);
|
bool rt;
|
||||||
|
DestoreMessage(now, m_windowStart % m_windowSize, out rt);
|
||||||
|
resetTimeout |= rt;
|
||||||
|
|
||||||
NetException.Assert(m_storedMessages[m_windowStart % m_windowSize].Message == null); // should already be destored
|
NetException.Assert(m_storedMessages[m_windowStart % m_windowSize].Message == null); // should already be destored
|
||||||
m_windowStart = (m_windowStart + 1) % NetConstants.NumSequenceNumbers;
|
m_windowStart = (m_windowStart + 1) % NetConstants.NumSequenceNumbers;
|
||||||
//m_connection.m_peer.LogDebug("Advancing window to #" + m_windowStart);
|
//m_connection.m_peer.LogDebug("Advancing window to #" + m_windowStart);
|
||||||
}
|
}
|
||||||
|
if (resetTimeout)
|
||||||
|
m_connection.ResetTimeout(now);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user