Modified CloseStatusCode enum values to PascalCase values

This commit is contained in:
sta 2014-03-01 17:32:06 +09:00
parent 69e057969b
commit eb36dd9e82
12 changed files with 73 additions and 79 deletions

View File

@ -114,7 +114,7 @@ namespace WebSocketSharp
{ {
return data.Length > 1 return data.Length > 1
? data.SubArray (0, 2).ToUInt16 (ByteOrder.Big) ? data.SubArray (0, 2).ToUInt16 (ByteOrder.Big)
: (ushort) CloseStatusCode.NO_STATUS_CODE; : (ushort) CloseStatusCode.NoStatusCode;
} }
private static string getReasonFrom (byte [] data) private static string getReasonFrom (byte [] data)

View File

@ -31,20 +31,18 @@ using System;
namespace WebSocketSharp namespace WebSocketSharp
{ {
/// <summary> /// <summary>
/// Contains the values of the status codes for the WebSocket connection /// Contains the values of the status codes for the WebSocket connection closure.
/// closure.
/// </summary> /// </summary>
/// <remarks> /// <remarks>
/// <para> /// <para>
/// The CloseStatusCode enumeration contains the values of the status codes /// The status codes for the WebSocket connection closure are defined in
/// for the WebSocket connection closure defined in
/// <a href="http://tools.ietf.org/html/rfc6455#section-7.4.1">RFC 6455</a> /// <a href="http://tools.ietf.org/html/rfc6455#section-7.4.1">RFC 6455</a>
/// for the WebSocket protocol. /// for the WebSocket protocol.
/// </para> /// </para>
/// <para> /// <para>
/// "Reserved value" must not be set as a status code in a close control frame /// "Reserved value" must not be set as a status code in a close control frame by
/// by an endpoint. It's designated for use in applications expecting a status /// an endpoint. It's designated for use in applications expecting a status code
/// code to indicate that the connection was closed due to a system grounds. /// to indicate that the connection was closed due to a system grounds.
/// </para> /// </para>
/// </remarks> /// </remarks>
public enum CloseStatusCode : ushort public enum CloseStatusCode : ushort
@ -53,78 +51,74 @@ namespace WebSocketSharp
/// Equivalent to close status 1000. /// Equivalent to close status 1000.
/// Indicates a normal closure. /// Indicates a normal closure.
/// </summary> /// </summary>
NORMAL = 1000, Normal = 1000,
/// <summary> /// <summary>
/// Equivalent to close status 1001. /// Equivalent to close status 1001.
/// Indicates that an endpoint is "going away". /// Indicates that an endpoint is going away.
/// </summary> /// </summary>
AWAY = 1001, Away = 1001,
/// <summary> /// <summary>
/// Equivalent to close status 1002. /// Equivalent to close status 1002.
/// Indicates that an endpoint is terminating the connection due to a protocol /// Indicates that an endpoint is terminating the connection due to a protocol error.
/// error.
/// </summary> /// </summary>
PROTOCOL_ERROR = 1002, ProtocolError = 1002,
/// <summary> /// <summary>
/// Equivalent to close status 1003. /// Equivalent to close status 1003.
/// Indicates that an endpoint is terminating the connection because it has /// Indicates that an endpoint is terminating the connection because it has received an
/// received a type of data it cannot accept. /// unacceptable type message.
/// </summary> /// </summary>
INCORRECT_DATA = 1003, IncorrectData = 1003,
/// <summary> /// <summary>
/// Equivalent to close status 1004. /// Equivalent to close status 1004.
/// Still undefined. Reserved value. /// Still undefined. Reserved value.
/// </summary> /// </summary>
UNDEFINED = 1004, Undefined = 1004,
/// <summary> /// <summary>
/// Equivalent to close status 1005. /// Equivalent to close status 1005.
/// Indicates that no status code was actually present. Reserved value. /// Indicates that no status code was actually present. Reserved value.
/// </summary> /// </summary>
NO_STATUS_CODE = 1005, NoStatusCode = 1005,
/// <summary> /// <summary>
/// Equivalent to close status 1006. /// Equivalent to close status 1006.
/// Indicates that the connection was closed abnormally. Reserved value. /// Indicates that the connection was closed abnormally. Reserved value.
/// </summary> /// </summary>
ABNORMAL = 1006, Abnormal = 1006,
/// <summary> /// <summary>
/// Equivalent to close status 1007. /// Equivalent to close status 1007.
/// Indicates that an endpoint is terminating the connection because it has /// Indicates that an endpoint is terminating the connection because it has received a message
/// received the data within a message that wasn't consistent with the type of /// that contains a data that isn't consistent with the type of the message.
/// the message.
/// </summary> /// </summary>
INCONSISTENT_DATA = 1007, InconsistentData = 1007,
/// <summary> /// <summary>
/// Equivalent to close status 1008. /// Equivalent to close status 1008.
/// Indicates that an endpoint is terminating the connection because it has /// Indicates that an endpoint is terminating the connection because it has received a message
/// received a message that violates its policy. /// that violates its policy.
/// </summary> /// </summary>
POLICY_VIOLATION = 1008, PolicyViolation = 1008,
/// <summary> /// <summary>
/// Equivalent to close status 1009. /// Equivalent to close status 1009.
/// Indicates that an endpoint is terminating the connection because it has /// Indicates that an endpoint is terminating the connection because it has received a message
/// received a message that is too big to process. /// that is too big to process.
/// </summary> /// </summary>
TOO_BIG = 1009, TooBig = 1009,
/// <summary> /// <summary>
/// Equivalent to close status 1010. /// Equivalent to close status 1010.
/// Indicates that an endpoint (client) is terminating the connection because /// Indicates that the client is terminating the connection because it has expected the server
/// it has expected the server to negotiate one or more extension, but the /// to negotiate one or more extension, but the server didn't return them in the handshake
/// server didn't return them in the response message of the WebSocket /// response.
/// handshake.
/// </summary> /// </summary>
IGNORE_EXTENSION = 1010, IgnoreExtension = 1010,
/// <summary> /// <summary>
/// Equivalent to close status 1011. /// Equivalent to close status 1011.
/// Indicates that the server is terminating the connection because it has /// Indicates that the server is terminating the connection because it has encountered an
/// encountered an unexpected condition that prevented it from fulfilling the /// unexpected condition that prevented it from fulfilling the request.
/// request.
/// </summary> /// </summary>
SERVER_ERROR = 1011, ServerError = 1011,
/// <summary> /// <summary>
/// Equivalent to close status 1015. /// Equivalent to close status 1015.
/// Indicates that the connection was closed due to a failure to perform a TLS /// Indicates that the connection was closed due to a failure to perform a TLS handshake.
/// handshake. Reserved value. /// Reserved value.
/// </summary> /// </summary>
TLS_HANDSHAKE_FAILURE = 1015 TlsHandshakeFailure = 1015
} }
} }

View File

@ -472,23 +472,23 @@ namespace WebSocketSharp
internal static string GetMessage (this CloseStatusCode code) internal static string GetMessage (this CloseStatusCode code)
{ {
return code == CloseStatusCode.PROTOCOL_ERROR return code == CloseStatusCode.ProtocolError
? "A WebSocket protocol error has occurred." ? "A WebSocket protocol error has occurred."
: code == CloseStatusCode.INCORRECT_DATA : code == CloseStatusCode.IncorrectData
? "An incorrect data has been received." ? "An incorrect data has been received."
: code == CloseStatusCode.ABNORMAL : code == CloseStatusCode.Abnormal
? "An exception has occurred." ? "An exception has occurred."
: code == CloseStatusCode.INCONSISTENT_DATA : code == CloseStatusCode.InconsistentData
? "An inconsistent data has been received." ? "An inconsistent data has been received."
: code == CloseStatusCode.POLICY_VIOLATION : code == CloseStatusCode.PolicyViolation
? "A policy violation has occurred." ? "A policy violation has occurred."
: code == CloseStatusCode.TOO_BIG : code == CloseStatusCode.TooBig
? "A too big data has been received." ? "A too big data has been received."
: code == CloseStatusCode.IGNORE_EXTENSION : code == CloseStatusCode.IgnoreExtension
? "WebSocket client did not receive expected extension(s)." ? "WebSocket client did not receive expected extension(s)."
: code == CloseStatusCode.SERVER_ERROR : code == CloseStatusCode.ServerError
? "WebSocket server got an internal error." ? "WebSocket server got an internal error."
: code == CloseStatusCode.TLS_HANDSHAKE_FAILURE : code == CloseStatusCode.TlsHandshakeFailure
? "An error has occurred while handshaking." ? "An error has occurred while handshaking."
: String.Empty; : String.Empty;
} }
@ -527,18 +527,18 @@ namespace WebSocketSharp
internal static bool IsReserved (this ushort code) internal static bool IsReserved (this ushort code)
{ {
return code == (ushort) CloseStatusCode.UNDEFINED || return code == (ushort) CloseStatusCode.Undefined ||
code == (ushort) CloseStatusCode.NO_STATUS_CODE || code == (ushort) CloseStatusCode.NoStatusCode ||
code == (ushort) CloseStatusCode.ABNORMAL || code == (ushort) CloseStatusCode.Abnormal ||
code == (ushort) CloseStatusCode.TLS_HANDSHAKE_FAILURE; code == (ushort) CloseStatusCode.TlsHandshakeFailure;
} }
internal static bool IsReserved (this CloseStatusCode code) internal static bool IsReserved (this CloseStatusCode code)
{ {
return code == CloseStatusCode.UNDEFINED || return code == CloseStatusCode.Undefined ||
code == CloseStatusCode.NO_STATUS_CODE || code == CloseStatusCode.NoStatusCode ||
code == CloseStatusCode.ABNORMAL || code == CloseStatusCode.Abnormal ||
code == CloseStatusCode.TLS_HANDSHAKE_FAILURE; code == CloseStatusCode.TlsHandshakeFailure;
} }
internal static bool IsText (this string value) internal static bool IsText (this string value)

View File

@ -55,7 +55,7 @@ namespace WebSocketSharp
internal MessageEventArgs (Opcode opcode, byte[] data) internal MessageEventArgs (Opcode opcode, byte[] data)
{ {
if ((ulong) data.LongLength > PayloadData.MaxLength) if ((ulong) data.LongLength > PayloadData.MaxLength)
throw new WebSocketException (CloseStatusCode.TOO_BIG); throw new WebSocketException (CloseStatusCode.TooBig);
_opcode = opcode; _opcode = opcode;
_rawData = data; _rawData = data;

View File

@ -410,7 +410,7 @@ namespace WebSocketSharp.Server
} }
_services.Stop ( _services.Stop (
((ushort) CloseStatusCode.SERVER_ERROR).ToByteArrayInternally (ByteOrder.Big), true); ((ushort) CloseStatusCode.ServerError).ToByteArrayInternally (ByteOrder.Big), true);
_listener.Abort (); _listener.Abort ();
_state = ServerState.Stop; _state = ServerState.Stop;

View File

@ -466,7 +466,7 @@ namespace WebSocketSharp.Server
_listener.Stop (); _listener.Stop ();
_services.Stop ( _services.Stop (
((ushort) CloseStatusCode.SERVER_ERROR).ToByteArrayInternally (ByteOrder.Big), true); ((ushort) CloseStatusCode.ServerError).ToByteArrayInternally (ByteOrder.Big), true);
_state = ServerState.Stop; _state = ServerState.Stop;
} }

View File

@ -215,7 +215,7 @@ namespace WebSocketSharp.Server
{ {
ID = _sessions.Add (this); ID = _sessions.Add (this);
if (ID == null) { if (ID == null) {
_websocket.Close (CloseStatusCode.AWAY); _websocket.Close (CloseStatusCode.Away);
return; return;
} }

View File

@ -295,7 +295,7 @@ namespace WebSocketSharp.Server
if (host.Sessions.State == ServerState.Start) if (host.Sessions.State == ServerState.Start)
host.Sessions.Stop ( host.Sessions.Stop (
((ushort) CloseStatusCode.AWAY).ToByteArrayInternally (ByteOrder.Big), true); ((ushort) CloseStatusCode.Away).ToByteArrayInternally (ByteOrder.Big), true);
return true; return true;
} }

View File

@ -812,7 +812,7 @@ namespace WebSocketSharp.Server
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.Abnormal);
else if (state == WebSocketState.CLOSING) else if (state == WebSocketState.CLOSING)
continue; continue;
else else

View File

@ -504,7 +504,7 @@ namespace WebSocketSharp
private void acceptException (Exception exception, string reason) private void acceptException (Exception exception, string reason)
{ {
var code = CloseStatusCode.ABNORMAL; var code = CloseStatusCode.Abnormal;
var msg = reason; var msg = reason;
if (exception is WebSocketException) { if (exception is WebSocketException) {
var wsex = (WebSocketException) exception; var wsex = (WebSocketException) exception;
@ -512,7 +512,7 @@ namespace WebSocketSharp
reason = wsex.Message; reason = wsex.Message;
} }
if (code == CloseStatusCode.ABNORMAL || code == CloseStatusCode.TLS_HANDSHAKE_FAILURE) { if (code == CloseStatusCode.Abnormal || code == CloseStatusCode.TlsHandshakeFailure) {
_logger.Fatal (exception.ToString ()); _logger.Fatal (exception.ToString ());
reason = msg; reason = msg;
} }
@ -561,7 +561,7 @@ namespace WebSocketSharp
return frame.IsCompressed && _compression == CompressionMethod.NONE return frame.IsCompressed && _compression == CompressionMethod.NONE
? acceptUnsupportedFrame ( ? acceptUnsupportedFrame (
frame, frame,
CloseStatusCode.INCORRECT_DATA, CloseStatusCode.IncorrectData,
"A compressed data has been received without available decompression method.") "A compressed data has been received without available decompression method.")
: frame.IsFragmented : frame.IsFragmented
? acceptFragmentedFrame (frame) ? acceptFragmentedFrame (frame)
@ -573,7 +573,7 @@ namespace WebSocketSharp
? acceptPongFrame (frame) ? acceptPongFrame (frame)
: frame.IsClose : frame.IsClose
? acceptCloseFrame (frame) ? acceptCloseFrame (frame)
: acceptUnsupportedFrame (frame, CloseStatusCode.POLICY_VIOLATION, null); : acceptUnsupportedFrame (frame, CloseStatusCode.PolicyViolation, null);
} }
// As server // As server
@ -851,7 +851,7 @@ namespace WebSocketSharp
// ? // ?
return acceptUnsupportedFrame ( return acceptUnsupportedFrame (
frame, frame,
CloseStatusCode.INCORRECT_DATA, CloseStatusCode.IncorrectData,
"An incorrect data has been received while receiving fragmented data."); "An incorrect data has been received while receiving fragmented data.");
} }
@ -978,7 +978,7 @@ namespace WebSocketSharp
msg = "An error has occurred while connecting."; msg = "An error has occurred while connecting.";
error (msg); error (msg);
close (CloseStatusCode.ABNORMAL, msg, false); close (CloseStatusCode.Abnormal, msg, false);
return false; return false;
} }
@ -1780,11 +1780,11 @@ namespace WebSocketSharp
/// Closes the WebSocket connection, and releases all associated resources. /// Closes the WebSocket connection, and releases all associated resources.
/// </summary> /// </summary>
/// <remarks> /// <remarks>
/// This method closes the WebSocket connection with <see cref="CloseStatusCode.AWAY"/>. /// This method closes the WebSocket connection with <see cref="CloseStatusCode.Away"/>.
/// </remarks> /// </remarks>
public void Dispose () public void Dispose ()
{ {
Close (CloseStatusCode.AWAY, null); Close (CloseStatusCode.Away, null);
} }
/// <summary> /// <summary>

View File

@ -39,7 +39,7 @@ namespace WebSocketSharp
#region Internal Constructors #region Internal Constructors
internal WebSocketException () internal WebSocketException ()
: this (CloseStatusCode.ABNORMAL, null, null) : this (CloseStatusCode.Abnormal, null, null)
{ {
} }
@ -49,12 +49,12 @@ namespace WebSocketSharp
} }
internal WebSocketException (string reason) internal WebSocketException (string reason)
: this (CloseStatusCode.ABNORMAL, reason, null) : this (CloseStatusCode.Abnormal, reason, null)
{ {
} }
internal WebSocketException (string reason, Exception innerException) internal WebSocketException (string reason, Exception innerException)
: this (CloseStatusCode.ABNORMAL, reason, innerException) : this (CloseStatusCode.Abnormal, reason, innerException)
{ {
} }

View File

@ -397,12 +397,12 @@ namespace WebSocketSharp
: null; : null;
if (incorrect != null) if (incorrect != null)
throw new WebSocketException (CloseStatusCode.INCORRECT_DATA, incorrect); throw new WebSocketException (CloseStatusCode.IncorrectData, incorrect);
// Check if consistent frame. // Check if consistent frame.
if (isControl (opcode) && payloadLen > 125) if (isControl (opcode) && payloadLen > 125)
throw new WebSocketException ( throw new WebSocketException (
CloseStatusCode.INCONSISTENT_DATA, CloseStatusCode.InconsistentData,
"The payload data length of a control frame is greater than 125 bytes."); "The payload data length of a control frame is greater than 125 bytes.");
var frame = new WsFrame { var frame = new WsFrame {
@ -460,7 +460,7 @@ namespace WebSocketSharp
// Check if allowable payload data length. // Check if allowable payload data length.
if (payloadLen > 126 && dataLen > PayloadData.MaxLength) if (payloadLen > 126 && dataLen > PayloadData.MaxLength)
throw new WebSocketException ( throw new WebSocketException (
CloseStatusCode.TOO_BIG, "The 'Payload Data' length is greater than the allowable length."); CloseStatusCode.TooBig, "The 'Payload Data' length is greater than the allowable length.");
data = payloadLen > 126 data = payloadLen > 126
? stream.ReadBytes ((long) dataLen, 1024) ? stream.ReadBytes ((long) dataLen, 1024)