From 3944137417587c4999e3a644836ac65b8c052867 Mon Sep 17 00:00:00 2001 From: sta Date: Fri, 30 Aug 2019 19:35:24 +0900 Subject: [PATCH] [Modify] Polish it --- websocket-sharp/WebSocketFrame.cs | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/websocket-sharp/WebSocketFrame.cs b/websocket-sharp/WebSocketFrame.cs index 15d9be07..9f3ec595 100644 --- a/websocket-sharp/WebSocketFrame.cs +++ b/websocket-sharp/WebSocketFrame.cs @@ -657,37 +657,37 @@ Extended Payload Length: {7} Action error ) { - var len = frame.ExactPayloadLength; - if (len == 0) { + var exactLen = frame.ExactPayloadLength; + if (exactLen > PayloadData.MaxLength) { + var msg = "A frame has too long payload length."; + throw new WebSocketException (CloseStatusCode.TooBig, msg); + } + + if (exactLen == 0) { frame._payloadData = PayloadData.Empty; completed (frame); return; } - if (len > PayloadData.MaxLength) { - var msg = "A frame has too long payload length."; - throw new WebSocketException (CloseStatusCode.TooBig, msg); - } - - var llen = (long) len; - Action compl = + var len = (long) exactLen; + Action comp = bytes => { - if (bytes.LongLength != llen) { + if (bytes.LongLength != len) { var msg = "The payload data of a frame could not be read."; throw new WebSocketException (msg); } - frame._payloadData = new PayloadData (bytes, llen); + frame._payloadData = new PayloadData (bytes, len); completed (frame); }; if (frame._payloadLength < 127) { - stream.ReadBytesAsync ((int) len, compl, error); + stream.ReadBytesAsync ((int) exactLen, comp, error); return; } - stream.ReadBytesAsync (llen, 1024, compl, error); + stream.ReadBytesAsync (len, 1024, comp, error); } private static string utf8Decode (byte[] bytes)