[Modify] It throws exceptions

This commit is contained in:
sta 2017-06-01 16:25:07 +09:00
parent 6c2f00d5e5
commit 4ce77fb5c5

View File

@ -1127,12 +1127,52 @@ namespace WebSocketSharp.Server
/// A <see cref="string"/> that represents the reason for the WebSocket /// A <see cref="string"/> that represents the reason for the WebSocket
/// connection close. The size must be 123 bytes or less. /// connection close. The size must be 123 bytes or less.
/// </param> /// </param>
/// <exception cref="ArgumentOutOfRangeException">
/// The size of <paramref name="reason"/> is greater than 123 bytes.
/// </exception>
/// <exception cref="ArgumentException">
/// <para>
/// <paramref name="code"/> is
/// <see cref="CloseStatusCode.MandatoryExtension"/>.
/// </para>
/// <para>
/// -or-
/// </para>
/// <para>
/// <paramref name="code"/> is
/// <see cref="CloseStatusCode.NoStatus"/> and
/// there is <paramref name="reason"/>.
/// </para>
/// <para>
/// -or-
/// </para>
/// <para>
/// <paramref name="reason"/> could not be UTF-8-encoded.
/// </para>
/// </exception>
public void Stop (CloseStatusCode code, string reason) public void Stop (CloseStatusCode code, string reason)
{ {
string msg; if (code == CloseStatusCode.MandatoryExtension) {
if (!WebSocket.CheckParametersForClose (code, reason, false, out msg)) { var msg = "MandatoryExtension cannot be used.";
_log.Error (msg); throw new ArgumentException (msg, "code");
return; }
if (!reason.IsNullOrEmpty ()) {
if (code == CloseStatusCode.NoStatus) {
var msg = "NoStatus cannot be used.";
throw new ArgumentException (msg, "code");
}
byte[] bytes;
if (!reason.TryGetUTF8EncodedBytes (out bytes)) {
var msg = "It could not be UTF-8-encoded.";
throw new ArgumentException (msg, "reason");
}
if (bytes.Length > 123) {
var msg = "Its size is greater than 123 bytes.";
throw new ArgumentOutOfRangeException ("reason", msg);
}
} }
stop ((ushort) code, reason); stop ((ushort) code, reason);