Added the close2 (CloseEventArgs, bool, bool) method, to replace the close (CloseEventArgs, bool, bool) method with this

This commit is contained in:
sta 2015-01-18 17:27:23 +09:00
parent fe9ec9f29b
commit 88a1bbb9f6

View File

@ -678,6 +678,39 @@ namespace WebSocketSharp
}
}
private void close2 (CloseEventArgs e, bool send, bool wait)
{
lock (_forConn) {
if (_readyState == WebSocketState.Closing || _readyState == WebSocketState.Closed) {
_logger.Info ("Closing the connection has already been done.");
return;
}
send = send && _readyState == WebSocketState.Open;
wait = wait && send;
_readyState = WebSocketState.Closing;
}
_logger.Trace ("Start closing the connection.");
e.WasClean = closeHandshake (
send ? WebSocketFrame.CreateCloseFrame (e.PayloadData, _client).ToByteArray () : null,
wait ? _waitTime : TimeSpan.Zero,
_client ? (Action) releaseClientResources : releaseServerResources);
_logger.Trace ("End closing the connection.");
_readyState = WebSocketState.Closed;
try {
OnClose.Emit (this, e);
}
catch (Exception ex) {
_logger.Fatal (ex.ToString ());
error ("An exception has occurred during an OnClose event.", ex);
}
}
private void closeAsync (CloseEventArgs e, bool send, bool wait)
{
Action<CloseEventArgs, bool, bool> closer = close;