[Modify] Polish it
This commit is contained in:
parent
55aabfbcaf
commit
3ef00d0368
@ -1615,31 +1615,42 @@ namespace WebSocketSharp.Server
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public void Sweep ()
|
public void Sweep ()
|
||||||
{
|
{
|
||||||
if (_state != ServerState.Start || _sweeping || Count == 0)
|
if (_sweeping) {
|
||||||
|
_log.Info ("The sweeping is already in progress.");
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
lock (_forSweep) {
|
lock (_forSweep) {
|
||||||
|
if (_sweeping) {
|
||||||
|
_log.Info ("The sweeping is already in progress.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
_sweeping = true;
|
_sweeping = true;
|
||||||
foreach (var id in InactiveIDs) {
|
}
|
||||||
|
|
||||||
|
foreach (var id in InactiveIDs) {
|
||||||
|
if (_state != ServerState.Start)
|
||||||
|
break;
|
||||||
|
|
||||||
|
lock (_sync) {
|
||||||
if (_state != ServerState.Start)
|
if (_state != ServerState.Start)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
lock (_sync) {
|
IWebSocketSession session;
|
||||||
IWebSocketSession session;
|
if (_sessions.TryGetValue (id, out session)) {
|
||||||
if (_sessions.TryGetValue (id, out session)) {
|
var state = session.State;
|
||||||
var state = session.State;
|
if (state == WebSocketState.Open)
|
||||||
if (state == WebSocketState.Open)
|
session.Context.WebSocket.Close (CloseStatusCode.Abnormal);
|
||||||
session.Context.WebSocket.Close (CloseStatusCode.ProtocolError);
|
else if (state == WebSocketState.Closing)
|
||||||
else if (state == WebSocketState.Closing)
|
continue;
|
||||||
continue;
|
else
|
||||||
else
|
_sessions.Remove (id);
|
||||||
_sessions.Remove (id);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
_sweeping = false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
_sweeping = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
Loading…
Reference in New Issue
Block a user