[Modify] Throw exceptions
This commit is contained in:
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) {
|
|
||||||
_logger.Error (msg);
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
stream.ReadBytesAsync (
|
if (stream == null)
|
||||||
length,
|
throw new ArgumentNullException ("stream");
|
||||||
data => {
|
|
||||||
var len = data.Length;
|
|
||||||
if (len == 0) {
|
|
||||||
_logger.Error ("The data cannot be read from 'stream'.");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (len < length)
|
if (!stream.CanRead)
|
||||||
_logger.Warn (
|
throw new ArgumentException ("It cannot be read.", "stream");
|
||||||
String.Format (
|
|
||||||
"The data with 'length' cannot be read from 'stream':\n expected: {0}\n actual: {1}",
|
|
||||||
length,
|
|
||||||
len));
|
|
||||||
|
|
||||||
if (len <= WebSocket.FragmentLength)
|
if (length < 1)
|
||||||
broadcast (Opcode.Binary, data, completed);
|
throw new ArgumentException ("It is less than 1.", "length");
|
||||||
else
|
|
||||||
broadcast (Opcode.Binary, new MemoryStream (data), completed);
|
var bytes = stream.ReadBytes (length);
|
||||||
},
|
|
||||||
ex => _logger.Fatal (ex.ToString ()));
|
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 (
|
||||||
|
"Only {0} byte(s) of data could be read from the specified stream.",
|
||||||
|
len
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (len <= WebSocket.FragmentLength)
|
||||||
|
broadcastAsync (Opcode.Binary, bytes, completed);
|
||||||
|
else
|
||||||
|
broadcastAsync (Opcode.Binary, new MemoryStream (bytes), completed);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
Loading…
Reference in New Issue
Block a user