From dc420c7b7e1d35f2376c852929b3dafea424edd8 Mon Sep 17 00:00:00 2001 From: sta Date: Wed, 21 Apr 2021 19:46:58 +0900 Subject: [PATCH] [Modify] Polish it --- websocket-sharp/Net/HttpListener.cs | 20 ++++++++------------ 1 file changed, 8 insertions(+), 12 deletions(-) diff --git a/websocket-sharp/Net/HttpListener.cs b/websocket-sharp/Net/HttpListener.cs index 70384c6a..fea43aac 100644 --- a/websocket-sharp/Net/HttpListener.cs +++ b/websocket-sharp/Net/HttpListener.cs @@ -433,22 +433,18 @@ namespace WebSocketSharp.Net private void cleanupContextRegistry () { - HttpListenerContext[] ctxs = null; + var cnt = _contextRegistry.Count; - lock (_contextRegistrySync) { - var cnt = _contextRegistry.Count; + if (cnt == 0) + return; - if (cnt == 0) - return; + var ctxs = new HttpListenerContext[cnt]; + _contextRegistry.CopyTo (ctxs, 0); - ctxs = new HttpListenerContext[cnt]; - _contextRegistry.CopyTo (ctxs, 0); + _contextRegistry.Clear (); - _contextRegistry.Clear (); - } - - for (var i = ctxs.Length - 1; i >= 0; i--) - ctxs[i].Connection.Close (true); + foreach (var ctx in ctxs) + ctx.Connection.Close (true); } private void cleanupWaitQueue (Exception exception)