diff --git a/websocket-sharp/Net/HttpConnection.cs b/websocket-sharp/Net/HttpConnection.cs index 3527731e..095f454e 100644 --- a/websocket-sharp/Net/HttpConnection.cs +++ b/websocket-sharp/Net/HttpConnection.cs @@ -294,7 +294,11 @@ namespace WebSocketSharp.Net var lsnr = conn._context.Listener; if (conn._lastListener != lsnr) { conn.removeConnection (); - lsnr.AddConnection (conn); + if (!lsnr.AddConnection (conn)) { + conn.close (); + return; + } + conn._lastListener = lsnr; } diff --git a/websocket-sharp/Net/HttpListener.cs b/websocket-sharp/Net/HttpListener.cs index 09729fb3..924e3cb9 100644 --- a/websocket-sharp/Net/HttpListener.cs +++ b/websocket-sharp/Net/HttpListener.cs @@ -503,10 +503,19 @@ namespace WebSocketSharp.Net #region Internal Methods - internal void AddConnection (HttpConnection connection) + internal bool AddConnection (HttpConnection connection) { - lock (_connectionsSync) + if (!_listening) + return false; + + lock (_connectionsSync) { + if (!_listening) + return false; + _connections[connection] = connection; + } + + return true; } internal bool Authenticate (HttpListenerContext context)