diff --git a/websocket-sharp/Net/HttpListener.cs b/websocket-sharp/Net/HttpListener.cs index 3ef5c4d4..7c25b287 100644 --- a/websocket-sharp/Net/HttpListener.cs +++ b/websocket-sharp/Net/HttpListener.cs @@ -596,28 +596,23 @@ namespace WebSocketSharp.Net if (!_listening) return false; - HttpListenerAsyncResult ares = null; lock (_ctxRegistrySync) { if (!_listening) return false; _ctxRegistry[context] = context; - lock (_waitQueueSync) { - if (_waitQueue.Count == 0) { - lock (_ctxQueueSync) - _ctxQueue.Add (context); - } - else { - ares = _waitQueue[0]; - _waitQueue.RemoveAt (0); - } - } - } - if (ares != null) - ares.Complete (context); + var ares = getAsyncResultFromQueue (); + if (ares == null) { + lock (_ctxQueueSync) + _ctxQueue.Add (context); + } + else { + ares.Complete (context); + } - return true; + return true; + } } internal void RemoveConnection (HttpConnection connection)