From 371ac36dd906b4a240f4d7d7152fda8b9dfa951b Mon Sep 17 00:00:00 2001 From: sta Date: Sun, 26 Apr 2015 16:50:09 +0900 Subject: [PATCH] Refactored a few for WebSocket.cs --- websocket-sharp/WebSocket.cs | 159 +++++++++++++++++------------------ 1 file changed, 78 insertions(+), 81 deletions(-) diff --git a/websocket-sharp/WebSocket.cs b/websocket-sharp/WebSocket.cs index 3b674328..bc848e1c 100644 --- a/websocket-sharp/WebSocket.cs +++ b/websocket-sharp/WebSocket.cs @@ -248,12 +248,13 @@ namespace WebSocketSharp #region Public Properties /// - /// Gets or sets the compression method used to compress the message on the WebSocket - /// connection. + /// Gets or sets the compression method used to compress the message on + /// the WebSocket connection. /// /// - /// One of the enum values, indicates the compression method - /// used to compress the message. The default value is . + /// One of the enum values, indicates + /// the compression method used to compress the message. The default value is + /// . /// public CompressionMethod Compression { get { @@ -295,8 +296,8 @@ namespace WebSocketSharp /// Gets the credentials for the HTTP authentication (Basic/Digest). /// /// - /// A that represents the credentials for the authentication. - /// The default value is . + /// A that represents the credentials for + /// the authentication. The default value is . /// public NetworkCredential Credentials { get { @@ -391,8 +392,8 @@ namespace WebSocketSharp } /// - /// Gets or sets the value of the HTTP Origin header to send with the WebSocket connection - /// request to the server. + /// Gets or sets the value of the HTTP Origin header to send with + /// the WebSocket connection request to the server. /// /// /// The sends the Origin header if this property has any. @@ -460,8 +461,8 @@ namespace WebSocketSharp /// Gets the state of the WebSocket connection. /// /// - /// One of the enum values, indicates the state of the WebSocket - /// connection. The default value is . + /// One of the enum values, indicates the state of + /// the WebSocket connection. The default value is . /// public WebSocketState ReadyState { get { @@ -590,9 +591,9 @@ namespace WebSocketSharp _protocol = null; if (!_ignoreExtensions) { - var extensions = _context.Headers["Sec-WebSocket-Extensions"]; - if (extensions != null && extensions.Length > 0) - processSecWebSocketExtensionsHeader (extensions); + var exts = _context.Headers["Sec-WebSocket-Extensions"]; + if (exts != null && exts.Length > 0) + processSecWebSocketExtensionsHeader (exts); } return sendHttpResponse (createHandshakeResponse ()); @@ -676,7 +677,7 @@ namespace WebSocketSharp _readyState = WebSocketState.Closing; } - _logger.Trace ("Start closing the connection."); + _logger.Trace ("Begin closing the connection."); e.WasClean = closeHandshake ( send ? WebSocketFrame.CreateCloseFrame (e.PayloadData, _client).ToByteArray () : null, @@ -718,11 +719,11 @@ namespace WebSocketSharp _exitReceiving = null; } - var res = sent && received; + var ret = sent && received; _logger.Debug ( - String.Format ("Was clean?: {0}\nsent: {1} received: {2}", res, sent, received)); + String.Format ("Was clean?: {0}\n sent: {1}\n received: {2}", ret, sent, received)); - return res; + return ret; } private bool concatenateFragmentsInto (Stream destination) @@ -773,7 +774,7 @@ namespace WebSocketSharp return processUnsupportedFrame ( frame, CloseStatusCode.IncorrectData, - "An incorrect data has been received while receiving the fragmented data."); + "Incorrect data has been received while receiving the fragmented data."); } return true; @@ -811,10 +812,10 @@ namespace WebSocketSharp var buff = new StringBuilder (80); if (_compression != CompressionMethod.None) { - var c = _compression.ToExtensionString ( + var str = _compression.ToExtensionString ( "server_no_context_takeover", "client_no_context_takeover"); - buff.AppendFormat ("{0}, ", c); + buff.AppendFormat ("{0}, ", str); } var len = buff.Length; @@ -829,18 +830,18 @@ namespace WebSocketSharp // As server private HttpResponse createHandshakeCloseResponse (HttpStatusCode code) { - var res = HttpResponse.CreateCloseResponse (code); - res.Headers["Sec-WebSocket-Version"] = _version; + var ret = HttpResponse.CreateCloseResponse (code); + ret.Headers["Sec-WebSocket-Version"] = _version; - return res; + return ret; } // As client private HttpRequest createHandshakeRequest () { - var req = HttpRequest.CreateWebSocketRequest (_uri); + var ret = HttpRequest.CreateWebSocketRequest (_uri); - var headers = req.Headers; + var headers = ret.Headers; if (!_origin.IsNullOrEmpty ()) headers["Origin"] = _origin; @@ -849,9 +850,9 @@ namespace WebSocketSharp if (_protocols != null) headers["Sec-WebSocket-Protocol"] = _protocols.ToString (", "); - var extensions = createExtensions (); - if (extensions != null) - headers["Sec-WebSocket-Extensions"] = extensions; + var exts = createExtensions (); + if (exts != null) + headers["Sec-WebSocket-Extensions"] = exts; headers["Sec-WebSocket-Version"] = _version; @@ -868,17 +869,17 @@ namespace WebSocketSharp headers["Authorization"] = authRes.ToString (); if (_cookies.Count > 0) - req.SetCookies (_cookies); + ret.SetCookies (_cookies); - return req; + return ret; } // As server private HttpResponse createHandshakeResponse () { - var res = HttpResponse.CreateWebSocketResponse (); + var ret = HttpResponse.CreateWebSocketResponse (); - var headers = res.Headers; + var headers = ret.Headers; headers["Sec-WebSocket-Accept"] = CreateResponseKey (_base64Key); if (_protocol != null) @@ -888,9 +889,9 @@ namespace WebSocketSharp headers["Sec-WebSocket-Extensions"] = _extensions; if (_cookies.Count > 0) - res.SetCookies (_cookies); + ret.SetCookies (_cookies); - return res; + return ret; } private MessageEventArgs dequeueFromMessageEventQueue () @@ -1087,10 +1088,10 @@ namespace WebSocketSharp var ext = e.Trim (); if (!comp && ext.IsCompressionExtension (CompressionMethod.Deflate)) { _compression = CompressionMethod.Deflate; - var c = _compression.ToExtensionString ( + var str = _compression.ToExtensionString ( "client_no_context_takeover", "server_no_context_takeover"); - buff.AppendFormat ("{0}, ", c); + buff.AppendFormat ("{0}, ", str); comp = true; } } @@ -1728,12 +1729,12 @@ namespace WebSocketSharp /// and releases all associated resources. /// /// - /// This method emits a event if - /// isn't in the allowable range of the close status code. + /// This method emits a event if isn't in + /// the allowable range of the close status code. /// /// - /// A that represents the status code indicating the reason - /// for the close. + /// A that represents the status code indicating the reason for + /// the close. /// public void Close (ushort code) { @@ -1759,8 +1760,8 @@ namespace WebSocketSharp /// and releases all associated resources. /// /// - /// One of the enum values, represents the status code - /// indicating the reason for the close. + /// One of the enum values, represents the status code indicating + /// the reason for the close. /// public void Close (CloseStatusCode code) { @@ -1782,17 +1783,16 @@ namespace WebSocketSharp } /// - /// Closes the WebSocket connection with the specified - /// and , and releases all associated resources. + /// Closes the WebSocket connection with the specified and + /// , and releases all associated resources. /// /// - /// This method emits a event if - /// isn't in the allowable range of the close status code or the size of - /// is greater than 123 bytes. + /// This method emits a event if isn't in + /// the allowable range of the close status code or the size of is + /// greater than 123 bytes. /// /// - /// A that represents the status code indicating the reason - /// for the close. + /// A that represents the status code indicating the reason for the close. /// /// /// A that represents the reason for the close. @@ -1817,16 +1817,16 @@ namespace WebSocketSharp } /// - /// Closes the WebSocket connection with the specified - /// and , and releases all associated resources. + /// Closes the WebSocket connection with the specified and + /// , and releases all associated resources. /// /// - /// This method emits a event if the size of - /// is greater than 123 bytes. + /// This method emits a event if the size of is + /// greater than 123 bytes. /// /// - /// One of the enum values, represents the status code - /// indicating the reason for the close. + /// One of the enum values, represents the status code indicating + /// the reason for the close. /// /// /// A that represents the reason for the close. @@ -1912,8 +1912,8 @@ namespace WebSocketSharp /// This method doesn't wait for the close to be complete. /// /// - /// One of the enum values, represents the status code - /// indicating the reason for the close. + /// One of the enum values, represents + /// the status code indicating the reason for the close. /// public void CloseAsync (CloseStatusCode code) { @@ -1935,8 +1935,8 @@ namespace WebSocketSharp } /// - /// Closes the WebSocket connection asynchronously with the specified - /// and , and releases all associated resources. + /// Closes the WebSocket connection asynchronously with the specified and + /// , and releases all associated resources. /// /// /// @@ -1944,8 +1944,8 @@ namespace WebSocketSharp /// /// /// This method emits a event if isn't in - /// the allowable range of the close status code or the size of - /// is greater than 123 bytes. + /// the allowable range of the close status code or the size of is + /// greater than 123 bytes. /// /// /// @@ -1983,13 +1983,13 @@ namespace WebSocketSharp /// This method doesn't wait for the close to be complete. /// /// - /// This method emits a event if the size of - /// is greater than 123 bytes. + /// This method emits a event if the size of + /// is greater than 123 bytes. /// /// /// - /// One of the enum values, represents the status code - /// indicating the reason for the close. + /// One of the enum values, represents + /// the status code indicating the reason for the close. /// /// /// A that represents the reason for the close. @@ -2099,7 +2099,7 @@ namespace WebSocketSharp } /// - /// Sends a binary using the WebSocket connection. + /// Sends binary using the WebSocket connection. /// /// /// An array of that represents the binary data to send. @@ -2118,8 +2118,7 @@ namespace WebSocketSharp } /// - /// Sends the specified as a binary data - /// using the WebSocket connection. + /// Sends the specified as binary data using the WebSocket connection. /// /// /// A that represents the file to send. @@ -2138,7 +2137,7 @@ namespace WebSocketSharp } /// - /// Sends a text using the WebSocket connection. + /// Sends text using the WebSocket connection. /// /// /// A that represents the text data to send. @@ -2157,7 +2156,7 @@ namespace WebSocketSharp } /// - /// Sends a binary asynchronously using the WebSocket connection. + /// Sends binary asynchronously using the WebSocket connection. /// /// /// This method doesn't wait for the send to be complete. @@ -2184,8 +2183,8 @@ namespace WebSocketSharp } /// - /// Sends the specified as a binary data asynchronously - /// using the WebSocket connection. + /// Sends the specified as binary data asynchronously using + /// the WebSocket connection. /// /// /// This method doesn't wait for the send to be complete. @@ -2212,7 +2211,7 @@ namespace WebSocketSharp } /// - /// Sends a text asynchronously using the WebSocket connection. + /// Sends text asynchronously using the WebSocket connection. /// /// /// This method doesn't wait for the send to be complete. @@ -2239,8 +2238,8 @@ namespace WebSocketSharp } /// - /// Sends a binary data from the specified asynchronously - /// using the WebSocket connection. + /// Sends binary data from the specified asynchronously using + /// the WebSocket connection. /// /// /// This method doesn't wait for the send to be complete. @@ -2283,7 +2282,7 @@ namespace WebSocketSharp if (len < length) _logger.Warn ( String.Format ( - "The data with 'length' cannot be read from 'stream'.\nexpected: {0} actual: {1}", + "The data with 'length' cannot be read from 'stream':\n expected: {0}\n actual: {1}", length, len)); @@ -2298,8 +2297,8 @@ namespace WebSocketSharp } /// - /// Sets an HTTP to send with the WebSocket connection request - /// to the server. + /// Sets an HTTP to send with the WebSocket connection request to + /// the server. /// /// /// A that represents the cookie to send. @@ -2307,9 +2306,7 @@ namespace WebSocketSharp public void SetCookie (Cookie cookie) { lock (_forConn) { - var msg = checkIfAvailable (false, false) ?? - (cookie == null ? "'cookie' is null." : null); - + var msg = checkIfAvailable (false, false) ?? (cookie == null ? "'cookie' is null." : null); if (msg != null) { _logger.Error (msg); error ("An error has occurred in setting the cookie.", null);