[Modify] Throw exceptions
This commit is contained in:
parent
4d850eb028
commit
4cbec28379
@ -2552,12 +2552,37 @@ namespace WebSocketSharp
|
||||
/// </param>
|
||||
public void Close (ushort code, string reason)
|
||||
{
|
||||
string msg;
|
||||
if (!CheckParametersForClose (code, reason, _client, out msg)) {
|
||||
_logger.Error (msg);
|
||||
error ("An error has occurred in closing the connection.", null);
|
||||
if (!code.IsCloseStatusCode ()) {
|
||||
var msg = "Less than 1000 or greater than 4999.";
|
||||
throw new ArgumentOutOfRangeException ("code", msg);
|
||||
}
|
||||
|
||||
return;
|
||||
if (_client && code == 1011) {
|
||||
var msg = "1011 cannot be used.";
|
||||
throw new ArgumentException (msg, "code");
|
||||
}
|
||||
|
||||
if (!_client && 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);
|
||||
}
|
||||
}
|
||||
|
||||
close (code, reason);
|
||||
|
Loading…
Reference in New Issue
Block a user