|
|
|
|
@ -1560,6 +1560,35 @@ namespace WebSocketSharp
|
|
|
|
|
|
|
|
|
|
#region Internal Methods
|
|
|
|
|
|
|
|
|
|
internal static string CheckIfValidCloseParameters (ushort code, string reason, bool client)
|
|
|
|
|
{
|
|
|
|
|
return !code.IsCloseStatusCode ()
|
|
|
|
|
? "An invalid close status code."
|
|
|
|
|
: code == (ushort) CloseStatusCode.NoStatus
|
|
|
|
|
? (!reason.IsNullOrEmpty () ? "NoStatus cannot have a reason." : null)
|
|
|
|
|
: code == (ushort) CloseStatusCode.MandatoryExtension && !client
|
|
|
|
|
? "MandatoryExtension cannot be used by the server."
|
|
|
|
|
: code == (ushort) CloseStatusCode.ServerError && client
|
|
|
|
|
? "ServerError cannot be used by the client."
|
|
|
|
|
: !reason.IsNullOrEmpty () && Encoding.UTF8.GetBytes (reason).Length > 123
|
|
|
|
|
? "A reason has greater than the allowable max size."
|
|
|
|
|
: null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
internal static string CheckIfValidCloseParameters (
|
|
|
|
|
CloseStatusCode code, string reason, bool client)
|
|
|
|
|
{
|
|
|
|
|
return code == CloseStatusCode.NoStatus
|
|
|
|
|
? (!reason.IsNullOrEmpty () ? "NoStatus cannot have a reason." : null)
|
|
|
|
|
: code == CloseStatusCode.MandatoryExtension && !client
|
|
|
|
|
? "MandatoryExtension cannot be used by the server."
|
|
|
|
|
: code == CloseStatusCode.ServerError && client
|
|
|
|
|
? "ServerError cannot be used by the client."
|
|
|
|
|
: !reason.IsNullOrEmpty () && Encoding.UTF8.GetBytes (reason).Length > 123
|
|
|
|
|
? "A reason has greater than the allowable max size."
|
|
|
|
|
: null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// As server
|
|
|
|
|
internal void Close (HttpResponse response)
|
|
|
|
|
{
|
|
|
|
|
@ -1738,7 +1767,9 @@ namespace WebSocketSharp
|
|
|
|
|
/// </param>
|
|
|
|
|
public void Close (ushort code)
|
|
|
|
|
{
|
|
|
|
|
var msg = _readyState.CheckIfClosable () ?? code.CheckIfValidCloseStatusCode ();
|
|
|
|
|
var msg = _readyState.CheckIfClosable () ??
|
|
|
|
|
CheckIfValidCloseParameters (code, null, _client);
|
|
|
|
|
|
|
|
|
|
if (msg != null) {
|
|
|
|
|
_logger.Error (msg);
|
|
|
|
|
error ("An error has occurred in closing the connection.", null);
|
|
|
|
|
@ -1765,7 +1796,9 @@ namespace WebSocketSharp
|
|
|
|
|
/// </param>
|
|
|
|
|
public void Close (CloseStatusCode code)
|
|
|
|
|
{
|
|
|
|
|
var msg = _readyState.CheckIfClosable ();
|
|
|
|
|
var msg = _readyState.CheckIfClosable () ??
|
|
|
|
|
CheckIfValidCloseParameters (code, null, _client);
|
|
|
|
|
|
|
|
|
|
if (msg != null) {
|
|
|
|
|
_logger.Error (msg);
|
|
|
|
|
error ("An error has occurred in closing the connection.", null);
|
|
|
|
|
@ -1799,7 +1832,9 @@ namespace WebSocketSharp
|
|
|
|
|
/// </param>
|
|
|
|
|
public void Close (ushort code, string reason)
|
|
|
|
|
{
|
|
|
|
|
var msg = _readyState.CheckIfClosable () ?? code.CheckIfValidCloseParameters (reason);
|
|
|
|
|
var msg = _readyState.CheckIfClosable () ??
|
|
|
|
|
CheckIfValidCloseParameters (code, reason, _client);
|
|
|
|
|
|
|
|
|
|
if (msg != null) {
|
|
|
|
|
_logger.Error (msg);
|
|
|
|
|
error ("An error has occurred in closing the connection.", null);
|
|
|
|
|
@ -1833,7 +1868,9 @@ namespace WebSocketSharp
|
|
|
|
|
/// </param>
|
|
|
|
|
public void Close (CloseStatusCode code, string reason)
|
|
|
|
|
{
|
|
|
|
|
var msg = _readyState.CheckIfClosable () ?? code.CheckIfValidCloseParameters (reason);
|
|
|
|
|
var msg = _readyState.CheckIfClosable () ??
|
|
|
|
|
CheckIfValidCloseParameters (code, reason, _client);
|
|
|
|
|
|
|
|
|
|
if (msg != null) {
|
|
|
|
|
_logger.Error (msg);
|
|
|
|
|
error ("An error has occurred in closing the connection.", null);
|
|
|
|
|
@ -1887,7 +1924,9 @@ namespace WebSocketSharp
|
|
|
|
|
/// </param>
|
|
|
|
|
public void CloseAsync (ushort code)
|
|
|
|
|
{
|
|
|
|
|
var msg = _readyState.CheckIfClosable () ?? code.CheckIfValidCloseStatusCode ();
|
|
|
|
|
var msg = _readyState.CheckIfClosable () ??
|
|
|
|
|
CheckIfValidCloseParameters (code, null, _client);
|
|
|
|
|
|
|
|
|
|
if (msg != null) {
|
|
|
|
|
_logger.Error (msg);
|
|
|
|
|
error ("An error has occurred in closing the connection.", null);
|
|
|
|
|
@ -1917,7 +1956,9 @@ namespace WebSocketSharp
|
|
|
|
|
/// </param>
|
|
|
|
|
public void CloseAsync (CloseStatusCode code)
|
|
|
|
|
{
|
|
|
|
|
var msg = _readyState.CheckIfClosable ();
|
|
|
|
|
var msg = _readyState.CheckIfClosable () ??
|
|
|
|
|
CheckIfValidCloseParameters (code, null, _client);
|
|
|
|
|
|
|
|
|
|
if (msg != null) {
|
|
|
|
|
_logger.Error (msg);
|
|
|
|
|
error ("An error has occurred in closing the connection.", null);
|
|
|
|
|
@ -1956,7 +1997,9 @@ namespace WebSocketSharp
|
|
|
|
|
/// </param>
|
|
|
|
|
public void CloseAsync (ushort code, string reason)
|
|
|
|
|
{
|
|
|
|
|
var msg = _readyState.CheckIfClosable () ?? code.CheckIfValidCloseParameters (reason);
|
|
|
|
|
var msg = _readyState.CheckIfClosable () ??
|
|
|
|
|
CheckIfValidCloseParameters (code, reason, _client);
|
|
|
|
|
|
|
|
|
|
if (msg != null) {
|
|
|
|
|
_logger.Error (msg);
|
|
|
|
|
error ("An error has occurred in closing the connection.", null);
|
|
|
|
|
@ -1996,7 +2039,9 @@ namespace WebSocketSharp
|
|
|
|
|
/// </param>
|
|
|
|
|
public void CloseAsync (CloseStatusCode code, string reason)
|
|
|
|
|
{
|
|
|
|
|
var msg = _readyState.CheckIfClosable () ?? code.CheckIfValidCloseParameters (reason);
|
|
|
|
|
var msg = _readyState.CheckIfClosable () ??
|
|
|
|
|
CheckIfValidCloseParameters (code, reason, _client);
|
|
|
|
|
|
|
|
|
|
if (msg != null) {
|
|
|
|
|
_logger.Error (msg);
|
|
|
|
|
error ("An error has occurred in closing the connection.", null);
|
|
|
|
|
|