You've already forked lidgren-network-gen3
mirror of
https://github.com/lidgren/lidgren-network-gen3.git
synced 2026-05-17 15:46:33 +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];
|
var channel = m_sendChannels[i];
|
||||||
NetException.Assert(m_sendBufferWritePtr < 1 || m_sendBufferNumMessages > 0);
|
NetException.Assert(m_sendBufferWritePtr < 1 || m_sendBufferNumMessages > 0);
|
||||||
if (channel != null)
|
if (channel != null)
|
||||||
|
{
|
||||||
channel.SendQueuedMessages(now);
|
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);
|
NetException.Assert(m_sendBufferWritePtr < 1 || m_sendBufferNumMessages > 0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -534,7 +538,7 @@ namespace Lidgren.Network
|
|||||||
}
|
}
|
||||||
|
|
||||||
windowSize = chan.WindowSize;
|
windowSize = chan.WindowSize;
|
||||||
freeWindowSlots = chan.GetAllowedSends() - chan.m_queuedSends.Count;
|
freeWindowSlots = chan.GetFreeWindowSlots();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -544,7 +548,7 @@ namespace Lidgren.Network
|
|||||||
var chan = m_sendChannels[channelSlot];
|
var chan = m_sendChannels[channelSlot];
|
||||||
if (chan == null)
|
if (chan == null)
|
||||||
return true;
|
return true;
|
||||||
return (chan.GetAllowedSends() - chan.m_queuedSends.Count) > 0;
|
return chan.GetFreeWindowSlots() > 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
internal void Shutdown(string reason)
|
internal void Shutdown(string reason)
|
||||||
|
|||||||
@@ -179,7 +179,7 @@ namespace Lidgren.Network
|
|||||||
{
|
{
|
||||||
if (sendChan == null)
|
if (sendChan == null)
|
||||||
continue;
|
continue;
|
||||||
numUnsent += sendChan.m_queuedSends.Count;
|
numUnsent += sendChan.QueuedSendsCount;
|
||||||
|
|
||||||
var relSendChan = sendChan as NetReliableSenderChannel;
|
var relSendChan = sendChan as NetReliableSenderChannel;
|
||||||
if (relSendChan != null)
|
if (relSendChan != null)
|
||||||
|
|||||||
@@ -26,6 +26,7 @@ namespace Lidgren.Network
|
|||||||
private double m_lastHeartbeat;
|
private double m_lastHeartbeat;
|
||||||
private double m_lastSocketBind = float.MinValue;
|
private double m_lastSocketBind = float.MinValue;
|
||||||
private NetUPnP m_upnp;
|
private NetUPnP m_upnp;
|
||||||
|
internal bool m_needFlushSendQueue;
|
||||||
|
|
||||||
internal readonly NetPeerConfiguration m_configuration;
|
internal readonly NetPeerConfiguration m_configuration;
|
||||||
private readonly NetQueue<NetIncomingMessage> m_releasedIncomingMessages;
|
private readonly NetQueue<NetIncomingMessage> m_releasedIncomingMessages;
|
||||||
@@ -368,8 +369,11 @@ namespace Lidgren.Network
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
// update m_executeFlushSendQueue
|
// update m_executeFlushSendQueue
|
||||||
if (m_configuration.m_autoFlushSendQueue)
|
if (m_configuration.m_autoFlushSendQueue && m_needFlushSendQueue == true)
|
||||||
|
{
|
||||||
m_executeFlushSendQueue = 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
|
// do connection heartbeats
|
||||||
lock (m_connections)
|
lock (m_connections)
|
||||||
|
|||||||
@@ -52,6 +52,7 @@ namespace Lidgren.Network
|
|||||||
internal override NetSendResult Enqueue(NetOutgoingMessage message)
|
internal override NetSendResult Enqueue(NetOutgoingMessage message)
|
||||||
{
|
{
|
||||||
m_queuedSends.Enqueue(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())
|
if (m_queuedSends.Count <= GetAllowedSends())
|
||||||
return NetSendResult.Sent;
|
return NetSendResult.Sent;
|
||||||
return NetSendResult.Queued;
|
return NetSendResult.Queued;
|
||||||
@@ -100,7 +101,7 @@ namespace Lidgren.Network
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
// queued sends
|
// queued sends
|
||||||
while (m_queuedSends.Count > 0 && num > 0)
|
while (num > 0 && m_queuedSends.Count > 0)
|
||||||
{
|
{
|
||||||
NetOutgoingMessage om;
|
NetOutgoingMessage om;
|
||||||
if (m_queuedSends.TryDequeue(out om))
|
if (m_queuedSends.TryDequeue(out om))
|
||||||
|
|||||||
@@ -5,12 +5,19 @@ namespace Lidgren.Network
|
|||||||
internal abstract class NetSenderChannelBase
|
internal abstract class NetSenderChannelBase
|
||||||
{
|
{
|
||||||
// access this directly to queue things in this channel
|
// 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 WindowSize { get; }
|
||||||
|
|
||||||
internal abstract int GetAllowedSends();
|
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 NetSendResult Enqueue(NetOutgoingMessage message);
|
||||||
internal abstract void SendQueuedMessages(double now);
|
internal abstract void SendQueuedMessages(double now);
|
||||||
internal abstract void Reset();
|
internal abstract void Reset();
|
||||||
|
|||||||
@@ -53,6 +53,7 @@ namespace Lidgren.Network
|
|||||||
}
|
}
|
||||||
|
|
||||||
m_queuedSends.Enqueue(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()
|
||||||
return NetSendResult.Sent;
|
return NetSendResult.Sent;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -64,7 +65,7 @@ namespace Lidgren.Network
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
// queued sends
|
// queued sends
|
||||||
while (m_queuedSends.Count > 0 && num > 0)
|
while (num > 0 && m_queuedSends.Count > 0)
|
||||||
{
|
{
|
||||||
NetOutgoingMessage om;
|
NetOutgoingMessage om;
|
||||||
if (m_queuedSends.TryDequeue(out om))
|
if (m_queuedSends.TryDequeue(out om))
|
||||||
|
|||||||
Reference in New Issue
Block a user