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