diff --git a/websocket-sharp/Ext.cs b/websocket-sharp/Ext.cs index 7e90ebf1..7ecb912c 100644 --- a/websocket-sharp/Ext.cs +++ b/websocket-sharp/Ext.cs @@ -223,18 +223,24 @@ namespace WebSocketSharp : null; } - internal static string CheckIfStarted (this ServerState state) + internal static string CheckIfStart (this ServerState state) { - return state != ServerState.START - ? "Any of not started, on shutdown or stopped." - : null; + return state == ServerState.READY + ? "The server hasn't started yet." + : state == ServerState.SHUTDOWN + ? "The server is shutting down." + : state == ServerState.STOP + ? "The server has already stopped." + : null; } internal static string CheckIfStopped (this ServerState state) { - return state == ServerState.START || state == ServerState.SHUTDOWN - ? "Already started or on shutdown." - : null; + return state == ServerState.START + ? "The server has already started." + : state == ServerState.SHUTDOWN + ? "The server is shutting down." + : null; } internal static string CheckIfValidCloseStatusCode (this ushort code) @@ -259,6 +265,13 @@ namespace WebSocketSharp : null; } + internal static string CheckIfValidSendData (this FileInfo file) + { + return file == null + ? "'file' must not be null." + : null; + } + internal static string CheckIfValidSendData (this string data) { return data == null diff --git a/websocket-sharp/Server/HttpServer.cs b/websocket-sharp/Server/HttpServer.cs index 80876224..99d99b17 100644 --- a/websocket-sharp/Server/HttpServer.cs +++ b/websocket-sharp/Server/HttpServer.cs @@ -537,7 +537,7 @@ namespace WebSocketSharp.Server private string checkIfCanStop (Func checkParams) { - return _state.CheckIfStarted () ?? checkParams (); + return _state.CheckIfStart () ?? checkParams (); } private string checkIfCertExists () @@ -742,7 +742,7 @@ namespace WebSocketSharp.Server public void Stop () { lock (_sync) { - var msg = _state.CheckIfStarted (); + var msg = _state.CheckIfStart (); if (msg != null) { _logger.Error (String.Format ("{0}\nstate: {1}", msg, _state)); return; diff --git a/websocket-sharp/Server/WebSocketServer.cs b/websocket-sharp/Server/WebSocketServer.cs index 9d2f83cf..8b127d64 100644 --- a/websocket-sharp/Server/WebSocketServer.cs +++ b/websocket-sharp/Server/WebSocketServer.cs @@ -551,7 +551,7 @@ namespace WebSocketSharp.Server private string checkIfCanStop (Func checkParams) { - return _state.CheckIfStarted () ?? checkParams (); + return _state.CheckIfStart () ?? checkParams (); } private string checkIfCertExists () @@ -758,7 +758,7 @@ namespace WebSocketSharp.Server public void Stop () { lock (_sync) { - var msg = _state.CheckIfStarted (); + var msg = _state.CheckIfStart (); if (msg != null) { _logger.Error (String.Format ("{0}\nstate: {1}", msg, _state)); return; diff --git a/websocket-sharp/Server/WebSocketService.cs b/websocket-sharp/Server/WebSocketService.cs index 2089c49a..906283e3 100644 --- a/websocket-sharp/Server/WebSocketService.cs +++ b/websocket-sharp/Server/WebSocketService.cs @@ -270,11 +270,11 @@ namespace WebSocketSharp.Server } /// - /// Sends a binary to the client of the current - /// instance. + /// Sends a binary to the client on the current + /// session in the WebSocket service. /// /// - /// An array of that contains the binary data to send. + /// An array of that represents the binary data to send. /// protected void Send (byte [] data) { @@ -283,11 +283,11 @@ namespace WebSocketSharp.Server } /// - /// Sends a binary data from the specified to - /// the client of the current instance. + /// Sends the specified as a binary data + /// to the client on the current session in the WebSocket service. /// /// - /// A from which contains the binary data to send. + /// A that represents the file to send. /// protected void Send (FileInfo file) { @@ -296,8 +296,8 @@ namespace WebSocketSharp.Server } /// - /// Sends a text to the client of the current - /// instance. + /// Sends a text to the client on the current + /// session in the WebSocket service. /// /// /// A that represents the text data to send. @@ -309,20 +309,19 @@ namespace WebSocketSharp.Server } /// - /// Sends a binary asynchronously to the client of the - /// current instance. + /// Sends a binary asynchronously to the client + /// on the current session in the WebSocket service. /// /// /// This method doesn't wait for the send to be complete. /// /// - /// An array of that contains the binary data to send. + /// An array of that represents the binary data to send. /// /// /// An Action<bool> delegate that references the method(s) called when - /// the send is complete. - /// A passed to this delegate is true if the send is - /// complete successfully; otherwise, false. + /// the send is complete. A passed to this delegate is + /// true if the send is complete successfully; otherwise, false. /// protected void SendAsync (byte [] data, Action completed) { @@ -331,21 +330,20 @@ namespace WebSocketSharp.Server } /// - /// Sends a binary data from the specified - /// asynchronously to the client of the current - /// instance. + /// Sends the specified as a binary data + /// asynchronously to the client on the current session in the WebSocket + /// service. /// /// /// This method doesn't wait for the send to be complete. /// /// - /// A from which contains the binary data to send. + /// A that represents the file to send. /// /// /// An Action<bool> delegate that references the method(s) called when - /// the send is complete. - /// A passed to this delegate is true if the send is - /// complete successfully; otherwise, false. + /// the send is complete. A passed to this delegate is + /// true if the send is complete successfully; otherwise, false. /// protected void SendAsync (FileInfo file, Action completed) { @@ -354,8 +352,8 @@ namespace WebSocketSharp.Server } /// - /// Sends a text asynchronously to the client of the - /// current instance. + /// Sends a text asynchronously to the client + /// on the current session in the WebSocket service. /// /// /// This method doesn't wait for the send to be complete. @@ -365,9 +363,8 @@ namespace WebSocketSharp.Server /// /// /// An Action<bool> delegate that references the method(s) called when - /// the send is complete. - /// A passed to this delegate is true if the send is - /// complete successfully; otherwise, false. + /// the send is complete. A passed to this delegate is + /// true if the send is complete successfully; otherwise, false. /// protected void SendAsync (string data, Action completed) { @@ -377,22 +374,21 @@ namespace WebSocketSharp.Server /// /// Sends a binary data from the specified asynchronously - /// to the client of the current instance. + /// to the client on the current session in the WebSocket service. /// /// /// This method doesn't wait for the send to be complete. /// /// - /// A object from which contains the binary data to send. + /// A from which contains the binary data to send. /// /// /// An that represents the number of bytes to send. /// /// /// An Action<bool> delegate that references the method(s) called when - /// the send is complete. - /// A passed to this delegate is true if the send is - /// complete successfully; otherwise, false. + /// the send is complete. A passed to this delegate is + /// true if the send is complete successfully; otherwise, false. /// protected void SendAsync (Stream stream, int length, Action completed) { diff --git a/websocket-sharp/Server/WebSocketServiceHostManager.cs b/websocket-sharp/Server/WebSocketServiceHostManager.cs index 36c55eed..90a72fe1 100644 --- a/websocket-sharp/Server/WebSocketServiceHostManager.cs +++ b/websocket-sharp/Server/WebSocketServiceHostManager.cs @@ -263,6 +263,11 @@ namespace WebSocketSharp.Server return result; } + private string checkIfCanSend (Func checkParams) + { + return _state.CheckIfStart () ?? checkParams (); + } + #endregion #region Internal Methods @@ -359,15 +364,16 @@ namespace WebSocketSharp.Server #region Public Methods /// - /// Broadcasts a binary to all clients of the - /// WebSocket services provided by the server. + /// Broadcasts a binary to all clients + /// of the WebSocket services provided by the server. /// /// - /// An array of that contains the binary data to broadcast. + /// An array of that represents the binary data + /// to broadcast. /// public void Broadcast (byte [] data) { - var msg = _state.CheckIfStarted () ?? data.CheckIfValidSendData (); + var msg = checkIfCanSend (() => data.CheckIfValidSendData ()); if (msg != null) { _logger.Error (msg); return; @@ -380,15 +386,15 @@ namespace WebSocketSharp.Server } /// - /// Broadcasts a text to all clients of the WebSocket - /// services provided by the server. + /// Broadcasts a text to all clients + /// of the WebSocket services provided by the server. /// /// /// A that represents the text data to broadcast. /// public void Broadcast (string data) { - var msg = _state.CheckIfStarted () ?? data.CheckIfValidSendData (); + var msg = checkIfCanSend (() => data.CheckIfValidSendData ()); if (msg != null) { _logger.Error (msg); return; @@ -409,7 +415,8 @@ namespace WebSocketSharp.Server /// This method doesn't wait for the broadcast to be complete. /// /// - /// An array of that contains the binary data to broadcast. + /// An array of that represents the binary data + /// to broadcast. /// /// /// A delegate that references the method(s) called when @@ -417,7 +424,7 @@ namespace WebSocketSharp.Server /// public void BroadcastAsync (byte [] data, Action completed) { - var msg = _state.CheckIfStarted () ?? data.CheckIfValidSendData (); + var msg = checkIfCanSend (() => data.CheckIfValidSendData ()); if (msg != null) { _logger.Error (msg); return; @@ -430,8 +437,8 @@ namespace WebSocketSharp.Server } /// - /// Broadcasts a text asynchronously to all clients of - /// the WebSocket services provided by the server. + /// Broadcasts a text asynchronously to all clients + /// of the WebSocket services provided by the server. /// /// /// This method doesn't wait for the broadcast to be complete. @@ -445,7 +452,7 @@ namespace WebSocketSharp.Server /// public void BroadcastAsync (string data, Action completed) { - var msg = _state.CheckIfStarted () ?? data.CheckIfValidSendData (); + var msg = checkIfCanSend (() => data.CheckIfValidSendData ()); if (msg != null) { _logger.Error (msg); return; @@ -460,15 +467,14 @@ namespace WebSocketSharp.Server /// /// Broadcasts a binary data from the specified - /// asynchronously to all clients of the WebSocket services provided by the - /// server. + /// asynchronously to all clients of the WebSocket services provided + /// by the server. /// /// /// This method doesn't wait for the broadcast to be complete. /// /// - /// A object from which contains the binary data to - /// broadcast. + /// A from which contains the binary data to broadcast. /// /// /// An that represents the number of bytes to broadcast. @@ -479,9 +485,9 @@ namespace WebSocketSharp.Server /// public void BroadcastAsync (Stream stream, int length, Action completed) { - var msg = _state.CheckIfStarted () ?? - stream.CheckIfCanRead () ?? - (length < 1 ? "'length' must be greater than 0." : null); + var msg = checkIfCanSend ( + () => stream.CheckIfCanRead () ?? + (length < 1 ? "'length' must be greater than 0." : null)); if (msg != null) { _logger.Error (msg); @@ -521,7 +527,8 @@ namespace WebSocketSharp.Server /// service to find. /// /// - /// An array of that contains the binary data to broadcast. + /// An array of that represents the binary data + /// to broadcast. /// public void BroadcastTo (string servicePath, byte [] data) { @@ -531,8 +538,8 @@ namespace WebSocketSharp.Server } /// - /// Broadcasts a text to all clients of the WebSocket - /// service with the specified . + /// Broadcasts a text to all clients of the + /// WebSocket service with the specified . /// /// /// A that represents the absolute path to the WebSocket @@ -560,7 +567,8 @@ namespace WebSocketSharp.Server /// service to find. /// /// - /// An array of that contains the binary data to broadcast. + /// An array of that represents the binary data + /// to broadcast. /// /// /// A delegate that references the method(s) called when @@ -575,8 +583,8 @@ namespace WebSocketSharp.Server } /// - /// Broadcasts a text asynchronously to all clients of - /// the WebSocket service with the specified . + /// Broadcasts a text asynchronously to all clients + /// of the WebSocket service with the specified . /// /// /// This method doesn't wait for the broadcast to be complete. @@ -602,8 +610,8 @@ namespace WebSocketSharp.Server /// /// Broadcasts a binary data from the specified - /// asynchronously to all clients of the WebSocket service with the specified - /// . + /// asynchronously to all clients of the WebSocket service with the + /// specified . /// /// /// This method doesn't wait for the broadcast to be complete. @@ -613,8 +621,7 @@ namespace WebSocketSharp.Server /// service to find. /// /// - /// A object from which contains the binary data to - /// broadcast. + /// A from which contains the binary data to broadcast. /// /// /// An that represents the number of bytes to broadcast. @@ -643,7 +650,7 @@ namespace WebSocketSharp.Server /// public Dictionary> Broadping () { - var msg = _state.CheckIfStarted (); + var msg = _state.CheckIfStart (); if (msg != null) { _logger.Error (msg); return null; @@ -671,8 +678,9 @@ namespace WebSocketSharp.Server return Broadping (); byte [] data = null; - var msg = _state.CheckIfStarted () ?? - (data = Encoding.UTF8.GetBytes (message)).CheckIfValidControlData ("message"); + var msg = checkIfCanSend ( + () => (data = Encoding.UTF8.GetBytes (message)) + .CheckIfValidControlData ("message")); if (msg != null) { _logger.Error (msg); @@ -851,19 +859,19 @@ namespace WebSocketSharp.Server } /// - /// Sends a binary to the client associated with the - /// specified and . + /// Sends a binary to the client on the session with + /// the specified , in the WebSocket service with the + /// specified . /// /// /// A that represents the absolute path to the WebSocket /// service to find. /// /// - /// A that represents the ID of the session to send the - /// data to. + /// A that represents the ID of the session to find. /// /// - /// An array of that contains the binary data to send. + /// An array of that represents the binary data to send. /// public void SendTo (string servicePath, string id, byte [] data) { @@ -873,16 +881,16 @@ namespace WebSocketSharp.Server } /// - /// Sends a text to the client associated with the - /// specified and . + /// Sends a text to the client on the session with + /// the specified , in the WebSocket service with the + /// specified . /// /// /// A that represents the absolute path to the WebSocket /// service to find. /// /// - /// A that represents the ID of the session to send the - /// data to. + /// A that represents the ID of the session to find. /// /// /// A that represents the text data to send. @@ -895,9 +903,9 @@ namespace WebSocketSharp.Server } /// - /// Sends a binary asynchronously to the client - /// associated with the specified and - /// . + /// Sends a binary asynchronously to the client on the + /// session with the specified , in the WebSocket service + /// with the specified . /// /// /// This method doesn't wait for the send to be complete. @@ -907,11 +915,10 @@ namespace WebSocketSharp.Server /// service to find. /// /// - /// A that represents the ID of the session to send the - /// data to. + /// A that represents the ID of the session to find. /// /// - /// An array of that contains the binary data to send. + /// An array of that represents the binary data to send. /// /// /// An Action<bool> delegate that references the method(s) called when @@ -928,9 +935,9 @@ namespace WebSocketSharp.Server } /// - /// Sends a text asynchronously to the client - /// associated with the specified and - /// . + /// Sends a text asynchronously to the client on the + /// session with the specified , in the WebSocket service + /// with the specified . /// /// /// This method doesn't wait for the send to be complete. @@ -940,8 +947,7 @@ namespace WebSocketSharp.Server /// service to find. /// /// - /// A that represents the ID of the session to send the - /// data to. + /// A that represents the ID of the session to find. /// /// /// A that represents the text data to send. @@ -962,8 +968,8 @@ namespace WebSocketSharp.Server /// /// Sends a binary data from the specified asynchronously - /// to the client associated with the specified - /// and . + /// to the client on the session with the specified , in + /// the WebSocket service with the specified . /// /// /// This method doesn't wait for the send to be complete. @@ -973,11 +979,10 @@ namespace WebSocketSharp.Server /// service to find. /// /// - /// A that represents the ID of the session to send the - /// data to. + /// A that represents the ID of the session to find. /// /// - /// A object from which contains the binary data to send. + /// A from which contains the binary data to send. /// /// /// An that represents the number of bytes to send. @@ -1016,7 +1021,7 @@ namespace WebSocketSharp.Server public bool TryGetServiceHost ( string servicePath, out WebSocketServiceHost serviceHost) { - var msg = _state.CheckIfStarted () ?? servicePath.CheckIfValidServicePath (); + var msg = _state.CheckIfStart () ?? servicePath.CheckIfValidServicePath (); if (msg != null) { _logger.Error (msg); serviceHost = null; diff --git a/websocket-sharp/Server/WebSocketSessionManager.cs b/websocket-sharp/Server/WebSocketSessionManager.cs index 9b20cad2..28d72313 100644 --- a/websocket-sharp/Server/WebSocketSessionManager.cs +++ b/websocket-sharp/Server/WebSocketSessionManager.cs @@ -276,6 +276,11 @@ namespace WebSocketSharp.Server state => broadcast (opcode, stream, completed)); } + private string checkIfCanSend (Func checkParams) + { + return _state.CheckIfStart () ?? checkParams (); + } + private static string createID () { return Guid.NewGuid ().ToString ("N"); @@ -398,15 +403,16 @@ namespace WebSocketSharp.Server #region Public Methods /// - /// Broadcasts a binary to all clients of the - /// WebSocket service. + /// Broadcasts a binary to all clients + /// of the WebSocket service. /// /// - /// An array of that contains the binary data to broadcast. + /// An array of that represents the binary data + /// to broadcast. /// public void Broadcast (byte [] data) { - var msg = _state.CheckIfStarted () ?? data.CheckIfValidSendData (); + var msg = checkIfCanSend (() => data.CheckIfValidSendData ()); if (msg != null) { _logger.Error (msg); return; @@ -419,15 +425,15 @@ namespace WebSocketSharp.Server } /// - /// Broadcasts a text to all clients of the WebSocket - /// service. + /// Broadcasts a text to all clients + /// of the WebSocket service. /// /// /// A that represents the text data to broadcast. /// public void Broadcast (string data) { - var msg = _state.CheckIfStarted () ?? data.CheckIfValidSendData (); + var msg = checkIfCanSend (() => data.CheckIfValidSendData ()); if (msg != null) { _logger.Error (msg); return; @@ -448,7 +454,8 @@ namespace WebSocketSharp.Server /// This method doesn't wait for the broadcast to be complete. /// /// - /// An array of that contains the binary data to broadcast. + /// An array of that represents the binary data + /// to broadcast. /// /// /// A delegate that references the method(s) called when @@ -456,7 +463,7 @@ namespace WebSocketSharp.Server /// public void BroadcastAsync (byte [] data, Action completed) { - var msg = _state.CheckIfStarted () ?? data.CheckIfValidSendData (); + var msg = checkIfCanSend (() => data.CheckIfValidSendData ()); if (msg != null) { _logger.Error (msg); return; @@ -469,8 +476,8 @@ namespace WebSocketSharp.Server } /// - /// Broadcasts a text asynchronously to all clients of - /// the WebSocket service. + /// Broadcasts a text asynchronously to all clients + /// of the WebSocket service. /// /// /// This method doesn't wait for the broadcast to be complete. @@ -484,7 +491,7 @@ namespace WebSocketSharp.Server /// public void BroadcastAsync (string data, Action completed) { - var msg = _state.CheckIfStarted () ?? data.CheckIfValidSendData (); + var msg = checkIfCanSend (() => data.CheckIfValidSendData ()); if (msg != null) { _logger.Error (msg); return; @@ -505,8 +512,7 @@ namespace WebSocketSharp.Server /// This method doesn't wait for the broadcast to be complete. /// /// - /// A object from which contains the binary data to - /// broadcast. + /// A from which contains the binary data to broadcast. /// /// /// An that represents the number of bytes to broadcast. @@ -517,9 +523,9 @@ namespace WebSocketSharp.Server /// public void BroadcastAsync (Stream stream, int length, Action completed) { - var msg = _state.CheckIfStarted () ?? - stream.CheckIfCanRead () ?? - (length < 1 ? "'length' must be greater than 0." : null); + var msg = checkIfCanSend ( + () => stream.CheckIfCanRead () ?? + (length < 1 ? "'length' must be greater than 0." : null)); if (msg != null) { _logger.Error (msg); @@ -560,7 +566,7 @@ namespace WebSocketSharp.Server /// public Dictionary Broadping () { - var msg = _state.CheckIfStarted (); + var msg = _state.CheckIfStart (); if (msg != null) { _logger.Error (msg); return null; @@ -587,8 +593,9 @@ namespace WebSocketSharp.Server return Broadping (); byte [] data = null; - var msg = _state.CheckIfStarted () ?? - (data = Encoding.UTF8.GetBytes (message)).CheckIfValidControlData ("message"); + var msg = checkIfCanSend ( + () => (data = Encoding.UTF8.GetBytes (message)) + .CheckIfValidControlData ("message")); if (msg != null) { _logger.Error (msg); @@ -695,15 +702,14 @@ namespace WebSocketSharp.Server } /// - /// Sends a binary to the client associated with the - /// specified . + /// Sends a binary to the client on the session + /// with the specified . /// /// - /// A that represents the ID of the session to send the - /// data to. + /// A that represents the ID of the session to find. /// /// - /// An array of that contains the binary data to send. + /// An array of that represents the binary data to send. /// public void SendTo (string id, byte [] data) { @@ -713,11 +719,11 @@ namespace WebSocketSharp.Server } /// - /// Sends a text to the client associated with the - /// specified . + /// Sends a text to the client on the session + /// with the specified . /// /// - /// A that represents the ID of the session to send the + /// A that represents the ID of the session to find. /// data to. /// /// @@ -732,17 +738,16 @@ namespace WebSocketSharp.Server /// /// Sends a binary asynchronously to the client - /// associated with the specified . + /// on the session with the specified . /// /// /// This method doesn't wait for the send to be complete. /// /// - /// A that represents the ID of the session to send the - /// data to. + /// A that represents the ID of the session to find. /// /// - /// An array of that contains the binary data to send. + /// An array of that represents the binary data to send. /// /// /// An Action<bool> delegate that references the method(s) called when @@ -759,14 +764,13 @@ namespace WebSocketSharp.Server /// /// Sends a text asynchronously to the client - /// associated with the specified . + /// on the session with the specified . /// /// /// This method doesn't wait for the send to be complete. /// /// - /// A that represents the ID of the session to send the - /// data to. + /// A that represents the ID of the session to find. /// /// /// A that represents the text data to send. @@ -786,17 +790,16 @@ namespace WebSocketSharp.Server /// /// Sends a binary data from the specified asynchronously - /// to the client associated with the specified . + /// to the client on the session with the specified . /// /// /// This method doesn't wait for the send to be complete. /// /// - /// A that represents the ID of the session to send the - /// data to. + /// A that represents the ID of the session to find. /// /// - /// A object from which contains the binary data to send. + /// A from which contains the binary data to send. /// /// /// An that represents the number of bytes to send. @@ -864,7 +867,7 @@ namespace WebSocketSharp.Server /// public bool TryGetSession (string id, out IWebSocketSession session) { - var msg = _state.CheckIfStarted () ?? id.CheckIfValidSessionID (); + var msg = _state.CheckIfStart () ?? id.CheckIfValidSessionID (); if (msg != null) { _logger.Error (msg); session = null; diff --git a/websocket-sharp/WebSocket.cs b/websocket-sharp/WebSocket.cs index 190d1594..754c57fd 100644 --- a/websocket-sharp/WebSocket.cs +++ b/websocket-sharp/WebSocket.cs @@ -650,6 +650,11 @@ namespace WebSocketSharp : _readyState.CheckIfConnectable (); } + private string checkIfCanSend (Func checkParams) + { + return _readyState.CheckIfOpen () ?? checkParams (); + } + // As server private string checkIfValidHandshakeRequest (WebSocketContext context) { @@ -1054,7 +1059,7 @@ namespace WebSocketSharp return res; } - private bool send (byte [] frameAsBytes) + private bool send (byte [] frame) { lock (_forConn) { if (_readyState != WebSocketState.OPEN) { @@ -1065,7 +1070,7 @@ namespace WebSocketSharp return false; } - return _stream.Write (frameAsBytes); + return _stream.Write (frame); } } @@ -1860,11 +1865,11 @@ namespace WebSocketSharp /// Sends a binary using the WebSocket connection. /// /// - /// An array of that contains the binary data to send. + /// An array of that represents the binary data to send. /// public void Send (byte [] data) { - var msg = _readyState.CheckIfOpen () ?? data.CheckIfValidSendData (); + var msg = checkIfCanSend (() => data.CheckIfValidSendData ()); if (msg != null) { _logger.Error (msg); error (msg); @@ -1884,17 +1889,15 @@ namespace WebSocketSharp } /// - /// Sends a binary data from the specified using the - /// WebSocket connection. + /// Sends the specified as a binary data + /// using the WebSocket connection. /// /// - /// A from which contains the binary data to send. + /// A that represents the file to send. /// public void Send (FileInfo file) { - var msg = _readyState.CheckIfOpen () ?? - (file == null ? "'file' must not be null." : null); - + var msg = checkIfCanSend (() => file.CheckIfValidSendData ()); if (msg != null) { _logger.Error (msg); error (msg); @@ -1913,7 +1916,7 @@ namespace WebSocketSharp /// public void Send (string data) { - var msg = _readyState.CheckIfOpen () ?? data.CheckIfValidSendData (); + var msg = checkIfCanSend (() => data.CheckIfValidSendData ()); if (msg != null) { _logger.Error (msg); error (msg); @@ -1929,24 +1932,23 @@ namespace WebSocketSharp } /// - /// Sends a binary asynchronously using the WebSocket - /// connection. + /// Sends a binary asynchronously + /// using the WebSocket connection. /// /// /// This method doesn't wait for the send to be complete. /// /// - /// An array of that contains the binary data to send. + /// An array of that represents the binary data to send. /// /// /// An Action<bool> delegate that references the method(s) called when - /// the send is complete. - /// A passed to this delegate is true if the send is - /// complete successfully; otherwise, false. + /// the send is complete. A passed to this delegate is + /// true if the send is complete successfully; otherwise, false. /// public void SendAsync (byte [] data, Action completed) { - var msg = _readyState.CheckIfOpen () ?? data.CheckIfValidSendData (); + var msg = checkIfCanSend (() => data.CheckIfValidSendData ()); if (msg != null) { _logger.Error (msg); error (msg); @@ -1967,26 +1969,23 @@ namespace WebSocketSharp } /// - /// Sends a binary data from the specified + /// Sends the specified as a binary data /// asynchronously using the WebSocket connection. /// /// /// This method doesn't wait for the send to be complete. /// /// - /// A from which contains the binary data to send. + /// A that represents the file to send. /// /// /// An Action<bool> delegate that references the method(s) called when - /// the send is complete. - /// A passed to this delegate is true if the send is - /// complete successfully; otherwise, false. + /// the send is complete. A passed to this delegate is + /// true if the send is complete successfully; otherwise, false. /// public void SendAsync (FileInfo file, Action completed) { - var msg = _readyState.CheckIfOpen () ?? - (file == null ? "'file' must not be null." : null); - + var msg = checkIfCanSend (() => file.CheckIfValidSendData ()); if (msg != null) { _logger.Error (msg); error (msg); @@ -1998,8 +1997,8 @@ namespace WebSocketSharp } /// - /// Sends a text asynchronously using the WebSocket - /// connection. + /// Sends a text asynchronously + /// using the WebSocket connection. /// /// /// This method doesn't wait for the send to be complete. @@ -2009,13 +2008,12 @@ namespace WebSocketSharp /// /// /// An Action<bool> delegate that references the method(s) called when - /// the send is complete. - /// A passed to this delegate is true if the send is - /// complete successfully; otherwise, false. + /// the send is complete. A passed to this delegate is + /// true if the send is complete successfully; otherwise, false. /// public void SendAsync (string data, Action completed) { - var msg = _readyState.CheckIfOpen () ?? data.CheckIfValidSendData (); + var msg = checkIfCanSend (() => data.CheckIfValidSendData ()); if (msg != null) { _logger.Error (msg); error (msg); @@ -2031,29 +2029,28 @@ namespace WebSocketSharp } /// - /// Sends a binary data from the specified asynchronously - /// using the WebSocket connection. + /// Sends a binary data from the specified + /// asynchronously using the WebSocket connection. /// /// /// This method doesn't wait for the send to be complete. /// /// - /// A object from which contains the binary data to send. + /// A from which contains the binary data to send. /// /// /// An that represents the number of bytes to send. /// /// /// An Action<bool> delegate that references the method(s) called when - /// the send is complete. - /// A passed to this delegate is true if the send is - /// complete successfully; otherwise, false. + /// the send is complete. A passed to this delegate is + /// true if the send is complete successfully; otherwise, false. /// public void SendAsync (Stream stream, int length, Action completed) { - var msg = _readyState.CheckIfOpen () ?? - stream.CheckIfCanRead () ?? - (length < 1 ? "'length' must be greater than 0." : null); + var msg = checkIfCanSend ( + () => stream.CheckIfCanRead () ?? + (length < 1 ? "'length' must be greater than 0." : null)); if (msg != null) { _logger.Error (msg); @@ -2067,9 +2064,9 @@ namespace WebSocketSharp data => { var len = data.Length; if (len == 0) { - var err = "A data cannot be read from 'stream'."; - _logger.Error (err); - error (err); + msg = "A data cannot be read from 'stream'."; + _logger.Error (msg); + error (msg); return; }