\r
using System;\r
using System.Collections.Generic;\r
+using System.Linq;\r
using System.Net;\r
using System.Net.Sockets;\r
using System.Runtime.CompilerServices;\r
{\r
lock (ConnectedSockets)\r
{\r
- foreach (var kv in ConnectedSockets)\r
+ try\r
+ {\r
+ foreach (var id in\r
+ (from c in ConnectedSockets\r
+ where c.Value?.IsSocketDead() ?? true\r
+ select c.Key).ToArray())\r
+ ConnectedSockets.Remove(id);\r
+ }\r
+ catch (Exception e)\r
{\r
- try\r
- {\r
- int id = kv.Key;\r
- HttpSocket state = kv.Value;\r
- if (state == null || state.IsSocketDead())\r
- ConnectedSockets.Remove(id);\r
- }\r
- catch (Exception e)\r
- {\r
- log.Error(e);\r
- }\r
+ log.Error(e);\r
}\r
}\r
}\r