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
added mutex for access to m_handshake everywhere except count requests
This commit is contained in:
@@ -340,26 +340,32 @@ namespace Lidgren.Network
|
|||||||
// do handshake heartbeats
|
// do handshake heartbeats
|
||||||
if ((m_frameCounter % 3) == 0)
|
if ((m_frameCounter % 3) == 0)
|
||||||
{
|
{
|
||||||
foreach (var kvp in m_handshakes)
|
if (m_handshakes.Count > 0)
|
||||||
{
|
{
|
||||||
NetConnection conn = kvp.Value as NetConnection;
|
lock (m_handshakes)
|
||||||
#if DEBUG
|
|
||||||
// sanity check
|
|
||||||
if (kvp.Key != kvp.Key)
|
|
||||||
LogWarning("Sanity fail! Connection in handshake list under wrong key!");
|
|
||||||
#endif
|
|
||||||
conn.UnconnectedHeartbeat(now);
|
|
||||||
if (conn.m_status == NetConnectionStatus.Connected || conn.m_status == NetConnectionStatus.Disconnected)
|
|
||||||
{
|
{
|
||||||
#if DEBUG
|
foreach (var kvp in m_handshakes)
|
||||||
// sanity check
|
|
||||||
if (conn.m_status == NetConnectionStatus.Disconnected && m_handshakes.ContainsKey(conn.RemoteEndPoint))
|
|
||||||
{
|
{
|
||||||
LogWarning("Sanity fail! Handshakes list contained disconnected connection!");
|
NetConnection conn = kvp.Value as NetConnection;
|
||||||
m_handshakes.Remove(conn.RemoteEndPoint);
|
#if DEBUG
|
||||||
}
|
// sanity check
|
||||||
|
if (kvp.Key != kvp.Key)
|
||||||
|
LogWarning("Sanity fail! Connection in handshake list under wrong key!");
|
||||||
#endif
|
#endif
|
||||||
break; // collection has been modified
|
conn.UnconnectedHeartbeat(now);
|
||||||
|
if (conn.m_status == NetConnectionStatus.Connected || conn.m_status == NetConnectionStatus.Disconnected)
|
||||||
|
{
|
||||||
|
#if DEBUG
|
||||||
|
// sanity check
|
||||||
|
if (conn.m_status == NetConnectionStatus.Disconnected && m_handshakes.ContainsKey(conn.RemoteEndPoint))
|
||||||
|
{
|
||||||
|
LogWarning("Sanity fail! Handshakes list contained disconnected connection!");
|
||||||
|
m_handshakes.Remove(conn.RemoteEndPoint);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
break; // collection has been modified
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -710,7 +716,8 @@ namespace Lidgren.Network
|
|||||||
// Ok, start handshake!
|
// Ok, start handshake!
|
||||||
NetConnection conn = new NetConnection(this, senderEndPoint);
|
NetConnection conn = new NetConnection(this, senderEndPoint);
|
||||||
conn.m_status = NetConnectionStatus.ReceivedInitiation;
|
conn.m_status = NetConnectionStatus.ReceivedInitiation;
|
||||||
m_handshakes.Add(senderEndPoint, conn);
|
lock(m_handshakes)
|
||||||
|
m_handshakes.Add(senderEndPoint, conn);
|
||||||
conn.ReceivedHandshake(now, tp, ptr, payloadByteLength);
|
conn.ReceivedHandshake(now, tp, ptr, payloadByteLength);
|
||||||
return;
|
return;
|
||||||
|
|
||||||
@@ -729,8 +736,11 @@ namespace Lidgren.Network
|
|||||||
// LogDebug("Accepted connection " + conn);
|
// LogDebug("Accepted connection " + conn);
|
||||||
conn.InitExpandMTU(NetTime.Now);
|
conn.InitExpandMTU(NetTime.Now);
|
||||||
|
|
||||||
if (m_handshakes.Remove(conn.m_remoteEndPoint) == false)
|
lock (m_handshakes)
|
||||||
LogWarning("AcceptConnection called but m_handshakes did not contain it!");
|
{
|
||||||
|
if (m_handshakes.Remove(conn.m_remoteEndPoint) == false)
|
||||||
|
LogWarning("AcceptConnection called but m_handshakes did not contain it!");
|
||||||
|
}
|
||||||
|
|
||||||
lock (m_connections)
|
lock (m_connections)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -306,7 +306,8 @@ namespace Lidgren.Network
|
|||||||
conn.m_connectRequested = true;
|
conn.m_connectRequested = true;
|
||||||
conn.m_connectionInitiator = true;
|
conn.m_connectionInitiator = true;
|
||||||
|
|
||||||
m_handshakes.Add(remoteEndPoint, conn);
|
lock(m_handshakes)
|
||||||
|
m_handshakes.Add(remoteEndPoint, conn);
|
||||||
|
|
||||||
return conn;
|
return conn;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -61,7 +61,6 @@
|
|||||||
<DependentUpon>Resources.resx</DependentUpon>
|
<DependentUpon>Resources.resx</DependentUpon>
|
||||||
<DesignTime>True</DesignTime>
|
<DesignTime>True</DesignTime>
|
||||||
</Compile>
|
</Compile>
|
||||||
<None Include="app.config" />
|
|
||||||
<None Include="Properties\Settings.settings">
|
<None Include="Properties\Settings.settings">
|
||||||
<Generator>SettingsSingleFileGenerator</Generator>
|
<Generator>SettingsSingleFileGenerator</Generator>
|
||||||
<LastGenOutput>Settings.Designer.cs</LastGenOutput>
|
<LastGenOutput>Settings.Designer.cs</LastGenOutput>
|
||||||
|
|||||||
@@ -61,7 +61,6 @@
|
|||||||
<DependentUpon>Resources.resx</DependentUpon>
|
<DependentUpon>Resources.resx</DependentUpon>
|
||||||
<DesignTime>True</DesignTime>
|
<DesignTime>True</DesignTime>
|
||||||
</Compile>
|
</Compile>
|
||||||
<None Include="app.config" />
|
|
||||||
<None Include="Properties\Settings.settings">
|
<None Include="Properties\Settings.settings">
|
||||||
<Generator>SettingsSingleFileGenerator</Generator>
|
<Generator>SettingsSingleFileGenerator</Generator>
|
||||||
<LastGenOutput>Settings.Designer.cs</LastGenOutput>
|
<LastGenOutput>Settings.Designer.cs</LastGenOutput>
|
||||||
|
|||||||
Reference in New Issue
Block a user