[Modify] Throw exceptions
This commit is contained in:
parent
a02b212d74
commit
5a91fbd318
@ -2652,14 +2652,37 @@ namespace WebSocketSharp
|
||||
/// </param>
|
||||
public void Close (CloseStatusCode 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 (_client && code == CloseStatusCode.ServerError) {
|
||||
var msg = "ServerError cannot be used.";
|
||||
throw new ArgumentException (msg, "code");
|
||||
}
|
||||
|
||||
if (!_client && code == CloseStatusCode.MandatoryExtension) {
|
||||
var msg = "MandatoryExtension cannot be used.";
|
||||
throw new ArgumentException (msg, "code");
|
||||
}
|
||||
|
||||
if (reason.IsNullOrEmpty ()) {
|
||||
close ((ushort) code, String.Empty);
|
||||
return;
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
close ((ushort) code, reason);
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user