From a002a77d1dbc887d31a910b7e30448e84f5a8761 Mon Sep 17 00:00:00 2001 From: sta Date: Tue, 22 Nov 2016 17:49:42 +0900 Subject: [PATCH] [Modify] Throw exceptions --- websocket-sharp/WebSocket.cs | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/websocket-sharp/WebSocket.cs b/websocket-sharp/WebSocket.cs index 32e53a45..ae9837eb 100644 --- a/websocket-sharp/WebSocket.cs +++ b/websocket-sharp/WebSocket.cs @@ -2893,15 +2893,19 @@ namespace WebSocketSharp /// public void SendAsync (Stream stream, int length, Action completed) { - var msg = _readyState.CheckIfAvailable (false, true, false, false) ?? - CheckSendParameters (stream, length); + if (_readyState != WebSocketState.Open) { + var msg = "The current state of the connection is not Open."; + throw new InvalidOperationException (msg); + } - if (msg != null) { - _logger.Error (msg); - error ("An error has occurred in sending data.", null); + if (stream == null) + throw new ArgumentNullException ("stream"); - return; - } + if (!stream.CanRead) + throw new ArgumentException ("Cannot be read.", "stream"); + + if (length < 1) + throw new ArgumentException ("Less than 1.", "length"); stream.ReadBytesAsync ( length,