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

Fixed shutdown iteration issue

This commit is contained in:
lidgren
2011-03-10 18:45:18 +00:00
parent f4831a98a7
commit 97a2b76856
2 changed files with 16 additions and 8 deletions

View File

@@ -156,16 +156,23 @@ namespace Lidgren.Network
LogDebug("Shutting down..."); LogDebug("Shutting down...");
// disconnect and make one final heartbeat // disconnect and make one final heartbeat
var list = new List<NetConnection>(m_handshakes.Count + m_connections.Count);
lock (m_connections) lock (m_connections)
{ {
foreach (NetConnection conn in m_connections) foreach (var conn in m_connections)
conn.Shutdown(m_shutdownReason); if (conn != null)
} list.Add(conn);
lock (m_handshakes) lock (m_handshakes)
{ {
foreach (NetConnection conn in m_handshakes.Values) foreach (var hs in m_handshakes.Values)
conn.Shutdown(m_shutdownReason); if (hs != null)
list.Add(hs);
// shut down connections
foreach (NetConnection conn in list)
conn.Shutdown(m_shutdownReason);
}
} }
// one final heartbeat, will send stuff and do disconnect // one final heartbeat, will send stuff and do disconnect

View File

@@ -44,7 +44,8 @@ namespace UnitTests
throw new Exception("Received error message!"); throw new Exception("Received error message!");
} }
} }
Console.WriteLine("Done");
Console.ReadKey(); Console.ReadKey();
} }