[Modify] Throw exceptions

This commit is contained in:
sta 2017-08-05 16:04:40 +09:00
parent 1ac454bd34
commit 3d98fd90b7

View File

@ -437,15 +437,20 @@ namespace WebSocketSharp.Server
/// </param> /// </param>
public void Broadcast (string data) public void Broadcast (string data)
{ {
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; if (data == null)
throw new ArgumentNullException ("data");
byte[] bytes;
if (!data.TryGetUTF8EncodedBytes (out bytes)) {
var msg = "It could not be UTF-8-encoded.";
throw new ArgumentException (msg, "data");
} }
var bytes = data.UTF8Encode ();
if (bytes.LongLength <= WebSocket.FragmentLength) if (bytes.LongLength <= WebSocket.FragmentLength)
broadcast (Opcode.Text, bytes, null); broadcast (Opcode.Text, bytes, null);
else else