Skip to content

Commit 6495576

Browse files
gedemgedem
authored andcommitted
Lifetime manager updated, timeouts
1 parent cb7d408 commit 6495576

File tree

1 file changed

+15
-2
lines changed

1 file changed

+15
-2
lines changed

src/NetCoreStack.WebSockets/Internal/TransportLifetimeManager.cs

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,24 @@ public TransportLifetimeManager()
1919
public void CheckQueue(object state)
2020
{
2121
var now = DateTime.Now;
22+
List<string> enableRemoveConnections = new List<string>();
2223
foreach (KeyValuePair<string, List<MessageHolder>> entry in _queueDict)
2324
{
2425
List<MessageHolder> timeoutItems = entry.Value.Where(p => p.KeepTime < now).ToList();
2526
entry.Value.RemoveAll(p => p.KeepTime < now);
27+
if (entry.Value.Count == 0)
28+
{
29+
enableRemoveConnections.Add(entry.Key);
30+
}
31+
}
32+
33+
foreach (var connection in enableRemoveConnections)
34+
{
35+
List<MessageHolder> queue = null;
36+
if (_queueDict.TryRemove(connection, out queue))
37+
{
38+
39+
}
2640
}
2741
}
2842

@@ -43,11 +57,10 @@ public void AddQueue(string connectionId, MessageHolder holder)
4357
public List<MessageHolder> TryDequeue(string connectionId)
4458
{
4559
List<MessageHolder> queue = null;
46-
if (_queueDict.TryGetValue(connectionId, out queue))
60+
if (_queueDict.TryRemove(connectionId, out queue))
4761
{
4862
var now = DateTime.Now;
4963
var items = queue.Where(x => x.KeepTime > now).ToList();
50-
queue.RemoveAll(x => x.KeepTime > now);
5164
return items;
5265
}
5366

0 commit comments

Comments
 (0)