[Fix] Check if can register a context
This commit is contained in:
parent
c9511823b8
commit
fdf1a18809
@ -303,7 +303,12 @@ namespace WebSocketSharp.Net
|
||||
}
|
||||
|
||||
conn._contextBound = true;
|
||||
lsnr.RegisterContext (conn._context);
|
||||
if (!lsnr.RegisterContext (conn._context)) {
|
||||
conn._contextBound = false;
|
||||
conn.close ();
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
@ -581,25 +581,33 @@ namespace WebSocketSharp.Net
|
||||
throw new ObjectDisposedException (GetType ().ToString ());
|
||||
}
|
||||
|
||||
internal void RegisterContext (HttpListenerContext context)
|
||||
internal bool RegisterContext (HttpListenerContext context)
|
||||
{
|
||||
lock (_ctxRegistrySync)
|
||||
_ctxRegistry[context] = context;
|
||||
if (!_listening)
|
||||
return false;
|
||||
|
||||
HttpListenerAsyncResult ares = null;
|
||||
lock (_waitQueueSync) {
|
||||
if (_waitQueue.Count == 0) {
|
||||
lock (_ctxQueueSync)
|
||||
_ctxQueue.Add (context);
|
||||
}
|
||||
else {
|
||||
ares = _waitQueue[0];
|
||||
_waitQueue.RemoveAt (0);
|
||||
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);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
internal void RemoveConnection (HttpConnection connection)
|
||||
|
Loading…
Reference in New Issue
Block a user