Added the internal Ext.CheckIfCanClose (WebSocketState) method
This commit is contained in:
		@@ -208,6 +208,13 @@ namespace WebSocketSharp
 | 
				
			|||||||
             : null;
 | 
					             : null;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    internal static string CheckIfCanClose (this WebSocketState state)
 | 
				
			||||||
 | 
					    {
 | 
				
			||||||
 | 
					      return state == WebSocketState.Closing || state == WebSocketState.Closed
 | 
				
			||||||
 | 
					             ? String.Format ("This operation isn't available ({0}).", state)
 | 
				
			||||||
 | 
					             : null;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    internal static string CheckIfCanConnect (this WebSocketState state)
 | 
					    internal static string CheckIfCanConnect (this WebSocketState state)
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
      return state == WebSocketState.Open || state == WebSocketState.Closing
 | 
					      return state == WebSocketState.Open || state == WebSocketState.Closing
 | 
				
			||||||
@@ -224,15 +231,6 @@ namespace WebSocketSharp
 | 
				
			|||||||
               : null;
 | 
					               : null;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    internal static string CheckIfClosable (this WebSocketState state)
 | 
					 | 
				
			||||||
    {
 | 
					 | 
				
			||||||
      return state == WebSocketState.Closing
 | 
					 | 
				
			||||||
             ? "While closing the WebSocket connection."
 | 
					 | 
				
			||||||
             : state == WebSocketState.Closed
 | 
					 | 
				
			||||||
               ? "The WebSocket connection has already been closed."
 | 
					 | 
				
			||||||
               : null;
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    internal static string CheckIfOpen (this WebSocketState state)
 | 
					    internal static string CheckIfOpen (this WebSocketState state)
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
      return state == WebSocketState.Connecting
 | 
					      return state == WebSocketState.Connecting
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -1806,7 +1806,7 @@ namespace WebSocketSharp
 | 
				
			|||||||
    /// </summary>
 | 
					    /// </summary>
 | 
				
			||||||
    public void Close ()
 | 
					    public void Close ()
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
      var msg = _readyState.CheckIfClosable ();
 | 
					      var msg = _readyState.CheckIfCanClose ();
 | 
				
			||||||
      if (msg != null) {
 | 
					      if (msg != null) {
 | 
				
			||||||
        _logger.Error (msg);
 | 
					        _logger.Error (msg);
 | 
				
			||||||
        error ("An error has occurred in closing the connection.", null);
 | 
					        error ("An error has occurred in closing the connection.", null);
 | 
				
			||||||
@@ -1830,7 +1830,7 @@ namespace WebSocketSharp
 | 
				
			|||||||
    /// </param>
 | 
					    /// </param>
 | 
				
			||||||
    public void Close (ushort code)
 | 
					    public void Close (ushort code)
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
      var msg = _readyState.CheckIfClosable () ?? CheckCloseParameters (code, null, _client);
 | 
					      var msg = _readyState.CheckIfCanClose () ?? CheckCloseParameters (code, null, _client);
 | 
				
			||||||
      if (msg != null) {
 | 
					      if (msg != null) {
 | 
				
			||||||
        _logger.Error (msg);
 | 
					        _logger.Error (msg);
 | 
				
			||||||
        error ("An error has occurred in closing the connection.", null);
 | 
					        error ("An error has occurred in closing the connection.", null);
 | 
				
			||||||
@@ -1857,7 +1857,7 @@ namespace WebSocketSharp
 | 
				
			|||||||
    /// </param>
 | 
					    /// </param>
 | 
				
			||||||
    public void Close (CloseStatusCode code)
 | 
					    public void Close (CloseStatusCode code)
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
      var msg = _readyState.CheckIfClosable () ?? CheckCloseParameters (code, null, _client);
 | 
					      var msg = _readyState.CheckIfCanClose () ?? CheckCloseParameters (code, null, _client);
 | 
				
			||||||
      if (msg != null) {
 | 
					      if (msg != null) {
 | 
				
			||||||
        _logger.Error (msg);
 | 
					        _logger.Error (msg);
 | 
				
			||||||
        error ("An error has occurred in closing the connection.", null);
 | 
					        error ("An error has occurred in closing the connection.", null);
 | 
				
			||||||
@@ -1891,7 +1891,7 @@ namespace WebSocketSharp
 | 
				
			|||||||
    /// </param>
 | 
					    /// </param>
 | 
				
			||||||
    public void Close (ushort code, string reason)
 | 
					    public void Close (ushort code, string reason)
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
      var msg = _readyState.CheckIfClosable () ?? CheckCloseParameters (code, reason, _client);
 | 
					      var msg = _readyState.CheckIfCanClose () ?? CheckCloseParameters (code, reason, _client);
 | 
				
			||||||
      if (msg != null) {
 | 
					      if (msg != null) {
 | 
				
			||||||
        _logger.Error (msg);
 | 
					        _logger.Error (msg);
 | 
				
			||||||
        error ("An error has occurred in closing the connection.", null);
 | 
					        error ("An error has occurred in closing the connection.", null);
 | 
				
			||||||
@@ -1925,7 +1925,7 @@ namespace WebSocketSharp
 | 
				
			|||||||
    /// </param>
 | 
					    /// </param>
 | 
				
			||||||
    public void Close (CloseStatusCode code, string reason)
 | 
					    public void Close (CloseStatusCode code, string reason)
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
      var msg = _readyState.CheckIfClosable () ?? CheckCloseParameters (code, reason, _client);
 | 
					      var msg = _readyState.CheckIfCanClose () ?? CheckCloseParameters (code, reason, _client);
 | 
				
			||||||
      if (msg != null) {
 | 
					      if (msg != null) {
 | 
				
			||||||
        _logger.Error (msg);
 | 
					        _logger.Error (msg);
 | 
				
			||||||
        error ("An error has occurred in closing the connection.", null);
 | 
					        error ("An error has occurred in closing the connection.", null);
 | 
				
			||||||
@@ -1950,7 +1950,7 @@ namespace WebSocketSharp
 | 
				
			|||||||
    /// </remarks>
 | 
					    /// </remarks>
 | 
				
			||||||
    public void CloseAsync ()
 | 
					    public void CloseAsync ()
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
      var msg = _readyState.CheckIfClosable ();
 | 
					      var msg = _readyState.CheckIfCanClose ();
 | 
				
			||||||
      if (msg != null) {
 | 
					      if (msg != null) {
 | 
				
			||||||
        _logger.Error (msg);
 | 
					        _logger.Error (msg);
 | 
				
			||||||
        error ("An error has occurred in closing the connection.", null);
 | 
					        error ("An error has occurred in closing the connection.", null);
 | 
				
			||||||
@@ -1979,7 +1979,7 @@ namespace WebSocketSharp
 | 
				
			|||||||
    /// </param>
 | 
					    /// </param>
 | 
				
			||||||
    public void CloseAsync (ushort code)
 | 
					    public void CloseAsync (ushort code)
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
      var msg = _readyState.CheckIfClosable () ?? CheckCloseParameters (code, null, _client);
 | 
					      var msg = _readyState.CheckIfCanClose () ?? CheckCloseParameters (code, null, _client);
 | 
				
			||||||
      if (msg != null) {
 | 
					      if (msg != null) {
 | 
				
			||||||
        _logger.Error (msg);
 | 
					        _logger.Error (msg);
 | 
				
			||||||
        error ("An error has occurred in closing the connection.", null);
 | 
					        error ("An error has occurred in closing the connection.", null);
 | 
				
			||||||
@@ -2009,7 +2009,7 @@ namespace WebSocketSharp
 | 
				
			|||||||
    /// </param>
 | 
					    /// </param>
 | 
				
			||||||
    public void CloseAsync (CloseStatusCode code)
 | 
					    public void CloseAsync (CloseStatusCode code)
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
      var msg = _readyState.CheckIfClosable () ?? CheckCloseParameters (code, null, _client);
 | 
					      var msg = _readyState.CheckIfCanClose () ?? CheckCloseParameters (code, null, _client);
 | 
				
			||||||
      if (msg != null) {
 | 
					      if (msg != null) {
 | 
				
			||||||
        _logger.Error (msg);
 | 
					        _logger.Error (msg);
 | 
				
			||||||
        error ("An error has occurred in closing the connection.", null);
 | 
					        error ("An error has occurred in closing the connection.", null);
 | 
				
			||||||
@@ -2048,7 +2048,7 @@ namespace WebSocketSharp
 | 
				
			|||||||
    /// </param>
 | 
					    /// </param>
 | 
				
			||||||
    public void CloseAsync (ushort code, string reason)
 | 
					    public void CloseAsync (ushort code, string reason)
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
      var msg = _readyState.CheckIfClosable () ?? CheckCloseParameters (code, reason, _client);
 | 
					      var msg = _readyState.CheckIfCanClose () ?? CheckCloseParameters (code, reason, _client);
 | 
				
			||||||
      if (msg != null) {
 | 
					      if (msg != null) {
 | 
				
			||||||
        _logger.Error (msg);
 | 
					        _logger.Error (msg);
 | 
				
			||||||
        error ("An error has occurred in closing the connection.", null);
 | 
					        error ("An error has occurred in closing the connection.", null);
 | 
				
			||||||
@@ -2088,7 +2088,7 @@ namespace WebSocketSharp
 | 
				
			|||||||
    /// </param>
 | 
					    /// </param>
 | 
				
			||||||
    public void CloseAsync (CloseStatusCode code, string reason)
 | 
					    public void CloseAsync (CloseStatusCode code, string reason)
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
      var msg = _readyState.CheckIfClosable () ?? CheckCloseParameters (code, reason, _client);
 | 
					      var msg = _readyState.CheckIfCanClose () ?? CheckCloseParameters (code, reason, _client);
 | 
				
			||||||
      if (msg != null) {
 | 
					      if (msg != null) {
 | 
				
			||||||
        _logger.Error (msg);
 | 
					        _logger.Error (msg);
 | 
				
			||||||
        error ("An error has occurred in closing the connection.", null);
 | 
					        error ("An error has occurred in closing the connection.", null);
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user