[Modify] It throws exceptions
This commit is contained in:
parent
7099e5a43b
commit
4d196e5798
@ -1365,15 +1365,66 @@ namespace WebSocketSharp.Server
|
|||||||
/// A <see cref="string"/> that represents the reason for
|
/// A <see cref="string"/> that represents the reason for
|
||||||
/// the close. The size must be 123 bytes or less in UTF-8.
|
/// the close. The size must be 123 bytes or less in UTF-8.
|
||||||
/// </param>
|
/// </param>
|
||||||
|
/// <exception cref="ArgumentOutOfRangeException">
|
||||||
|
/// <para>
|
||||||
|
/// <paramref name="code"/> is less than 1000 or greater than 4999.
|
||||||
|
/// </para>
|
||||||
|
/// <para>
|
||||||
|
/// -or-
|
||||||
|
/// </para>
|
||||||
|
/// <para>
|
||||||
|
/// The size of <paramref name="reason"/> is greater than 123 bytes.
|
||||||
|
/// </para>
|
||||||
|
/// </exception>
|
||||||
|
/// <exception cref="ArgumentException">
|
||||||
|
/// <para>
|
||||||
|
/// <paramref name="code"/> is 1010 (mandatory extension).
|
||||||
|
/// </para>
|
||||||
|
/// <para>
|
||||||
|
/// -or-
|
||||||
|
/// </para>
|
||||||
|
/// <para>
|
||||||
|
/// <paramref name="code"/> is 1005 (no status) and
|
||||||
|
/// there is <paramref name="reason"/>.
|
||||||
|
/// </para>
|
||||||
|
/// <para>
|
||||||
|
/// -or-
|
||||||
|
/// </para>
|
||||||
|
/// <para>
|
||||||
|
/// <paramref name="reason"/> could not be UTF-8-encoded.
|
||||||
|
/// </para>
|
||||||
|
/// </exception>
|
||||||
/// <exception cref="SocketException">
|
/// <exception cref="SocketException">
|
||||||
/// The underlying <see cref="TcpListener"/> has failed to stop.
|
/// The underlying <see cref="TcpListener"/> has failed to stop.
|
||||||
/// </exception>
|
/// </exception>
|
||||||
public void Stop (ushort code, string reason)
|
public void Stop (ushort code, string reason)
|
||||||
{
|
{
|
||||||
string msg;
|
if (!code.IsCloseStatusCode ()) {
|
||||||
if (!WebSocket.CheckParametersForClose (code, reason, false, out msg)) {
|
var msg = "Less than 1000 or greater than 4999.";
|
||||||
_log.Error (msg);
|
throw new ArgumentOutOfRangeException ("code", msg);
|
||||||
return;
|
}
|
||||||
|
|
||||||
|
if (code == 1010) {
|
||||||
|
var msg = "1010 cannot be used.";
|
||||||
|
throw new ArgumentException (msg, "code");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!reason.IsNullOrEmpty ()) {
|
||||||
|
if (code == 1005) {
|
||||||
|
var msg = "1005 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 (code, reason);
|
stop (code, reason);
|
||||||
|
Loading…
Reference in New Issue
Block a user