[Modify] Throw exceptions

master
sta 9 years ago
parent d13d4c8c79
commit 4cc4837fbe

@ -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) { if (data == null)
_logger.Error (msg); throw new ArgumentNullException ("data");
error ("An error has occurred in sending data.", null);
return; byte[] bytes;
} if (!data.TryGetUTF8EncodedBytes (out bytes))
throw new ArgumentException ("Cannot be UTF8 encoded.", "data");
sendAsync (Opcode.Text, new MemoryStream (data.UTF8Encode ()), completed); sendAsync (Opcode.Text, new MemoryStream (bytes), completed);
} }
/// <summary> /// <summary>

Loading…
Cancel
Save