diff --git a/websocket-sharp/Server/WebSocketServer.cs b/websocket-sharp/Server/WebSocketServer.cs index 80e8e7f9..5d678dbc 100644 --- a/websocket-sharp/Server/WebSocketServer.cs +++ b/websocket-sharp/Server/WebSocketServer.cs @@ -1448,15 +1448,54 @@ namespace WebSocketSharp.Server /// A that represents the reason for /// the close. The size must be 123 bytes or less in UTF-8. /// + /// + /// The size of is greater than 123 bytes. + /// + /// + /// + /// is + /// . + /// + /// + /// -or- + /// + /// + /// is and + /// there is . + /// + /// + /// -or- + /// + /// + /// could not be UTF-8-encoded. + /// + /// /// /// The underlying has failed to stop. /// public void Stop (CloseStatusCode code, string reason) { - string msg; - if (!WebSocket.CheckParametersForClose (code, reason, false, out msg)) { - _log.Error (msg); - return; + if (code == CloseStatusCode.MandatoryExtension) { + var msg = "MandatoryExtension cannot be used."; + throw new ArgumentException (msg, "code"); + } + + 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);