[Modify] Throw exceptions
This commit is contained in:
parent
cf9f3b11e5
commit
31d4c555f9
@ -2991,14 +2991,37 @@ namespace WebSocketSharp
|
|||||||
/// </param>
|
/// </param>
|
||||||
public void CloseAsync (CloseStatusCode code, string reason)
|
public void CloseAsync (CloseStatusCode code, string reason)
|
||||||
{
|
{
|
||||||
string msg;
|
if (_client && code == CloseStatusCode.ServerError) {
|
||||||
if (!CheckParametersForClose (code, reason, _client, out msg)) {
|
var msg = "ServerError cannot be used.";
|
||||||
_logger.Error (msg);
|
throw new ArgumentException (msg, "code");
|
||||||
error ("An error has occurred in closing the connection.", null);
|
}
|
||||||
|
|
||||||
|
if (!_client && code == CloseStatusCode.MandatoryExtension) {
|
||||||
|
var msg = "MandatoryExtension cannot be used.";
|
||||||
|
throw new ArgumentException (msg, "code");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (reason.IsNullOrEmpty ()) {
|
||||||
|
closeAsync ((ushort) code, String.Empty);
|
||||||
return;
|
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);
|
||||||
|
}
|
||||||
|
|
||||||
closeAsync ((ushort) code, reason);
|
closeAsync ((ushort) code, reason);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user