You've already forked lidgren-network-gen3
mirror of
https://github.com/lidgren/lidgren-network-gen3.git
synced 2026-05-16 07:06:30 +09:00
m_needFlushSendQueue added to prevent traversing sender channels each heartbeat
This commit is contained in:
@@ -253,7 +253,11 @@ namespace Lidgren.Network
|
||||
var channel = m_sendChannels[i];
|
||||
NetException.Assert(m_sendBufferWritePtr < 1 || m_sendBufferNumMessages > 0);
|
||||
if (channel != null)
|
||||
{
|
||||
channel.SendQueuedMessages(now);
|
||||
if (channel.QueuedSendsCount > 0)
|
||||
m_peer.m_needFlushSendQueue = true; // failed to send all queued sends; likely a full window - need to try again
|
||||
}
|
||||
NetException.Assert(m_sendBufferWritePtr < 1 || m_sendBufferNumMessages > 0);
|
||||
}
|
||||
}
|
||||
@@ -534,7 +538,7 @@ namespace Lidgren.Network
|
||||
}
|
||||
|
||||
windowSize = chan.WindowSize;
|
||||
freeWindowSlots = chan.GetAllowedSends() - chan.m_queuedSends.Count;
|
||||
freeWindowSlots = chan.GetFreeWindowSlots();
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -544,7 +548,7 @@ namespace Lidgren.Network
|
||||
var chan = m_sendChannels[channelSlot];
|
||||
if (chan == null)
|
||||
return true;
|
||||
return (chan.GetAllowedSends() - chan.m_queuedSends.Count) > 0;
|
||||
return chan.GetFreeWindowSlots() > 0;
|
||||
}
|
||||
|
||||
internal void Shutdown(string reason)
|
||||
|
||||
@@ -179,7 +179,7 @@ namespace Lidgren.Network
|
||||
{
|
||||
if (sendChan == null)
|
||||
continue;
|
||||
numUnsent += sendChan.m_queuedSends.Count;
|
||||
numUnsent += sendChan.QueuedSendsCount;
|
||||
|
||||
var relSendChan = sendChan as NetReliableSenderChannel;
|
||||
if (relSendChan != null)
|
||||
|
||||
@@ -26,6 +26,7 @@ namespace Lidgren.Network
|
||||
private double m_lastHeartbeat;
|
||||
private double m_lastSocketBind = float.MinValue;
|
||||
private NetUPnP m_upnp;
|
||||
internal bool m_needFlushSendQueue;
|
||||
|
||||
internal readonly NetPeerConfiguration m_configuration;
|
||||
private readonly NetQueue<NetIncomingMessage> m_releasedIncomingMessages;
|
||||
@@ -368,8 +369,11 @@ namespace Lidgren.Network
|
||||
#endif
|
||||
|
||||
// update m_executeFlushSendQueue
|
||||
if (m_configuration.m_autoFlushSendQueue)
|
||||
if (m_configuration.m_autoFlushSendQueue && m_needFlushSendQueue == true)
|
||||
{
|
||||
m_executeFlushSendQueue = true;
|
||||
m_needFlushSendQueue = false; // a race condition to this variable will simply result in a single superfluous call to FlushSendQueue()
|
||||
}
|
||||
|
||||
// do connection heartbeats
|
||||
lock (m_connections)
|
||||
|
||||
@@ -52,6 +52,7 @@ namespace Lidgren.Network
|
||||
internal override NetSendResult Enqueue(NetOutgoingMessage message)
|
||||
{
|
||||
m_queuedSends.Enqueue(message);
|
||||
m_connection.m_peer.m_needFlushSendQueue = true; // a race condition to this variable will simply result in a single superflous call to FlushSendQueue()
|
||||
if (m_queuedSends.Count <= GetAllowedSends())
|
||||
return NetSendResult.Sent;
|
||||
return NetSendResult.Queued;
|
||||
@@ -100,7 +101,7 @@ namespace Lidgren.Network
|
||||
return;
|
||||
|
||||
// queued sends
|
||||
while (m_queuedSends.Count > 0 && num > 0)
|
||||
while (num > 0 && m_queuedSends.Count > 0)
|
||||
{
|
||||
NetOutgoingMessage om;
|
||||
if (m_queuedSends.TryDequeue(out om))
|
||||
|
||||
@@ -5,12 +5,19 @@ namespace Lidgren.Network
|
||||
internal abstract class NetSenderChannelBase
|
||||
{
|
||||
// access this directly to queue things in this channel
|
||||
internal NetQueue<NetOutgoingMessage> m_queuedSends;
|
||||
protected NetQueue<NetOutgoingMessage> m_queuedSends;
|
||||
|
||||
internal abstract int WindowSize { get; }
|
||||
|
||||
internal abstract int GetAllowedSends();
|
||||
|
||||
internal int QueuedSendsCount { get { return m_queuedSends.Count; } }
|
||||
|
||||
public int GetFreeWindowSlots()
|
||||
{
|
||||
return GetAllowedSends() - m_queuedSends.Count;
|
||||
}
|
||||
|
||||
internal abstract NetSendResult Enqueue(NetOutgoingMessage message);
|
||||
internal abstract void SendQueuedMessages(double now);
|
||||
internal abstract void Reset();
|
||||
|
||||
@@ -53,6 +53,7 @@ namespace Lidgren.Network
|
||||
}
|
||||
|
||||
m_queuedSends.Enqueue(message);
|
||||
m_connection.m_peer.m_needFlushSendQueue = true; // a race condition to this variable will simply result in a single superflous call to FlushSendQueue()
|
||||
return NetSendResult.Sent;
|
||||
}
|
||||
|
||||
@@ -64,7 +65,7 @@ namespace Lidgren.Network
|
||||
return;
|
||||
|
||||
// queued sends
|
||||
while (m_queuedSends.Count > 0 && num > 0)
|
||||
while (num > 0 && m_queuedSends.Count > 0)
|
||||
{
|
||||
NetOutgoingMessage om;
|
||||
if (m_queuedSends.TryDequeue(out om))
|
||||
|
||||
Reference in New Issue
Block a user