From c86e317ef1a4ce8bda725f0dc7cf0f0fdb9fc435 Mon Sep 17 00:00:00 2001 From: sta Date: Thu, 27 Jul 2017 17:39:08 +0900 Subject: [PATCH] [Modify] Polish it --- websocket-sharp/WebSocket.cs | 31 +++++++++++++++++-------------- 1 file changed, 17 insertions(+), 14 deletions(-) diff --git a/websocket-sharp/WebSocket.cs b/websocket-sharp/WebSocket.cs index 8e98df97..83df0180 100644 --- a/websocket-sharp/WebSocket.cs +++ b/websocket-sharp/WebSocket.cs @@ -2613,22 +2613,25 @@ namespace WebSocketSharp throw new ArgumentException (msg, "code"); } - if (!reason.IsNullOrEmpty ()) { - if (code == 1005) { - var msg = "1005 cannot be used."; - throw new ArgumentException (msg, "code"); - } + if (reason.IsNullOrEmpty ()) { + close (code, String.Empty); + return; + } - byte[] bytes; - if (!reason.TryGetUTF8EncodedBytes (out bytes)) { - var msg = "It could not be UTF-8-encoded."; - throw new ArgumentException (msg, "reason"); - } + if (code == 1005) { + var msg = "1005 cannot be used."; + throw new ArgumentException (msg, "code"); + } - if (bytes.Length > 123) { - var msg = "Its size is greater than 123 bytes."; - throw new ArgumentOutOfRangeException ("reason", msg); - } + 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);