From d2bb26730632635ba5d4a9c2c2ebddc172f4d7e5 Mon Sep 17 00:00:00 2001 From: sta Date: Fri, 25 Sep 2015 15:00:58 +0900 Subject: [PATCH] [Modify] Polish it --- websocket-sharp/WebSocketFrame.cs | 37 +++++++++---------------------- 1 file changed, 11 insertions(+), 26 deletions(-) diff --git a/websocket-sharp/WebSocketFrame.cs b/websocket-sharp/WebSocketFrame.cs index adc38bc0..dafad8f4 100644 --- a/websocket-sharp/WebSocketFrame.cs +++ b/websocket-sharp/WebSocketFrame.cs @@ -631,36 +631,21 @@ Extended Payload Length: {7} CloseStatusCode.TooBig, "The length of 'Payload Data' of a frame is greater than the allowable max length."); + Action compl = bytes => { + if (bytes.LongLength != (long) len) + throw new WebSocketException ( + "The 'Payload Data' of a frame cannot be read from the data source."); + + frame._payloadData = new PayloadData (bytes, frame.IsMasked); + completed (frame); + }; + if (frame._payloadLength < 127) { - var ilen = (int) len; - stream.ReadBytesAsync ( - ilen, - bytes => { - if (bytes.Length != ilen) - throw new WebSocketException ( - "The 'Payload Data' of a frame cannot be read from the data source."); - - frame._payloadData = new PayloadData (bytes, frame.IsMasked); - completed (frame); - }, - error); - + stream.ReadBytesAsync ((int) len, compl, error); return; } - var llen = (long) len; - stream.ReadBytesAsync ( - llen, - 1024, - bytes => { - if (bytes.LongLength != llen) - throw new WebSocketException ( - "The 'Payload Data' of a frame cannot be read from the data source."); - - frame._payloadData = new PayloadData (bytes, frame.IsMasked); - completed (frame); - }, - error); + stream.ReadBytesAsync ((long) len, 1024, compl, error); } #endregion