1
0
mirror of https://github.com/lidgren/lidgren-network-gen3.git synced 2026-05-19 00:26:30 +09:00

Capped max connection heartbeats per second

This commit is contained in:
lidgren
2010-11-03 13:00:05 +00:00
parent c29270a5cf
commit dd192b1486
2 changed files with 45 additions and 34 deletions

View File

@@ -21,6 +21,7 @@ namespace Lidgren.Network
private EndPoint m_senderRemote;
private object m_initializeLock = new object();
private uint m_frameCounter;
private double m_lastHeartbeat;
internal readonly NetPeerConfiguration m_configuration;
private readonly NetQueue<NetIncomingMessage> m_releasedIncomingMessages;
@@ -196,9 +197,18 @@ namespace Lidgren.Network
{
VerifyNetworkThread();
float now = (float)NetTime.Now;
double dnow = NetTime.Now;
float now = (float)dnow;
double delta = dnow - m_lastHeartbeat;
int maxCHBpS = 1250 - m_connections.Count;
if (maxCHBpS < 250)
maxCHBpS = 250;
if (delta > (1.0 / (double)maxCHBpS)) // max connection heartbeats/second max
{
m_frameCounter++;
m_lastHeartbeat = dnow;
// do handshake heartbeats
if ((m_frameCounter % 3) == 0)
@@ -247,6 +257,7 @@ namespace Lidgren.Network
if (om.m_recyclingCount <= 0)
Recycle(om);
}
}
//
// read from socket

View File

@@ -26,7 +26,7 @@ namespace ManyServer
#else
// throw new Exception("Sample not relevant in RELEASE; statistics needed to make sense!");
#endif
config.MaximumConnections = 64;
config.MaximumConnections = 256;
Server = new NetServer(config);
Server.Start();