[Modify] Throw exceptions

This commit is contained in:
sta 2017-04-03 17:09:53 +09:00
parent 66ce1f401b
commit 689e0600a6

View File

@ -652,15 +652,18 @@ namespace WebSocketSharp.Server
/// </param> /// </param>
public void BroadcastAsync (string data, Action completed) public void BroadcastAsync (string data, Action completed)
{ {
var msg = _state.CheckIfAvailable (false, true, false) ?? if (_state != ServerState.Start) {
WebSocket.CheckSendParameter (data); var msg = "The current state of the manager is not Start.";
throw new InvalidOperationException (msg);
if (msg != null) {
_logger.Error (msg);
return;
} }
var bytes = data.UTF8Encode (); if (data == null)
throw new ArgumentNullException ("data");
byte[] bytes;
if (!data.TryGetUTF8EncodedBytes (out bytes))
throw new ArgumentException ("It could not be UTF-8-encoded.", "data");
if (bytes.LongLength <= WebSocket.FragmentLength) if (bytes.LongLength <= WebSocket.FragmentLength)
broadcastAsync (Opcode.Text, bytes, completed); broadcastAsync (Opcode.Text, bytes, completed);
else else