From 64fd327e283bfc9ddd2ea8505c9f234d9c2ecd20 Mon Sep 17 00:00:00 2001 From: sta Date: Sun, 17 May 2015 17:49:21 +0900 Subject: [PATCH] Refactored a few for WebSocketFrame.cs --- websocket-sharp/WebSocketFrame.cs | 19 +++++++------------ 1 file changed, 7 insertions(+), 12 deletions(-) diff --git a/websocket-sharp/WebSocketFrame.cs b/websocket-sharp/WebSocketFrame.cs index 3fd6947b..afb9ac39 100644 --- a/websocket-sharp/WebSocketFrame.cs +++ b/websocket-sharp/WebSocketFrame.cs @@ -440,7 +440,7 @@ Extended Payload Length: {7} // Check if valid header. var err = isControl (opcode) && payloadLen > 125 - ? "A control frame has payload data which is greater than the allowable max size." + ? "A control frame has payload data which is greater than the allowable max length." : isControl (opcode) && fin == Fin.More ? "A control frame is fragmented." : !isData (opcode) && rsv1 == Rsv.On @@ -461,12 +461,7 @@ Extended Payload Length: {7} /* Extended Payload Length */ - var size = payloadLen < 126 - ? 0 - : payloadLen == 126 - ? 2 - : 8; - + var size = payloadLen < 126 ? 0 : (payloadLen == 126 ? 2 : 8); var extPayloadLen = size > 0 ? stream.ReadBytes (size) : new byte[0]; if (size > 0 && extPayloadLen.Length != size) throw new WebSocketException ( @@ -619,17 +614,17 @@ Extended Payload Length: {7} buff.Write (((ushort) header).InternalToByteArray (ByteOrder.Big), 0, 2); if (_payloadLength > 125) - buff.Write (_extPayloadLength, 0, _extPayloadLength.Length); + buff.Write (_extPayloadLength, 0, _payloadLength == 126 ? 2 : 8); if (_mask == Mask.Mask) - buff.Write (_maskingKey, 0, _maskingKey.Length); + buff.Write (_maskingKey, 0, 4); if (_payloadLength > 0) { - var payload = _payloadData.ToByteArray (); + var bytes = _payloadData.ToByteArray (); if (_payloadLength < 127) - buff.Write (payload, 0, payload.Length); + buff.Write (bytes, 0, bytes.Length); else - buff.WriteBytes (payload); + buff.WriteBytes (bytes); } buff.Close ();