[Modify] Throw exceptions

master
sta 9 years ago
parent 18a165d6e4
commit 0e9ec9bf89

@ -704,36 +704,39 @@ namespace WebSocketSharp.Server
/// </param> /// </param>
public void BroadcastAsync (Stream stream, int length, Action completed) public void BroadcastAsync (Stream stream, int length, Action completed)
{ {
var msg = _state.CheckIfAvailable (false, true, false) ?? if (_state != ServerState.Start) {
WebSocket.CheckSendParameters (stream, length); var msg = "The current state of the manager is not Start.";
throw new InvalidOperationException (msg);
}
if (msg != null) { if (stream == null)
_logger.Error (msg); throw new ArgumentNullException ("stream");
return;
} if (!stream.CanRead)
throw new ArgumentException ("It cannot be read.", "stream");
stream.ReadBytesAsync (
length, if (length < 1)
data => { throw new ArgumentException ("It is less than 1.", "length");
var len = data.Length;
if (len == 0) { var bytes = stream.ReadBytes (length);
_logger.Error ("The data cannot be read from 'stream'.");
return; var len = bytes.Length;
} if (len == 0)
throw new ArgumentException ("No data could be read from it.", "stream");
if (len < length)
_logger.Warn ( if (len < length) {
String.Format ( _logger.Warn (
"The data with 'length' cannot be read from 'stream':\n expected: {0}\n actual: {1}", String.Format (
length, "Only {0} byte(s) of data could be read from the specified stream.",
len)); len
)
if (len <= WebSocket.FragmentLength) );
broadcast (Opcode.Binary, data, completed); }
else
broadcast (Opcode.Binary, new MemoryStream (data), completed); if (len <= WebSocket.FragmentLength)
}, broadcastAsync (Opcode.Binary, bytes, completed);
ex => _logger.Fatal (ex.ToString ())); else
broadcastAsync (Opcode.Binary, new MemoryStream (bytes), completed);
} }
/// <summary> /// <summary>

Loading…
Cancel
Save