diff --git a/Example/bin/Debug/example.exe b/Example/bin/Debug/example.exe index 96fd9a04..6d0a9213 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 800d3ceb..2d16b542 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 0945a899..058adcd5 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 8e14ee3f..9175caf0 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 193f1e9e..4b24b22c 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 1324645a..a138726c 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 7b40b4c7..d07774a2 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 68b9ca92..73b88546 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 bb44cf3f..194c0626 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 800d3ceb..2d16b542 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 07aae19a..22f56a81 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 8e14ee3f..9175caf0 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 8db347aa..de169a3d 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 1324645a..a138726c 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 11d89835..f577383e 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 68b9ca92..73b88546 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 bfd139f3..621200fe 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 800d3ceb..2d16b542 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 6fa987bd..f487748f 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 8e14ee3f..9175caf0 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 2617b28d..470423be 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 1324645a..a138726c 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 7d4cfa0e..b7b6d78c 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 68b9ca92..73b88546 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 0d65df06..78f8ff71 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 800d3ceb..2d16b542 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 8b63c2b1..2ea2a5ec 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 8e14ee3f..9175caf0 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 d788ea96..7dc4b60f 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 1324645a..a138726c 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 6b08de79..e5fe2269 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 68b9ca92..73b88546 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/Ext.cs b/websocket-sharp/Ext.cs index 0a797eb4..c6c8a035 100644 --- a/websocket-sharp/Ext.cs +++ b/websocket-sharp/Ext.cs @@ -1096,7 +1096,8 @@ namespace WebSocketSharp { } /// - /// Reads a block of bytes from the specified stream and returns the read data in an array of . + /// Reads a block of bytes from the specified + /// and returns the read data in an array of . /// /// /// An array of that receives the read data. @@ -1112,8 +1113,20 @@ namespace WebSocketSharp { if (stream == null || length <= 0) return new byte[]{}; - var buffer = new byte[length]; + var buffer = new byte[length]; var readLen = stream.Read(buffer, 0, length); + if (readLen <= 0) + return new byte[]{}; + + var tmpLen = 0; + while (readLen < length) + { + tmpLen = stream.Read(buffer, readLen, length - readLen); + if (tmpLen <= 0) + break; + + readLen += tmpLen; + } return readLen == length ? buffer @@ -1140,7 +1153,8 @@ namespace WebSocketSharp { } /// - /// Reads a block of bytes from the specified stream and returns the read data in an array of . + /// Reads a block of bytes from the specified + /// and returns the read data in an array of . /// /// /// An array of that receives the read data. @@ -1162,34 +1176,53 @@ namespace WebSocketSharp { if (bufferLength <= 0) bufferLength = 1024; - var count = length / bufferLength; - var rem = length % bufferLength; - var readData = new List(); - var readBuffer = new byte[bufferLength]; - long readLen = 0; - var tmpLen = 0; + var count = length / bufferLength; + var rem = length % bufferLength; + if (count == 0) + return stream.ReadBytes((int)rem); - Action read = (buffer) => + using (var readData = new MemoryStream()) { - tmpLen = stream.Read(buffer, 0, buffer.Length); - if (tmpLen > 0) + var readLen = 0; + var bufferLen = 0; + var tmpLen = 0; + Func read = buffer => { - readLen += tmpLen; - readData.AddRange(buffer.SubArray(0, tmpLen)); - } - }; + bufferLen = buffer.Length; + readLen = stream.Read(buffer, 0, bufferLen); + if (readLen <= 0) + return false; - count.Times(() => - { - read(readBuffer); - }); + while (readLen < bufferLen) + { + tmpLen = stream.Read(buffer, readLen, bufferLen - readLen); + if (tmpLen <= 0) + break; + + readLen += tmpLen; + } - if (rem > 0) - read(new byte[rem]); + readData.Write(buffer, 0, readLen); + return readLen == bufferLen; + }; - return readLen > 0 - ? readData.ToArray() - : new byte[]{}; + var readBuffer = new byte[bufferLength]; + var cont = true; + for (long i = 0; i < count; i++) + { + if (!read(readBuffer)) + { + cont = false; + break; + } + } + + if (cont && rem > 0) + read(new byte[rem]); + + readData.Close(); + return readData.ToArray(); + } } /// diff --git a/websocket-sharp/WebSocket.cs b/websocket-sharp/WebSocket.cs index 1c99cd10..92dbbebe 100644 --- a/websocket-sharp/WebSocket.cs +++ b/websocket-sharp/WebSocket.cs @@ -1196,13 +1196,26 @@ namespace WebSocketSharp { var compressed = false; try { + if (_readyState != WsState.OPEN) + { + onError("The WebSocket connection isn't established or has been closed."); + return; + } + if (_compression != CompressionMethod.NONE) { data = data.Compress(_compression); compressed = true; } - send(opcode, data, compressed); + var length = data.Length; + lock (_forSend) + { + if (length <= _fragmentLen) + send(Fin.FINAL, opcode, data.ReadBytes((int)length), compressed); + else + sendFragmented(opcode, data, compressed); + } } catch (Exception ex) { @@ -1217,24 +1230,6 @@ namespace WebSocketSharp { } } - private void send(Opcode opcode, Stream stream, bool compressed) - { - lock (_forSend) - { - if (_readyState != WsState.OPEN) - { - onError("The WebSocket connection isn't established or has been closed."); - return; - } - - var length = stream.Length; - if (length <= _fragmentLen) - send(Fin.FINAL, opcode, stream.ReadBytes((int)length), compressed); - else - sendFragmented(opcode, stream, compressed); - } - } - private bool send(Fin fin, Opcode opcode, byte[] data, bool compressed) { var frame = createFrame(fin, opcode, new PayloadData(data), compressed, _client); diff --git a/websocket-sharp/bin/Debug/websocket-sharp.dll b/websocket-sharp/bin/Debug/websocket-sharp.dll index 800d3ceb..2d16b542 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 8e14ee3f..9175caf0 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 1324645a..a138726c 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 68b9ca92..73b88546 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/bin/Release_Ubuntu/websocket-sharp.xml b/websocket-sharp/bin/Release_Ubuntu/websocket-sharp.xml index 5e544832..af000dc0 100644 --- a/websocket-sharp/bin/Release_Ubuntu/websocket-sharp.xml +++ b/websocket-sharp/bin/Release_Ubuntu/websocket-sharp.xml @@ -402,7 +402,8 @@ - Reads a block of bytes from the specified stream and returns the read data in an array of . + Reads a block of bytes from the specified + and returns the read data in an array of . An array of that receives the read data. @@ -430,7 +431,8 @@ - Reads a block of bytes from the specified stream and returns the read data in an array of . + Reads a block of bytes from the specified + and returns the read data in an array of . An array of that receives the read data. diff --git a/websocket-sharp/doc/html/WebSocketSharp/Ext.html b/websocket-sharp/doc/html/WebSocketSharp/Ext.html index 11637cc3..1c09233f 100644 --- a/websocket-sharp/doc/html/WebSocketSharp/Ext.html +++ b/websocket-sharp/doc/html/WebSocketSharp/Ext.html @@ -533,7 +533,8 @@ ReadBytes (this System.IO.Stream, int) : byte[]
- Reads a block of bytes from the specified stream and returns the read data in an array of byte. + Reads a block of bytes from the specified System.IO.Stream + and returns the read data in an array of byte.
@@ -555,7 +556,8 @@ ReadBytes (this System.IO.Stream, long, int) : byte[]
- Reads a block of bytes from the specified stream and returns the read data in an array of byte. + Reads a block of bytes from the specified System.IO.Stream + and returns the read data in an array of byte.
@@ -1822,7 +1824,8 @@

ReadBytes Method

- Reads a block of bytes from the specified stream and returns the read data in an array of byte. + Reads a block of bytes from the specified System.IO.Stream + and returns the read data in an array of byte.

Syntax

public static byte[] ReadBytes (this System.IO.Stream stream, int length)
@@ -1896,7 +1899,8 @@

ReadBytes Method

- Reads a block of bytes from the specified stream and returns the read data in an array of byte. + Reads a block of bytes from the specified System.IO.Stream + and returns the read data in an array of byte.

Syntax

public static byte[] ReadBytes (this System.IO.Stream stream, long length, int bufferLength)
diff --git a/websocket-sharp/doc/mdoc/WebSocketSharp/Ext.xml b/websocket-sharp/doc/mdoc/WebSocketSharp/Ext.xml index d5e2a348..1f46727d 100644 --- a/websocket-sharp/doc/mdoc/WebSocketSharp/Ext.xml +++ b/websocket-sharp/doc/mdoc/WebSocketSharp/Ext.xml @@ -771,7 +771,8 @@ An that contains the number of bytes to read. - Reads a block of bytes from the specified stream and returns the read data in an array of . + Reads a block of bytes from the specified + and returns the read data in an array of . An array of that receives the read data. @@ -829,7 +830,8 @@ An that contains the buffer size in bytes of each internal read. - Reads a block of bytes from the specified stream and returns the read data in an array of . + Reads a block of bytes from the specified + and returns the read data in an array of . An array of that receives the read data. diff --git a/websocket-sharp/doc/mdoc/index.xml b/websocket-sharp/doc/mdoc/index.xml index 6105e709..d40954e5 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 ] @@ -866,7 +866,8 @@ An that contains the number of bytes to read. - Reads a block of bytes from the specified stream and returns the read data in an array of . + Reads a block of bytes from the specified + and returns the read data in an array of . @@ -928,7 +929,8 @@ An that contains the buffer size in bytes of each internal read. - Reads a block of bytes from the specified stream and returns the read data in an array of . + Reads a block of bytes from the specified + and returns the read data in an array of .