Remove Connections only from a queue to prevent desync

This commit is contained in:
Sofia 2020-08-08 22:41:57 +03:00
parent 6ba89572ae
commit 8d2e90a457
1 changed files with 6 additions and 1 deletions

View File

@ -15,6 +15,7 @@ namespace NeonTea.Quakeball.TeaNet.Peers {
private Peer Peer;
public Dictionary<ulong, Queue<ProtocolAction>> ProtocolActionQueues = new Dictionary<ulong, Queue<ProtocolAction>>();
private Queue<Connection> ConnectionsToRemove = new Queue<Connection>();
private Thread UpdateThread;
@ -131,6 +132,10 @@ namespace NeonTea.Quakeball.TeaNet.Peers {
}
}
}
while (ConnectionsToRemove.Count > 0) {
Connection conn = ConnectionsToRemove.Dequeue();
RemoveConnection(conn);
}
}
private void AddConnection(Connection conn) {
@ -257,7 +262,7 @@ namespace NeonTea.Quakeball.TeaNet.Peers {
}
foreach (ulong uid in timedOut) {
Connection conn = Connections[uid];
RemoveConnection(conn);
ConnectionsToRemove.Enqueue(conn);
if (conn.Status == ConnectionStatus.Ready
|| conn.Status == ConnectionStatus.Establishing
|| conn.Status == ConnectionStatus.Awaiting