diff --git a/Example/Example.pidb b/Example/Example.pidb index ff4acb4f..15ecbd30 100644 Binary files a/Example/Example.pidb and b/Example/Example.pidb differ diff --git a/Example/bin/Debug/example.exe b/Example/bin/Debug/example.exe index c85aa3a9..9a42d5a4 100755 Binary files a/Example/bin/Debug/example.exe and b/Example/bin/Debug/example.exe differ diff --git a/Example/bin/Debug/example.exe.mdb b/Example/bin/Debug/example.exe.mdb index cd615381..9d1afa5b 100644 Binary files a/Example/bin/Debug/example.exe.mdb and b/Example/bin/Debug/example.exe.mdb differ diff --git a/Example/bin/Debug/websocket-sharp.dll b/Example/bin/Debug/websocket-sharp.dll index fe3951ba..57dd7bdf 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/websocket-sharp.dll.mdb b/Example/bin/Debug/websocket-sharp.dll.mdb index 61e329d0..e5e66409 100644 Binary files a/Example/bin/Debug/websocket-sharp.dll.mdb and b/Example/bin/Debug/websocket-sharp.dll.mdb differ diff --git a/Example/bin/Debug_Ubuntu/example.exe b/Example/bin/Debug_Ubuntu/example.exe index e55b1bf3..8b4a109d 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/example.exe.mdb b/Example/bin/Debug_Ubuntu/example.exe.mdb index 1e02a4aa..def6ddd4 100644 Binary files a/Example/bin/Debug_Ubuntu/example.exe.mdb and b/Example/bin/Debug_Ubuntu/example.exe.mdb differ diff --git a/Example/bin/Debug_Ubuntu/websocket-sharp.dll b/Example/bin/Debug_Ubuntu/websocket-sharp.dll index a868c718..c80dd6d9 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/Debug_Ubuntu/websocket-sharp.dll.mdb b/Example/bin/Debug_Ubuntu/websocket-sharp.dll.mdb index 97c87fac..e3582a6b 100644 Binary files a/Example/bin/Debug_Ubuntu/websocket-sharp.dll.mdb and b/Example/bin/Debug_Ubuntu/websocket-sharp.dll.mdb differ diff --git a/Example/bin/Release/example.exe b/Example/bin/Release/example.exe index 067fd9ae..9df7db74 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 5cb2e8a3..9f4c0c65 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 9e5f6f41..3c3b3be5 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 89c7e9fd..4b57a6a1 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 060d7b5c..b275d7bd 100755 Binary files a/Example1/bin/Debug/example1.exe and b/Example1/bin/Debug/example1.exe differ diff --git a/Example1/bin/Debug/example1.exe.mdb b/Example1/bin/Debug/example1.exe.mdb index 34a0521b..2b1a7c51 100644 Binary files a/Example1/bin/Debug/example1.exe.mdb and b/Example1/bin/Debug/example1.exe.mdb differ diff --git a/Example1/bin/Debug/websocket-sharp.dll b/Example1/bin/Debug/websocket-sharp.dll index fe3951ba..57dd7bdf 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/websocket-sharp.dll.mdb b/Example1/bin/Debug/websocket-sharp.dll.mdb index 61e329d0..e5e66409 100644 Binary files a/Example1/bin/Debug/websocket-sharp.dll.mdb and b/Example1/bin/Debug/websocket-sharp.dll.mdb differ diff --git a/Example1/bin/Debug_Ubuntu/example1.exe b/Example1/bin/Debug_Ubuntu/example1.exe index 18c0b310..5fac093c 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/example1.exe.mdb b/Example1/bin/Debug_Ubuntu/example1.exe.mdb index c90326b1..d33a32a5 100644 Binary files a/Example1/bin/Debug_Ubuntu/example1.exe.mdb and b/Example1/bin/Debug_Ubuntu/example1.exe.mdb differ diff --git a/Example1/bin/Debug_Ubuntu/websocket-sharp.dll b/Example1/bin/Debug_Ubuntu/websocket-sharp.dll index a868c718..c80dd6d9 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/Debug_Ubuntu/websocket-sharp.dll.mdb b/Example1/bin/Debug_Ubuntu/websocket-sharp.dll.mdb index 97c87fac..e3582a6b 100644 Binary files a/Example1/bin/Debug_Ubuntu/websocket-sharp.dll.mdb and b/Example1/bin/Debug_Ubuntu/websocket-sharp.dll.mdb differ diff --git a/Example1/bin/Release/example1.exe b/Example1/bin/Release/example1.exe index cae08766..39325deb 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 5cb2e8a3..9f4c0c65 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 d7bb31aa..83f4b371 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 89c7e9fd..4b57a6a1 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 fb1d5123..843cae2c 100755 Binary files a/Example2/bin/Debug/example2.exe and b/Example2/bin/Debug/example2.exe differ diff --git a/Example2/bin/Debug/example2.exe.mdb b/Example2/bin/Debug/example2.exe.mdb index 3c33a8b5..b250fe86 100644 Binary files a/Example2/bin/Debug/example2.exe.mdb and b/Example2/bin/Debug/example2.exe.mdb differ diff --git a/Example2/bin/Debug/websocket-sharp.dll b/Example2/bin/Debug/websocket-sharp.dll index fe3951ba..57dd7bdf 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/websocket-sharp.dll.mdb b/Example2/bin/Debug/websocket-sharp.dll.mdb index 61e329d0..e5e66409 100644 Binary files a/Example2/bin/Debug/websocket-sharp.dll.mdb and b/Example2/bin/Debug/websocket-sharp.dll.mdb differ diff --git a/Example2/bin/Debug_Ubuntu/example2.exe b/Example2/bin/Debug_Ubuntu/example2.exe index 9b55ae32..9c4f3a2d 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/example2.exe.mdb b/Example2/bin/Debug_Ubuntu/example2.exe.mdb index 5ca39f3a..a24697d7 100644 Binary files a/Example2/bin/Debug_Ubuntu/example2.exe.mdb and b/Example2/bin/Debug_Ubuntu/example2.exe.mdb differ diff --git a/Example2/bin/Debug_Ubuntu/websocket-sharp.dll b/Example2/bin/Debug_Ubuntu/websocket-sharp.dll index a868c718..c80dd6d9 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/Debug_Ubuntu/websocket-sharp.dll.mdb b/Example2/bin/Debug_Ubuntu/websocket-sharp.dll.mdb index 97c87fac..e3582a6b 100644 Binary files a/Example2/bin/Debug_Ubuntu/websocket-sharp.dll.mdb and b/Example2/bin/Debug_Ubuntu/websocket-sharp.dll.mdb differ diff --git a/Example2/bin/Release/example2.exe b/Example2/bin/Release/example2.exe index 7666fda0..36d4c56a 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 5cb2e8a3..9f4c0c65 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 be5029fa..edc8442f 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 89c7e9fd..4b57a6a1 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 01c0678d..dfba6b4d 100755 Binary files a/Example3/bin/Debug/Example3.exe and b/Example3/bin/Debug/Example3.exe differ diff --git a/Example3/bin/Debug/Example3.exe.mdb b/Example3/bin/Debug/Example3.exe.mdb index 6e7f3d2e..dbafc597 100644 Binary files a/Example3/bin/Debug/Example3.exe.mdb and b/Example3/bin/Debug/Example3.exe.mdb differ diff --git a/Example3/bin/Debug/websocket-sharp.dll b/Example3/bin/Debug/websocket-sharp.dll index fe3951ba..57dd7bdf 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/websocket-sharp.dll.mdb b/Example3/bin/Debug/websocket-sharp.dll.mdb index 61e329d0..e5e66409 100644 Binary files a/Example3/bin/Debug/websocket-sharp.dll.mdb and b/Example3/bin/Debug/websocket-sharp.dll.mdb differ diff --git a/Example3/bin/Debug_Ubuntu/Example3.exe b/Example3/bin/Debug_Ubuntu/Example3.exe index bdeb3237..725c8624 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/Example3.exe.mdb b/Example3/bin/Debug_Ubuntu/Example3.exe.mdb index 6f89d880..d71f3915 100644 Binary files a/Example3/bin/Debug_Ubuntu/Example3.exe.mdb and b/Example3/bin/Debug_Ubuntu/Example3.exe.mdb differ diff --git a/Example3/bin/Debug_Ubuntu/websocket-sharp.dll b/Example3/bin/Debug_Ubuntu/websocket-sharp.dll index a868c718..c80dd6d9 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/Debug_Ubuntu/websocket-sharp.dll.mdb b/Example3/bin/Debug_Ubuntu/websocket-sharp.dll.mdb index 97c87fac..e3582a6b 100644 Binary files a/Example3/bin/Debug_Ubuntu/websocket-sharp.dll.mdb and b/Example3/bin/Debug_Ubuntu/websocket-sharp.dll.mdb differ diff --git a/Example3/bin/Release/Example3.exe b/Example3/bin/Release/Example3.exe index 0236f4b5..0764424d 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 5cb2e8a3..9f4c0c65 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 36350e47..5a08c817 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 89c7e9fd..4b57a6a1 100755 Binary files a/Example3/bin/Release_Ubuntu/websocket-sharp.dll and b/Example3/bin/Release_Ubuntu/websocket-sharp.dll differ diff --git a/README.md b/README.md index c2732295..eb123bab 100644 --- a/README.md +++ b/README.md @@ -346,19 +346,40 @@ Examples of using **websocket-sharp**. Please access [http://localhost:4649](http://localhost:4649) to do WebSocket Echo Test with your web browser after [Example3] running. -## Supported WebSocket Protocol ## +## Supported WebSocket Protocols ## **websocket-sharp** supports **[RFC 6455]**. - **[branch: hybi-00]** supports older draft-ietf-hybi-thewebsocketprotocol-00 ( **[hybi-00]** ). - **[branch: draft75]** supports even more old draft-hixie-thewebsocketprotocol-75 ( **[hixie-75]** ). -## Reference ## +## Supported WebSocket Extensions ## + +### Per-message Compression ### + +**websocket-sharp** supports **[Per-message Compression]**. + +If you want to enable this extension as a WebSocket client, you should do like the following. + +```cs +ws.Compression = CompressionMethod.DEFLATE; +``` + +And then your client sends the following header in the opening handshake to a WebSocket server. + +``` +Sec-WebSocket-Extensions: permessage-compress; method=deflate +``` + +If the server supports this extension, responds the same header. And when your client receives the header, enables this extension. + +## References ## - **[The WebSocket Protocol]** - **[The WebSocket API]** +- **[Per-message Compression]** -Thx for translating to japanese. +Thanks for translating to japanese. - **[The WebSocket Protocol 日本語訳]** - **[The WebSocket API 日本語訳]** @@ -383,6 +404,7 @@ Licensed under the **[MIT License]**. [Json.NET]: http://james.newtonking.com/projects/json-net.aspx [MIT License]: http://www.opensource.org/licenses/mit-license.php [Mono]: http://www.mono-project.com/ +[Per-message Compression]: http://tools.ietf.org/html/draft-tyoshino-hybi-permessage-compression-00 [RFC 6455]: http://tools.ietf.org/html/rfc6455 [The WebSocket API]: http://www.w3.org/TR/websockets/ [The WebSocket API 日本語訳]: http://www.hcn.zaq.ne.jp/___/WEB/WebSocket-ja.html diff --git a/websocket-sharp/CloseEventArgs.cs b/websocket-sharp/CloseEventArgs.cs index e5fc3614..c0914772 100644 --- a/websocket-sharp/CloseEventArgs.cs +++ b/websocket-sharp/CloseEventArgs.cs @@ -54,9 +54,9 @@ namespace WebSocketSharp { internal CloseEventArgs(PayloadData data) : base(Opcode.CLOSE, data) { - _code = getCodeFrom(data); + _code = getCodeFrom(data); _reason = getReasonFrom(data); - _clean = false; + _clean = false; } #endregion @@ -107,19 +107,22 @@ namespace WebSocketSharp { #region Private Methods - private ushort getCodeFrom(PayloadData data) + private static ushort getCodeFrom(PayloadData data) { - return data.Length >= 2 - ? data.ToByteArray().SubArray(0, 2).To(ByteOrder.BIG) + var appData = data.ApplicationData; + return appData.Length >= 2 + ? appData.SubArray(0, 2).To(ByteOrder.BIG) : (ushort)CloseStatusCode.NO_STATUS_CODE; } - private string getReasonFrom(PayloadData data) + private static string getReasonFrom(PayloadData data) { - if (data.Length <= 2) + var appData = data.ApplicationData; + var appDataLen = appData.Length; + if (appDataLen <= 2) return String.Empty; - var buffer = data.ToByteArray().SubArray(2, (int)(data.Length - 2)); + var buffer = appData.SubArray(2, appDataLen - 2); return Encoding.UTF8.GetString(buffer); } diff --git a/websocket-sharp/MessageEventArgs.cs b/websocket-sharp/MessageEventArgs.cs index 89843f01..9f928571 100644 --- a/websocket-sharp/MessageEventArgs.cs +++ b/websocket-sharp/MessageEventArgs.cs @@ -50,6 +50,11 @@ namespace WebSocketSharp { #region Constructors + internal MessageEventArgs(Opcode type, byte[] data) + : this(type, new PayloadData(data)) + { + } + internal MessageEventArgs(Opcode type, PayloadData data) { _type = type; diff --git a/websocket-sharp/PayloadData.cs b/websocket-sharp/PayloadData.cs index 34053b3f..69bca92f 100644 --- a/websocket-sharp/PayloadData.cs +++ b/websocket-sharp/PayloadData.cs @@ -30,7 +30,6 @@ using System; using System.Collections; using System.Collections.Generic; using System.IO; -using System.IO.Compression; using System.Linq; using System.Text; @@ -138,43 +137,6 @@ namespace WebSocketSharp { #region Internal Methods - internal bool Compress(CompressionMethod method) - { - try - { - if (method == CompressionMethod.NONE) - return false; - - if (ExtensionData.LongLength > 0) - return false; - - ApplicationData = ApplicationData.Compress(method); - return true; - } - catch - { - return false; - } - } - - internal bool Decompress(CompressionMethod method) - { - try - { - if (method == CompressionMethod.NONE) - return false; - - if (ApplicationData.LongLength > 0) - ApplicationData = ApplicationData.Decompress(method); - - return true; - } - catch - { - return false; - } - } - #endregion #region Public Methods diff --git a/websocket-sharp/WebSocket.cs b/websocket-sharp/WebSocket.cs index d91cb1de..69dc2340 100644 --- a/websocket-sharp/WebSocket.cs +++ b/websocket-sharp/WebSocket.cs @@ -76,7 +76,6 @@ namespace WebSocketSharp { private Object _forClose; private Object _forSend; private string _origin; - private bool _perFrameCompress; private string _protocol; private string _protocols; private volatile WsState _readyState; @@ -98,7 +97,6 @@ namespace WebSocketSharp { _forClose = new Object(); _forSend = new Object(); _origin = String.Empty; - _perFrameCompress = false; _protocol = String.Empty; _readyState = WsState.CONNECTING; } @@ -576,18 +574,14 @@ namespace WebSocketSharp { private static WsFrame createControlFrame(Opcode opcode, PayloadData payloadData, bool client) { - var mask = client ? Mask.MASK : Mask.UNMASK; - return new WsFrame(opcode, mask, payloadData); + return createFrame(Fin.FINAL, opcode, payloadData, false, client); } - private static WsFrame createDataFrame( - Fin fin, Opcode opcode, PayloadData payloadData, CompressionMethod method, bool compressed, bool client) + private static WsFrame createFrame( + Fin fin, Opcode opcode, PayloadData payloadData, bool compressed, bool client) { var mask = client ? Mask.MASK : Mask.UNMASK; - var compress = compressed ? CompressionMethod.NONE : method; - var frame = new WsFrame(fin, opcode, mask, payloadData, compress); - if (compressed) - frame.PerMessageCompressed = true; + var frame = new WsFrame(fin, opcode, mask, payloadData, compressed); return frame; } @@ -716,18 +710,6 @@ namespace WebSocketSharp { return true; } - // As server - private static bool isPerFrameCompressExtension(string value) - { - if (value.Equals("deflate-frame")) - return true; - - if (value.Equals("perframe-compress; method=deflate")) - return true; - - return false; - } - // As server private bool isValidHostHeader() { @@ -776,10 +758,7 @@ namespace WebSocketSharp { if (!contFrame.IsContinuation) return false; - if (contFrame.IsCompressed) - contFrame.Decompress(_compression); - - dest.WriteBytes(contFrame.PayloadData.ToByteArray()); + dest.WriteBytes(contFrame.PayloadData.ApplicationData); return true; }; @@ -921,10 +900,11 @@ namespace WebSocketSharp { if (frame.IsCompressed && _compression == CompressionMethod.NONE) return false; - if (frame.IsCompressed) - frame.Decompress(_compression); + var data = frame.IsCompressed + ? new PayloadData(frame.PayloadData.ApplicationData.Decompress(_compression)) + : frame.PayloadData; - onMessage(new MessageEventArgs(frame.Opcode, frame.PayloadData)); + onMessage(new MessageEventArgs(frame.Opcode, data)); return true; } @@ -938,8 +918,10 @@ namespace WebSocketSharp { if (frame.IsFinal) return false; - // First fragment - if (frame.IsData && !(frame.IsCompressed && _compression == CompressionMethod.NONE)) + bool incorrect = !frame.IsData || + frame.IsCompressed && _compression == CompressionMethod.NONE; + + if (!incorrect) processFragments(frame); else processIncorrectFrame(); @@ -951,15 +933,12 @@ namespace WebSocketSharp { { using (var merge = new MemoryStream()) { - if (first.IsCompressed && _perFrameCompress) - first.Decompress(_compression); - - merge.WriteBytes(first.PayloadData.ToByteArray()); + merge.WriteBytes(first.PayloadData.ApplicationData); if (!mergeFragments(merge)) return; byte[] data; - if (_compression != CompressionMethod.NONE && !_perFrameCompress) + if (_compression != CompressionMethod.NONE) { data = merge.DecompressToArray(_compression); } @@ -969,7 +948,7 @@ namespace WebSocketSharp { data = merge.ToArray(); } - onMessage(new MessageEventArgs(first.Opcode, new PayloadData(data))); + onMessage(new MessageEventArgs(first.Opcode, data)); } } @@ -1032,26 +1011,11 @@ namespace WebSocketSharp { { var e = extension.Trim(); var tmp = e.RemovePrefix("x-webkit-"); - if (!compress) + if (!compress && isCompressExtension(tmp, CompressionMethod.DEFLATE)) { - if (isPerFrameCompressExtension(tmp)) - { - _perFrameCompress = true; - _compression = CompressionMethod.DEFLATE; - compress = true; - } - - if (!compress && isCompressExtension(tmp, CompressionMethod.DEFLATE)) - { - _compression = CompressionMethod.DEFLATE; - compress = true; - } - - if (compress) - { - buffer.Add(e); - continue; - } + _compression = CompressionMethod.DEFLATE; + compress = true; + buffer.Add(e); } } @@ -1216,7 +1180,7 @@ namespace WebSocketSharp { private void send(Opcode opcode, Stream stream) { - if (_compression == CompressionMethod.NONE || _perFrameCompress) + if (_compression == CompressionMethod.NONE) { send(opcode, stream, false); return; @@ -1255,8 +1219,7 @@ namespace WebSocketSharp { private bool send(Fin fin, Opcode opcode, byte[] data, bool compressed) { - var frame = createDataFrame( - fin, opcode, new PayloadData(data), _compression, compressed, _client); + var frame = createFrame(fin, opcode, new PayloadData(data), compressed, _client); return send(frame); } diff --git a/websocket-sharp/WsFrame.cs b/websocket-sharp/WsFrame.cs index bd362660..c5c3f625 100644 --- a/websocket-sharp/WsFrame.cs +++ b/websocket-sharp/WsFrame.cs @@ -63,12 +63,12 @@ namespace WebSocketSharp { } public WsFrame(Fin fin, Opcode opcode, Mask mask, PayloadData payloadData) - : this(fin, opcode, mask, payloadData, CompressionMethod.NONE) + : this(fin, opcode, mask, payloadData, false) { } public WsFrame( - Fin fin, Opcode opcode, Mask mask, PayloadData payloadData, CompressionMethod compress) + Fin fin, Opcode opcode, Mask mask, PayloadData payloadData, bool compressed) { if (payloadData.IsNull()) throw new ArgumentNullException("payloadData"); @@ -80,18 +80,14 @@ namespace WebSocketSharp { if (!isFinal(fin) && isControl(opcode)) throw new ArgumentException("The control frame must not be fragmented."); - if (isControl(opcode) && compress != CompressionMethod.NONE) + if (isControl(opcode) && compressed) throw new ArgumentException("The control frame must not be compressed."); Fin = fin; - Rsv1 = Rsv.OFF; - Rsv2 = Rsv.OFF; - Rsv3 = Rsv.OFF; + Rsv1 = isData(opcode) && compressed ? Rsv.ON : Rsv.OFF; Opcode = opcode; Mask = mask; PayloadData = payloadData; - if (compress != CompressionMethod.NONE) - compressPayloadData(compress); init(); } @@ -219,26 +215,6 @@ namespace WebSocketSharp { #region Private Methods - private bool compressPayloadData(CompressionMethod method) - { - if (!PayloadData.Compress(method)) - return false; - - if (IsData) - Rsv1 = Rsv.ON; - - return true; - } - - private bool decompressPayloadData(CompressionMethod method) - { - if (!PayloadData.Decompress(method)) - return false; - - Rsv1 = Rsv.OFF; - return true; - } - private static void dump(WsFrame frame) { var len = frame.Length; @@ -311,6 +287,8 @@ namespace WebSocketSharp { private void init() { + Rsv2 = Rsv.OFF; + Rsv3 = Rsv.OFF; setPayloadLen(PayloadData.Length); if (IsMasked) maskPayloadData(); @@ -560,19 +538,6 @@ namespace WebSocketSharp { #endregion - #region Internal Methods - - internal void Decompress(CompressionMethod method) - { - if (Mask == Mask.MASK) - unmaskPayloadData(); - - if (decompressPayloadData(method)) - setPayloadLen(PayloadData.Length); - } - - #endregion - #region Public Methods public IEnumerator GetEnumerator() diff --git a/websocket-sharp/bin/Debug/websocket-sharp.dll b/websocket-sharp/bin/Debug/websocket-sharp.dll index fe3951ba..57dd7bdf 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/websocket-sharp.dll.mdb b/websocket-sharp/bin/Debug/websocket-sharp.dll.mdb index 61e329d0..e5e66409 100644 Binary files a/websocket-sharp/bin/Debug/websocket-sharp.dll.mdb and b/websocket-sharp/bin/Debug/websocket-sharp.dll.mdb differ diff --git a/websocket-sharp/bin/Debug_Ubuntu/websocket-sharp.dll b/websocket-sharp/bin/Debug_Ubuntu/websocket-sharp.dll index a868c718..c80dd6d9 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/Debug_Ubuntu/websocket-sharp.dll.mdb b/websocket-sharp/bin/Debug_Ubuntu/websocket-sharp.dll.mdb index 97c87fac..e3582a6b 100644 Binary files a/websocket-sharp/bin/Debug_Ubuntu/websocket-sharp.dll.mdb and b/websocket-sharp/bin/Debug_Ubuntu/websocket-sharp.dll.mdb differ diff --git a/websocket-sharp/bin/Release/websocket-sharp.dll b/websocket-sharp/bin/Release/websocket-sharp.dll index 5cb2e8a3..9f4c0c65 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 89c7e9fd..4b57a6a1 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 560a4eec..dff297a2 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 ] diff --git a/websocket-sharp/websocket-sharp.pidb b/websocket-sharp/websocket-sharp.pidb index 0aea65fd..c8f7d8cb 100644 Binary files a/websocket-sharp/websocket-sharp.pidb and b/websocket-sharp/websocket-sharp.pidb differ