[Modify] Throw exceptions

This commit is contained in:
sta 2016-11-22 17:04:22 +09:00
parent d13d4c8c79
commit 4cc4837fbe

View File

@ -2848,17 +2848,19 @@ namespace WebSocketSharp
/// </param> /// </param>
public void SendAsync (string data, Action<bool> completed) public void SendAsync (string data, Action<bool> completed)
{ {
var msg = _readyState.CheckIfAvailable (false, true, false, false) ?? if (_readyState != WebSocketState.Open) {
CheckSendParameter (data); 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);
return;
} }
sendAsync (Opcode.Text, new MemoryStream (data.UTF8Encode ()), completed); if (data == null)
throw new ArgumentNullException ("data");
byte[] bytes;
if (!data.TryGetUTF8EncodedBytes (out bytes))
throw new ArgumentException ("Cannot be UTF8 encoded.", "data");
sendAsync (Opcode.Text, new MemoryStream (bytes), completed);
} }
/// <summary> /// <summary>