Modified WebSocketState enum values to PascalCase values

This commit is contained in:
sta 2014-03-05 17:04:45 +09:00
parent e594696a38
commit d632fc839f
5 changed files with 57 additions and 53 deletions

View File

@ -196,27 +196,27 @@ namespace WebSocketSharp
internal static string CheckIfClosable (this WebSocketState state) internal static string CheckIfClosable (this WebSocketState state)
{ {
return state == WebSocketState.CLOSING return state == WebSocketState.Closing
? "While closing the WebSocket connection." ? "While closing the WebSocket connection."
: state == WebSocketState.CLOSED : state == WebSocketState.Closed
? "The WebSocket connection has already been closed." ? "The WebSocket connection has already been closed."
: null; : null;
} }
internal static string CheckIfConnectable (this WebSocketState state) internal static string CheckIfConnectable (this WebSocketState state)
{ {
return state == WebSocketState.OPEN || state == WebSocketState.CLOSING return state == WebSocketState.Open || state == WebSocketState.Closing
? "A WebSocket connection has already been established." ? "A WebSocket connection has already been established."
: null; : null;
} }
internal static string CheckIfOpen (this WebSocketState state) internal static string CheckIfOpen (this WebSocketState state)
{ {
return state == WebSocketState.CONNECTING return state == WebSocketState.Connecting
? "A WebSocket connection isn't established." ? "A WebSocket connection isn't established."
: state == WebSocketState.CLOSING : state == WebSocketState.Closing
? "While closing the WebSocket connection." ? "While closing the WebSocket connection."
: state == WebSocketState.CLOSED : state == WebSocketState.Closed
? "The WebSocket connection has already been closed." ? "The WebSocket connection has already been closed."
: null; : null;
} }

View File

@ -153,7 +153,7 @@ namespace WebSocketSharp.Server
} }
set { set {
if (State == WebSocketState.CONNECTING && if (State == WebSocketState.Connecting &&
value != null && value != null &&
value.Length > 0 && value.Length > 0 &&
value.IsToken ()) value.IsToken ())
@ -184,7 +184,7 @@ namespace WebSocketSharp.Server
get { get {
return _websocket != null return _websocket != null
? _websocket.ReadyState ? _websocket.ReadyState
: WebSocketState.CONNECTING; : WebSocketState.Connecting;
} }
} }

View File

@ -811,9 +811,9 @@ namespace WebSocketSharp.Server
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.Abnormal);
else if (state == WebSocketState.CLOSING) else if (state == WebSocketState.Closing)
continue; continue;
else else
_sessions.Remove (id); _sessions.Remove (id);

View File

@ -204,7 +204,7 @@ namespace WebSocketSharp
internal bool IsConnected { internal bool IsConnected {
get { get {
return _readyState == WebSocketState.OPEN || _readyState == WebSocketState.CLOSING; return _readyState == WebSocketState.Open || _readyState == WebSocketState.Closing;
} }
} }
@ -398,7 +398,7 @@ namespace WebSocketSharp
/// </summary> /// </summary>
/// <value> /// <value>
/// One of the <see cref="WebSocketState"/> enum values, indicates the state of the WebSocket /// One of the <see cref="WebSocketState"/> enum values, indicates the state of the WebSocket
/// connection. The default value is <see cref="WebSocketState.CONNECTING"/>. /// connection. The default value is <see cref="WebSocketState.Connecting"/>.
/// </value> /// </value>
public WebSocketState ReadyState { public WebSocketState ReadyState {
get { get {
@ -522,7 +522,7 @@ namespace WebSocketSharp
} }
error (msg ?? code.GetMessage ()); error (msg ?? code.GetMessage ());
if (_readyState == WebSocketState.CONNECTING && !_client) if (_readyState == WebSocketState.Connecting && !_client)
Close (HttpStatusCode.BadRequest); Close (HttpStatusCode.BadRequest);
else else
close (code, reason ?? code.GetMessage (), false); close (code, reason ?? code.GetMessage (), false);
@ -668,7 +668,7 @@ namespace WebSocketSharp
private string checkIfCanConnect () private string checkIfCanConnect ()
{ {
return !_client && _readyState == WebSocketState.CLOSED return !_client && _readyState == WebSocketState.Closed
? "Connect isn't available to reconnect as a server." ? "Connect isn't available to reconnect as a server."
: _readyState.CheckIfConnectable (); : _readyState.CheckIfConnectable ();
} }
@ -718,12 +718,12 @@ namespace WebSocketSharp
private void close (PayloadData payload, bool send, bool wait) private void close (PayloadData payload, bool send, bool wait)
{ {
lock (_forConn) { lock (_forConn) {
if (_readyState == WebSocketState.CLOSING || _readyState == WebSocketState.CLOSED) { if (_readyState == WebSocketState.Closing || _readyState == WebSocketState.Closed) {
_logger.Info ("Closing the WebSocket connection has already been done."); _logger.Info ("Closing the WebSocket connection has already been done.");
return; return;
} }
_readyState = WebSocketState.CLOSING; _readyState = WebSocketState.Closing;
} }
_logger.Trace ("Start closing handshake."); _logger.Trace ("Start closing handshake.");
@ -742,7 +742,7 @@ namespace WebSocketSharp
_logger.Trace ("End closing handshake."); _logger.Trace ("End closing handshake.");
_readyState = WebSocketState.CLOSED; _readyState = WebSocketState.Closed;
try { try {
OnClose.Emit (this, args); OnClose.Emit (this, args);
} }
@ -871,7 +871,7 @@ namespace WebSocketSharp
try { try {
if (_client ? doHandshake () : acceptHandshake ()) { if (_client ? doHandshake () : acceptHandshake ()) {
_readyState = WebSocketState.OPEN; _readyState = WebSocketState.Open;
return true; return true;
} }
} }
@ -1001,14 +1001,14 @@ namespace WebSocketSharp
_cookies = new CookieCollection (); _cookies = new CookieCollection ();
_forConn = new object (); _forConn = new object ();
_forSend = new object (); _forSend = new object ();
_readyState = WebSocketState.CONNECTING; _readyState = WebSocketState.Connecting;
} }
private void open () private void open ()
{ {
try { try {
OnOpen.Emit (this, EventArgs.Empty); OnOpen.Emit (this, EventArgs.Empty);
if (_readyState == WebSocketState.OPEN) if (_readyState == WebSocketState.Open)
startReceiving (); startReceiving ();
} }
catch (Exception ex) { catch (Exception ex) {
@ -1028,7 +1028,7 @@ namespace WebSocketSharp
private bool send (byte [] frame) private bool send (byte [] frame)
{ {
lock (_forConn) { lock (_forConn) {
if (_readyState != WebSocketState.OPEN) { if (_readyState != WebSocketState.Open) {
_logger.Warn ("Sending has been interrupted."); _logger.Warn ("Sending has been interrupted.");
return false; return false;
} }
@ -1058,7 +1058,7 @@ namespace WebSocketSharp
private bool send (WsFrame frame) private bool send (WsFrame frame)
{ {
lock (_forConn) { lock (_forConn) {
if (_readyState != WebSocketState.OPEN) { if (_readyState != WebSocketState.Open) {
_logger.Warn ("Sending has been interrupted."); _logger.Warn ("Sending has been interrupted.");
return false; return false;
} }
@ -1355,12 +1355,12 @@ namespace WebSocketSharp
// As server // As server
internal void Close (HandshakeResponse response) internal void Close (HandshakeResponse response)
{ {
_readyState = WebSocketState.CLOSING; _readyState = WebSocketState.Closing;
send (response); send (response);
closeServerResources (); closeServerResources ();
_readyState = WebSocketState.CLOSED; _readyState = WebSocketState.Closed;
} }
// As server // As server
@ -1373,17 +1373,17 @@ namespace WebSocketSharp
internal void Close (CloseEventArgs args, byte [] frame, int timeout) internal void Close (CloseEventArgs args, byte [] frame, int timeout)
{ {
lock (_forConn) { lock (_forConn) {
if (_readyState == WebSocketState.CLOSING || _readyState == WebSocketState.CLOSED) { if (_readyState == WebSocketState.Closing || _readyState == WebSocketState.Closed) {
_logger.Info ("Closing the WebSocket connection has already been done."); _logger.Info ("Closing the WebSocket connection has already been done.");
return; return;
} }
_readyState = WebSocketState.CLOSING; _readyState = WebSocketState.Closing;
} }
args.WasClean = closeHandshake (frame, timeout, closeServerResources); args.WasClean = closeHandshake (frame, timeout, closeServerResources);
_readyState = WebSocketState.CLOSED; _readyState = WebSocketState.Closed;
try { try {
OnClose.Emit (this, args); OnClose.Emit (this, args);
} }
@ -1397,7 +1397,7 @@ namespace WebSocketSharp
{ {
try { try {
if (acceptHandshake ()) { if (acceptHandshake ()) {
_readyState = WebSocketState.OPEN; _readyState = WebSocketState.Open;
open (); open ();
} }
} }
@ -1436,7 +1436,7 @@ namespace WebSocketSharp
{ {
lock (_forSend) { lock (_forSend) {
lock (_forConn) { lock (_forConn) {
if (_readyState != WebSocketState.OPEN) if (_readyState != WebSocketState.Open)
return; return;
try { try {
@ -1476,7 +1476,7 @@ namespace WebSocketSharp
else else
cached.Position = 0; cached.Position = 0;
if (_readyState == WebSocketState.OPEN) if (_readyState == WebSocketState.Open)
sendFragmented (opcode, cached, Mask.Unmask, _compression != CompressionMethod.None); sendFragmented (opcode, cached, Mask.Unmask, _compression != CompressionMethod.None);
} }
catch (Exception ex) { catch (Exception ex) {
@ -1503,7 +1503,7 @@ namespace WebSocketSharp
return; return;
} }
var send = _readyState == WebSocketState.OPEN; var send = _readyState == WebSocketState.Open;
close (new PayloadData (), send, send); close (new PayloadData (), send, send);
} }
@ -1565,7 +1565,7 @@ namespace WebSocketSharp
return; return;
} }
var send = _readyState == WebSocketState.OPEN && !code.IsReserved (); var send = _readyState == WebSocketState.Open && !code.IsReserved ();
close (new PayloadData (data), send, send); close (new PayloadData (data), send, send);
} }
@ -1597,7 +1597,7 @@ namespace WebSocketSharp
return; return;
} }
var send = _readyState == WebSocketState.OPEN && !code.IsReserved (); var send = _readyState == WebSocketState.Open && !code.IsReserved ();
close (new PayloadData (data), send, send); close (new PayloadData (data), send, send);
} }
@ -1617,7 +1617,7 @@ namespace WebSocketSharp
return; return;
} }
var send = _readyState == WebSocketState.OPEN; var send = _readyState == WebSocketState.Open;
closeAsync (new PayloadData (), send, send); closeAsync (new PayloadData (), send, send);
} }
@ -1692,7 +1692,7 @@ namespace WebSocketSharp
return; return;
} }
var send = _readyState == WebSocketState.OPEN && !code.IsReserved (); var send = _readyState == WebSocketState.Open && !code.IsReserved ();
closeAsync (new PayloadData (data), send, send); closeAsync (new PayloadData (data), send, send);
} }
@ -1730,7 +1730,7 @@ namespace WebSocketSharp
return; return;
} }
var send = _readyState == WebSocketState.OPEN && !code.IsReserved (); var send = _readyState == WebSocketState.Open && !code.IsReserved ();
closeAsync (new PayloadData (data), send, send); closeAsync (new PayloadData (data), send, send);
} }

View File

@ -4,7 +4,7 @@
* *
* The MIT License * The MIT License
* *
* Copyright (c) 2010-2013 sta.blockhead * Copyright (c) 2010-2014 sta.blockhead
* *
* Permission is hereby granted, free of charge, to any person obtaining a copy * Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal * of this software and associated documentation files (the "Software"), to deal
@ -28,34 +28,38 @@
using System; using System;
namespace WebSocketSharp { namespace WebSocketSharp
{
/// <summary> /// <summary>
/// Contains the values of the state of the WebSocket connection. /// Contains the values of the state of the WebSocket connection.
/// </summary> /// </summary>
/// <remarks> /// <remarks>
/// The WebSocketState enumeration contains the values of the state of the WebSocket connection defined in /// The state of the WebSocket connection is defined in
/// <a href="http://www.w3.org/TR/websockets/#dom-websocket-readystate">The WebSocket API</a>. /// <see href="http://www.w3.org/TR/websockets/#dom-websocket-readystate">The WebSocket
/// API</see>.
/// </remarks> /// </remarks>
public enum WebSocketState : ushort public enum WebSocketState : ushort
{ {
/// <summary> /// <summary>
/// Equivalent to numeric value 0. Indicates that the connection has not yet been established. /// Equivalent to numeric value 0.
/// Indicates that the connection has not yet been established.
/// </summary> /// </summary>
CONNECTING = 0, Connecting = 0,
/// <summary> /// <summary>
/// Equivalent to numeric value 1. Indicates that the connection is established and the communication /// Equivalent to numeric value 1.
/// is possible. /// Indicates that the connection is established and the communication is possible.
/// </summary> /// </summary>
OPEN = 1, Open = 1,
/// <summary> /// <summary>
/// Equivalent to numeric value 2. Indicates that the connection is going through the closing handshake, /// Equivalent to numeric value 2.
/// or the WebSocket.Close method has been invoked. /// Indicates that the connection is going through the closing handshake or
/// the <c>WebSocket.Close</c> method has been invoked.
/// </summary> /// </summary>
CLOSING = 2, Closing = 2,
/// <summary> /// <summary>
/// Equivalent to numeric value 3. Indicates that the connection has been closed or could not be opened. /// Equivalent to numeric value 3.
/// Indicates that the connection has been closed or couldn't be opened.
/// </summary> /// </summary>
CLOSED = 3 Closed = 3
} }
} }