diff --git a/Example/bin/Debug/example.exe b/Example/bin/Debug/example.exe index f58903fc..e3ad430c 100755 Binary files a/Example/bin/Debug/example.exe and b/Example/bin/Debug/example.exe differ diff --git a/Example/bin/Debug/websocket-sharp.dll b/Example/bin/Debug/websocket-sharp.dll index e6348c11..243724f8 100755 Binary files a/Example/bin/Debug/websocket-sharp.dll and b/Example/bin/Debug/websocket-sharp.dll differ diff --git a/Example/bin/Debug_Ubuntu/example.exe b/Example/bin/Debug_Ubuntu/example.exe index c5c47fa6..1eb32d06 100755 Binary files a/Example/bin/Debug_Ubuntu/example.exe and b/Example/bin/Debug_Ubuntu/example.exe differ diff --git a/Example/bin/Debug_Ubuntu/websocket-sharp.dll b/Example/bin/Debug_Ubuntu/websocket-sharp.dll index 64c64cd5..86fd3a42 100755 Binary files a/Example/bin/Debug_Ubuntu/websocket-sharp.dll and b/Example/bin/Debug_Ubuntu/websocket-sharp.dll differ diff --git a/Example/bin/Release/example.exe b/Example/bin/Release/example.exe index 706edd70..b66ef3a4 100755 Binary files a/Example/bin/Release/example.exe and b/Example/bin/Release/example.exe differ diff --git a/Example/bin/Release/websocket-sharp.dll b/Example/bin/Release/websocket-sharp.dll index d0a30ed2..404bacb2 100755 Binary files a/Example/bin/Release/websocket-sharp.dll and b/Example/bin/Release/websocket-sharp.dll differ diff --git a/Example/bin/Release_Ubuntu/example.exe b/Example/bin/Release_Ubuntu/example.exe index 793a568f..c8a0295a 100755 Binary files a/Example/bin/Release_Ubuntu/example.exe and b/Example/bin/Release_Ubuntu/example.exe differ diff --git a/Example/bin/Release_Ubuntu/websocket-sharp.dll b/Example/bin/Release_Ubuntu/websocket-sharp.dll index 52ee834c..ceed25c1 100755 Binary files a/Example/bin/Release_Ubuntu/websocket-sharp.dll and b/Example/bin/Release_Ubuntu/websocket-sharp.dll differ diff --git a/Example1/bin/Debug/example1.exe b/Example1/bin/Debug/example1.exe index 414e11cb..50f7638c 100755 Binary files a/Example1/bin/Debug/example1.exe and b/Example1/bin/Debug/example1.exe differ diff --git a/Example1/bin/Debug/websocket-sharp.dll b/Example1/bin/Debug/websocket-sharp.dll index e6348c11..243724f8 100755 Binary files a/Example1/bin/Debug/websocket-sharp.dll and b/Example1/bin/Debug/websocket-sharp.dll differ diff --git a/Example1/bin/Debug_Ubuntu/example1.exe b/Example1/bin/Debug_Ubuntu/example1.exe index f721a810..aec52a24 100755 Binary files a/Example1/bin/Debug_Ubuntu/example1.exe and b/Example1/bin/Debug_Ubuntu/example1.exe differ diff --git a/Example1/bin/Debug_Ubuntu/websocket-sharp.dll b/Example1/bin/Debug_Ubuntu/websocket-sharp.dll index 64c64cd5..86fd3a42 100755 Binary files a/Example1/bin/Debug_Ubuntu/websocket-sharp.dll and b/Example1/bin/Debug_Ubuntu/websocket-sharp.dll differ diff --git a/Example1/bin/Release/example1.exe b/Example1/bin/Release/example1.exe index 23182988..f08d541d 100755 Binary files a/Example1/bin/Release/example1.exe and b/Example1/bin/Release/example1.exe differ diff --git a/Example1/bin/Release/websocket-sharp.dll b/Example1/bin/Release/websocket-sharp.dll index d0a30ed2..404bacb2 100755 Binary files a/Example1/bin/Release/websocket-sharp.dll and b/Example1/bin/Release/websocket-sharp.dll differ diff --git a/Example1/bin/Release_Ubuntu/example1.exe b/Example1/bin/Release_Ubuntu/example1.exe index 182ead32..feeffa89 100755 Binary files a/Example1/bin/Release_Ubuntu/example1.exe and b/Example1/bin/Release_Ubuntu/example1.exe differ diff --git a/Example1/bin/Release_Ubuntu/websocket-sharp.dll b/Example1/bin/Release_Ubuntu/websocket-sharp.dll index 52ee834c..ceed25c1 100755 Binary files a/Example1/bin/Release_Ubuntu/websocket-sharp.dll and b/Example1/bin/Release_Ubuntu/websocket-sharp.dll differ diff --git a/Example2/bin/Debug/example2.exe b/Example2/bin/Debug/example2.exe index b4fab08c..6c139aff 100755 Binary files a/Example2/bin/Debug/example2.exe and b/Example2/bin/Debug/example2.exe differ diff --git a/Example2/bin/Debug/websocket-sharp.dll b/Example2/bin/Debug/websocket-sharp.dll index e6348c11..243724f8 100755 Binary files a/Example2/bin/Debug/websocket-sharp.dll and b/Example2/bin/Debug/websocket-sharp.dll differ diff --git a/Example2/bin/Debug_Ubuntu/example2.exe b/Example2/bin/Debug_Ubuntu/example2.exe index 510f3ba7..e3513839 100755 Binary files a/Example2/bin/Debug_Ubuntu/example2.exe and b/Example2/bin/Debug_Ubuntu/example2.exe differ diff --git a/Example2/bin/Debug_Ubuntu/websocket-sharp.dll b/Example2/bin/Debug_Ubuntu/websocket-sharp.dll index 64c64cd5..86fd3a42 100755 Binary files a/Example2/bin/Debug_Ubuntu/websocket-sharp.dll and b/Example2/bin/Debug_Ubuntu/websocket-sharp.dll differ diff --git a/Example2/bin/Release/example2.exe b/Example2/bin/Release/example2.exe index d8ba8c0e..6aa07061 100755 Binary files a/Example2/bin/Release/example2.exe and b/Example2/bin/Release/example2.exe differ diff --git a/Example2/bin/Release/websocket-sharp.dll b/Example2/bin/Release/websocket-sharp.dll index d0a30ed2..404bacb2 100755 Binary files a/Example2/bin/Release/websocket-sharp.dll and b/Example2/bin/Release/websocket-sharp.dll differ diff --git a/Example2/bin/Release_Ubuntu/example2.exe b/Example2/bin/Release_Ubuntu/example2.exe index 79a28de8..a97924ed 100755 Binary files a/Example2/bin/Release_Ubuntu/example2.exe and b/Example2/bin/Release_Ubuntu/example2.exe differ diff --git a/Example2/bin/Release_Ubuntu/websocket-sharp.dll b/Example2/bin/Release_Ubuntu/websocket-sharp.dll index 52ee834c..ceed25c1 100755 Binary files a/Example2/bin/Release_Ubuntu/websocket-sharp.dll and b/Example2/bin/Release_Ubuntu/websocket-sharp.dll differ diff --git a/Example3/bin/Debug/Example3.exe b/Example3/bin/Debug/Example3.exe index eeea3382..b41f7d7b 100755 Binary files a/Example3/bin/Debug/Example3.exe and b/Example3/bin/Debug/Example3.exe differ diff --git a/Example3/bin/Debug/websocket-sharp.dll b/Example3/bin/Debug/websocket-sharp.dll index e6348c11..243724f8 100755 Binary files a/Example3/bin/Debug/websocket-sharp.dll and b/Example3/bin/Debug/websocket-sharp.dll differ diff --git a/Example3/bin/Debug_Ubuntu/Example3.exe b/Example3/bin/Debug_Ubuntu/Example3.exe index d10208ca..532b8c2c 100755 Binary files a/Example3/bin/Debug_Ubuntu/Example3.exe and b/Example3/bin/Debug_Ubuntu/Example3.exe differ diff --git a/Example3/bin/Debug_Ubuntu/websocket-sharp.dll b/Example3/bin/Debug_Ubuntu/websocket-sharp.dll index 64c64cd5..86fd3a42 100755 Binary files a/Example3/bin/Debug_Ubuntu/websocket-sharp.dll and b/Example3/bin/Debug_Ubuntu/websocket-sharp.dll differ diff --git a/Example3/bin/Release/Example3.exe b/Example3/bin/Release/Example3.exe index 08efcafc..6cb58465 100755 Binary files a/Example3/bin/Release/Example3.exe and b/Example3/bin/Release/Example3.exe differ diff --git a/Example3/bin/Release/websocket-sharp.dll b/Example3/bin/Release/websocket-sharp.dll index d0a30ed2..404bacb2 100755 Binary files a/Example3/bin/Release/websocket-sharp.dll and b/Example3/bin/Release/websocket-sharp.dll differ diff --git a/Example3/bin/Release_Ubuntu/Example3.exe b/Example3/bin/Release_Ubuntu/Example3.exe index e89f3ba6..d7fb5aea 100755 Binary files a/Example3/bin/Release_Ubuntu/Example3.exe and b/Example3/bin/Release_Ubuntu/Example3.exe differ diff --git a/Example3/bin/Release_Ubuntu/websocket-sharp.dll b/Example3/bin/Release_Ubuntu/websocket-sharp.dll index 52ee834c..ceed25c1 100755 Binary files a/Example3/bin/Release_Ubuntu/websocket-sharp.dll and b/Example3/bin/Release_Ubuntu/websocket-sharp.dll differ diff --git a/websocket-sharp/MessageEventArgs.cs b/websocket-sharp/MessageEventArgs.cs index 25804b93..3dddf973 100644 --- a/websocket-sharp/MessageEventArgs.cs +++ b/websocket-sharp/MessageEventArgs.cs @@ -78,9 +78,8 @@ namespace WebSocketSharp { /// public string Data { get { - _data = _data != null - ? _data - : _rawData.LongLength == 0 + if (_data == null) + _data = _rawData.LongLength == 0 ? String.Empty : _opcode == Opcode.TEXT ? Encoding.UTF8.GetString(_rawData) diff --git a/websocket-sharp/WsFrame.cs b/websocket-sharp/WsFrame.cs index 5e0d231f..6785070c 100644 --- a/websocket-sharp/WsFrame.cs +++ b/websocket-sharp/WsFrame.cs @@ -113,13 +113,13 @@ namespace WebSocketSharp { internal bool IsBinary { get { - return isBinary(Opcode); + return Opcode == Opcode.BINARY; } } internal bool IsClose { get { - return isClose(Opcode); + return Opcode == Opcode.CLOSE; } } @@ -131,55 +131,64 @@ namespace WebSocketSharp { internal bool IsContinuation { get { - return isContinuation(Opcode); + return Opcode == Opcode.CONT; } } internal bool IsControl { get { - return isControl(Opcode); + var opcode = Opcode; + return opcode == Opcode.CLOSE || opcode == Opcode.PING || opcode == Opcode.PONG; } } internal bool IsData { get { - return isData(Opcode); + var opcode = Opcode; + return opcode == Opcode.BINARY || opcode == Opcode.TEXT; } } internal bool IsFinal { get { - return isFinal(Fin); + return Fin == Fin.FINAL; } } internal bool IsFragmented { get { - return !IsFinal || IsContinuation; + return Fin == Fin.MORE || Opcode == Opcode.CONT; } } internal bool IsMasked { get { - return isMasked(Mask); + return Mask == Mask.MASK; + } + } + + internal bool IsPerMessageCompressed { + get { + var opcode = Opcode; + return (opcode == Opcode.BINARY || opcode == Opcode.TEXT) && Rsv1 == Rsv.ON; } } internal bool IsPing { get { - return isPing(Opcode); + return Opcode == Opcode.PING; } } internal bool IsPong { get { - return isPong(Opcode); + return Opcode == Opcode.PONG; } } internal bool IsText { get { - return isText(Opcode); + return Opcode == Opcode.TEXT; } } @@ -189,19 +198,6 @@ namespace WebSocketSharp { } } - internal bool PerMessageCompressed { - get { - return IsData && IsCompressed; - } - - set { - if (value && !IsData) - return; - - Rsv1 = value ? Rsv.ON : Rsv.OFF; - } - } - #endregion #region Public Properties @@ -230,24 +226,20 @@ namespace WebSocketSharp { #region Private Methods - private static WsFrame createCloseFrame(WebSocketException exception) + private static WsFrame createCloseFrame(CloseStatusCode code, string message) { using (var buffer = new MemoryStream()) { - var code = (ushort)exception.Code; - var msg = exception.Message; - buffer.Write(code.ToByteArray(ByteOrder.BIG), 0, 2); - if (msg.Length != 0) + var tmp = ((ushort)code).ToByteArray(ByteOrder.BIG); + buffer.Write(tmp, 0, 2); + if (message.Length != 0) { - var tmp = Encoding.UTF8.GetBytes(msg); + tmp = Encoding.UTF8.GetBytes(message); buffer.Write(tmp, 0, tmp.Length); } buffer.Close(); - var payload = new PayloadData(buffer.ToArray()); - var frame = new WsFrame(Fin.FINAL, Opcode.CLOSE, Mask.UNMASK, payload); - - return frame; + return new WsFrame(Fin.FINAL, Opcode.CLOSE, Mask.UNMASK, new PayloadData(buffer.ToArray())); } } @@ -382,9 +374,6 @@ namespace WebSocketSharp { private static WsFrame parse(byte[] header, Stream stream, bool unmask) { - if (header == null || header.Length != 2) - return null; - /* Header */ // FIN @@ -403,7 +392,7 @@ namespace WebSocketSharp { var payloadLen = (byte)(header[1] & 0x7f); if (isControl(opcode) && payloadLen > 125) - throw new WebSocketException(CloseStatusCode.INCONSISTENT_DATA, + return createCloseFrame(CloseStatusCode.INCONSISTENT_DATA, "The payload length of a control frame must be 125 bytes or less."); var frame = new WsFrame { @@ -429,7 +418,8 @@ namespace WebSocketSharp { : new byte[]{}; if (extLen > 0 && extPayloadLen.Length != extLen) - throw new IOException(); + return createCloseFrame(CloseStatusCode.ABNORMAL, + "'Extended Payload Length' of a frame cannot be read from the data stream."); frame.ExtPayloadLen = extPayloadLen; @@ -441,7 +431,8 @@ namespace WebSocketSharp { : new byte[]{}; if (masked && maskingKey.Length != 4) - throw new IOException(); + return createCloseFrame(CloseStatusCode.ABNORMAL, + "'Masking Key' of a frame cannot be read from the data stream."); frame.MaskingKey = maskingKey; @@ -457,14 +448,18 @@ namespace WebSocketSharp { if (dataLen > 0) { if (payloadLen > 126 && dataLen > PayloadData.MaxLength) - throw new WebSocketException(CloseStatusCode.TOO_BIG); + { + var code = CloseStatusCode.TOO_BIG; + return createCloseFrame(code, code.GetMessage()); + } data = dataLen > 1024 ? stream.ReadBytesInternal((long)dataLen, 1024) : stream.ReadBytesInternal((int)dataLen); if (data.LongLength != (long)dataLen) - throw new IOException(); + return createCloseFrame(CloseStatusCode.ABNORMAL, + "'Payload Data' of a frame cannot be read from the data stream."); } else { @@ -559,11 +554,10 @@ namespace WebSocketSharp { try { var header = stream.ReadBytesInternal(2); - frame = parse(header, stream, unmask); - } - catch (WebSocketException ex) - { - frame = createCloseFrame(ex); + frame = header.Length == 2 + ? parse(header, stream, unmask) + : createCloseFrame(CloseStatusCode.ABNORMAL, + "'Header' of a frame cannot be read from the data stream."); } catch (Exception ex) { @@ -594,17 +588,20 @@ namespace WebSocketSharp { try { var readLen = stream.EndRead(ar); - if (readLen > 0) + if (readLen == 1) { - if (readLen == 1) - header[1] = (byte)stream.ReadByte(); - - frame = parse(header, stream, unmask); + var tmp = stream.ReadByte(); + if (tmp > -1) + { + header[1] = (byte)tmp; + readLen++; + } } - } - catch (WebSocketException ex) - { - frame = createCloseFrame(ex); + + frame = readLen == 2 + ? parse(header, stream, unmask) + : createCloseFrame(CloseStatusCode.ABNORMAL, + "'Header' of a frame cannot be read from the data stream."); } catch (Exception ex) { diff --git a/websocket-sharp/bin/Debug/websocket-sharp.dll b/websocket-sharp/bin/Debug/websocket-sharp.dll index e6348c11..243724f8 100755 Binary files a/websocket-sharp/bin/Debug/websocket-sharp.dll and b/websocket-sharp/bin/Debug/websocket-sharp.dll differ diff --git a/websocket-sharp/bin/Debug_Ubuntu/websocket-sharp.dll b/websocket-sharp/bin/Debug_Ubuntu/websocket-sharp.dll index 64c64cd5..86fd3a42 100755 Binary files a/websocket-sharp/bin/Debug_Ubuntu/websocket-sharp.dll and b/websocket-sharp/bin/Debug_Ubuntu/websocket-sharp.dll differ diff --git a/websocket-sharp/bin/Release/websocket-sharp.dll b/websocket-sharp/bin/Release/websocket-sharp.dll index d0a30ed2..404bacb2 100755 Binary files a/websocket-sharp/bin/Release/websocket-sharp.dll and b/websocket-sharp/bin/Release/websocket-sharp.dll differ diff --git a/websocket-sharp/bin/Release_Ubuntu/websocket-sharp.dll b/websocket-sharp/bin/Release_Ubuntu/websocket-sharp.dll index 52ee834c..ceed25c1 100755 Binary files a/websocket-sharp/bin/Release_Ubuntu/websocket-sharp.dll and b/websocket-sharp/bin/Release_Ubuntu/websocket-sharp.dll differ diff --git a/websocket-sharp/doc/mdoc/index.xml b/websocket-sharp/doc/mdoc/index.xml index 8de50d22..e7d89c82 100644 --- a/websocket-sharp/doc/mdoc/index.xml +++ b/websocket-sharp/doc/mdoc/index.xml @@ -1,6 +1,6 @@ - + [00 24 00 00 04 80 00 00 94 00 00 00 06 02 00 00 00 24 00 00 52 53 41 31 00 04 00 00 11 00 00 00 29 17 fb 89 fe c3 91 f7 2b cb 8b e2 61 d2 3f 05 93 6d 65 a8 9e 63 72 a6 f5 d5 2c f2 9d 20 fa 0b c0 70 6a f6 88 7e 8b 90 3f 39 f5 76 c8 48 e0 bb 7b b2 7b ed d3 10 a7 1a 0f 70 98 0f 7f f4 4b 53 09 d2 a5 ef 36 c3 56 b4 aa f0 91 72 63 25 07 89 e0 93 3e 3f 2e f2 b9 73 0e 12 15 5d 43 56 c3 f4 70 a5 89 fe f7 f6 ac 3e 77 c2 d8 d0 84 91 f4 0c d1 f3 8e dc c3 c3 b8 38 3d 0c bf 17 de 20 78 c1 ]