[Modify] Polish it
This commit is contained in:
parent
a002a77d1d
commit
e65bd0aaee
@ -2907,35 +2907,22 @@ namespace WebSocketSharp
|
|||||||
if (length < 1)
|
if (length < 1)
|
||||||
throw new ArgumentException ("Less than 1.", "length");
|
throw new ArgumentException ("Less than 1.", "length");
|
||||||
|
|
||||||
stream.ReadBytesAsync (
|
var bytes = stream.ReadBytes (length);
|
||||||
length,
|
|
||||||
data => {
|
|
||||||
var len = data.Length;
|
|
||||||
if (len == 0) {
|
|
||||||
_logger.Error ("The data cannot be read from 'stream'.");
|
|
||||||
error ("An error has occurred in sending data.", null);
|
|
||||||
|
|
||||||
return;
|
var len = bytes.Length;
|
||||||
}
|
if (len == 0)
|
||||||
|
throw new ArgumentException ("No data could be read.", "stream");
|
||||||
|
|
||||||
if (len < length)
|
if (len < length) {
|
||||||
_logger.Warn (
|
_logger.Warn (
|
||||||
String.Format (
|
String.Format (
|
||||||
"The length of the data is less than 'length':\n expected: {0}\n actual: {1}",
|
"Only {0} byte(s) of data could be read from the specified stream.",
|
||||||
length,
|
len
|
||||||
len
|
)
|
||||||
)
|
);
|
||||||
);
|
}
|
||||||
|
|
||||||
var sent = send (Opcode.Binary, new MemoryStream (data));
|
sendAsync (Opcode.Binary, new MemoryStream (bytes), completed);
|
||||||
if (completed != null)
|
|
||||||
completed (sent);
|
|
||||||
},
|
|
||||||
ex => {
|
|
||||||
_logger.Error (ex.ToString ());
|
|
||||||
error ("An exception has occurred while sending data.", ex);
|
|
||||||
}
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
Loading…
Reference in New Issue
Block a user