[Fix] Check if can add a connection

This commit is contained in:
sta 2016-04-01 12:21:48 +09:00
parent afd6191331
commit c9511823b8
2 changed files with 16 additions and 3 deletions

View File

@ -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;
}

View File

@ -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)