Modified WebSocket.cs, Ext.cs
This commit is contained in:
parent
ee3746cc03
commit
4fa05f928b
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -1096,7 +1096,8 @@ namespace WebSocketSharp {
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Reads a block of bytes from the specified stream and returns the read data in an array of <see cref="byte"/>.
|
||||
/// Reads a block of bytes from the specified <see cref="Stream"/>
|
||||
/// and returns the read data in an array of <see cref="byte"/>.
|
||||
/// </summary>
|
||||
/// <returns>
|
||||
/// An array of <see cref="byte"/> 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 {
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Reads a block of bytes from the specified stream and returns the read data in an array of <see cref="byte"/>.
|
||||
/// Reads a block of bytes from the specified <see cref="Stream"/>
|
||||
/// and returns the read data in an array of <see cref="byte"/>.
|
||||
/// </summary>
|
||||
/// <returns>
|
||||
/// An array of <see cref="byte"/> 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<byte>();
|
||||
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<byte[]> 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<byte[], bool> read = buffer =>
|
||||
{
|
||||
readLen += tmpLen;
|
||||
readData.AddRange(buffer.SubArray(0, tmpLen));
|
||||
bufferLen = buffer.Length;
|
||||
readLen = stream.Read(buffer, 0, bufferLen);
|
||||
if (readLen <= 0)
|
||||
return false;
|
||||
|
||||
while (readLen < bufferLen)
|
||||
{
|
||||
tmpLen = stream.Read(buffer, readLen, bufferLen - readLen);
|
||||
if (tmpLen <= 0)
|
||||
break;
|
||||
|
||||
readLen += tmpLen;
|
||||
}
|
||||
|
||||
readData.Write(buffer, 0, readLen);
|
||||
return readLen == bufferLen;
|
||||
};
|
||||
|
||||
var readBuffer = new byte[bufferLength];
|
||||
var cont = true;
|
||||
for (long i = 0; i < count; i++)
|
||||
{
|
||||
if (!read(readBuffer))
|
||||
{
|
||||
cont = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
count.Times(() =>
|
||||
{
|
||||
read(readBuffer);
|
||||
});
|
||||
if (cont && rem > 0)
|
||||
read(new byte[rem]);
|
||||
|
||||
if (rem > 0)
|
||||
read(new byte[rem]);
|
||||
|
||||
return readLen > 0
|
||||
? readData.ToArray()
|
||||
: new byte[]{};
|
||||
readData.Close();
|
||||
return readData.ToArray();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
@ -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);
|
||||
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -402,7 +402,8 @@
|
||||
</member>
|
||||
<member name="M:WebSocketSharp.Ext.ReadBytes(System.IO.Stream,System.Int32)">
|
||||
<summary>
|
||||
Reads a block of bytes from the specified stream and returns the read data in an array of <see cref="T:System.Byte" />.
|
||||
Reads a block of bytes from the specified <see cref="T:System.IO.Stream" />
|
||||
and returns the read data in an array of <see cref="T:System.Byte" />.
|
||||
</summary>
|
||||
<returns>
|
||||
An array of <see cref="T:System.Byte" /> that receives the read data.
|
||||
@ -430,7 +431,8 @@
|
||||
</member>
|
||||
<member name="M:WebSocketSharp.Ext.ReadBytes(System.IO.Stream,System.Int64,System.Int32)">
|
||||
<summary>
|
||||
Reads a block of bytes from the specified stream and returns the read data in an array of <see cref="T:System.Byte" />.
|
||||
Reads a block of bytes from the specified <see cref="T:System.IO.Stream" />
|
||||
and returns the read data in an array of <see cref="T:System.Byte" />.
|
||||
</summary>
|
||||
<returns>
|
||||
An array of <see cref="T:System.Byte" /> that receives the read data.
|
||||
|
@ -533,7 +533,8 @@
|
||||
<b>
|
||||
<a href="#M:WebSocketSharp.Ext.ReadBytes(System.IO.Stream,System.Int32)">ReadBytes</a>
|
||||
</b>(<i>this</i> <a href="http://www.go-mono.com/docs/monodoc.ashx?link=T:System.IO.Stream">System.IO.Stream</a>, <a href="http://www.go-mono.com/docs/monodoc.ashx?link=T:System.Int32">int</a>)<nobr> : <a href="http://www.go-mono.com/docs/monodoc.ashx?link=T:System.Byte">byte</a>[]</nobr><blockquote>
|
||||
Reads a block of bytes from the specified stream and returns the read data in an array of <a href="http://www.go-mono.com/docs/monodoc.ashx?link=T:System.Byte">byte</a>.
|
||||
Reads a block of bytes from the specified <a href="http://www.go-mono.com/docs/monodoc.ashx?link=T:System.IO.Stream">System.IO.Stream</a>
|
||||
and returns the read data in an array of <a href="http://www.go-mono.com/docs/monodoc.ashx?link=T:System.Byte">byte</a>.
|
||||
</blockquote></td>
|
||||
</tr>
|
||||
<tr valign="top">
|
||||
@ -555,7 +556,8 @@
|
||||
<b>
|
||||
<a href="#M:WebSocketSharp.Ext.ReadBytes(System.IO.Stream,System.Int64,System.Int32)">ReadBytes</a>
|
||||
</b>(<i>this</i> <a href="http://www.go-mono.com/docs/monodoc.ashx?link=T:System.IO.Stream">System.IO.Stream</a>, <a href="http://www.go-mono.com/docs/monodoc.ashx?link=T:System.Int64">long</a>, <a href="http://www.go-mono.com/docs/monodoc.ashx?link=T:System.Int32">int</a>)<nobr> : <a href="http://www.go-mono.com/docs/monodoc.ashx?link=T:System.Byte">byte</a>[]</nobr><blockquote>
|
||||
Reads a block of bytes from the specified stream and returns the read data in an array of <a href="http://www.go-mono.com/docs/monodoc.ashx?link=T:System.Byte">byte</a>.
|
||||
Reads a block of bytes from the specified <a href="http://www.go-mono.com/docs/monodoc.ashx?link=T:System.IO.Stream">System.IO.Stream</a>
|
||||
and returns the read data in an array of <a href="http://www.go-mono.com/docs/monodoc.ashx?link=T:System.Byte">byte</a>.
|
||||
</blockquote></td>
|
||||
</tr>
|
||||
<tr valign="top">
|
||||
@ -1822,7 +1824,8 @@
|
||||
<h3 id="M:WebSocketSharp.Ext.ReadBytes(System.IO.Stream,System.Int32)">ReadBytes Method</h3>
|
||||
<blockquote id="M:WebSocketSharp.Ext.ReadBytes(System.IO.Stream,System.Int32):member">
|
||||
<p class="Summary">
|
||||
Reads a block of bytes from the specified stream and returns the read data in an array of <a href="http://www.go-mono.com/docs/monodoc.ashx?link=T:System.Byte">byte</a>.
|
||||
Reads a block of bytes from the specified <a href="http://www.go-mono.com/docs/monodoc.ashx?link=T:System.IO.Stream">System.IO.Stream</a>
|
||||
and returns the read data in an array of <a href="http://www.go-mono.com/docs/monodoc.ashx?link=T:System.Byte">byte</a>.
|
||||
</p>
|
||||
<h2>Syntax</h2>
|
||||
<div class="Signature">public static <a href="http://www.go-mono.com/docs/monodoc.ashx?link=T:System.Byte">byte</a>[] <b>ReadBytes</b> (<i>this</i> <a href="http://www.go-mono.com/docs/monodoc.ashx?link=T:System.IO.Stream">System.IO.Stream</a> stream, <a href="http://www.go-mono.com/docs/monodoc.ashx?link=T:System.Int32">int</a> length)</div>
|
||||
@ -1896,7 +1899,8 @@
|
||||
<h3 id="M:WebSocketSharp.Ext.ReadBytes(System.IO.Stream,System.Int64,System.Int32)">ReadBytes Method</h3>
|
||||
<blockquote id="M:WebSocketSharp.Ext.ReadBytes(System.IO.Stream,System.Int64,System.Int32):member">
|
||||
<p class="Summary">
|
||||
Reads a block of bytes from the specified stream and returns the read data in an array of <a href="http://www.go-mono.com/docs/monodoc.ashx?link=T:System.Byte">byte</a>.
|
||||
Reads a block of bytes from the specified <a href="http://www.go-mono.com/docs/monodoc.ashx?link=T:System.IO.Stream">System.IO.Stream</a>
|
||||
and returns the read data in an array of <a href="http://www.go-mono.com/docs/monodoc.ashx?link=T:System.Byte">byte</a>.
|
||||
</p>
|
||||
<h2>Syntax</h2>
|
||||
<div class="Signature">public static <a href="http://www.go-mono.com/docs/monodoc.ashx?link=T:System.Byte">byte</a>[] <b>ReadBytes</b> (<i>this</i> <a href="http://www.go-mono.com/docs/monodoc.ashx?link=T:System.IO.Stream">System.IO.Stream</a> stream, <a href="http://www.go-mono.com/docs/monodoc.ashx?link=T:System.Int64">long</a> length, <a href="http://www.go-mono.com/docs/monodoc.ashx?link=T:System.Int32">int</a> bufferLength)</div>
|
||||
|
@ -771,7 +771,8 @@
|
||||
An <see cref="T:System.Int32" /> that contains the number of bytes to read.
|
||||
</param>
|
||||
<summary>
|
||||
Reads a block of bytes from the specified stream and returns the read data in an array of <see cref="T:System.Byte" />.
|
||||
Reads a block of bytes from the specified <see cref="T:System.IO.Stream" />
|
||||
and returns the read data in an array of <see cref="T:System.Byte" />.
|
||||
</summary>
|
||||
<returns>
|
||||
An array of <see cref="T:System.Byte" /> that receives the read data.
|
||||
@ -829,7 +830,8 @@
|
||||
An <see cref="T:System.Int32" /> that contains the buffer size in bytes of each internal read.
|
||||
</param>
|
||||
<summary>
|
||||
Reads a block of bytes from the specified stream and returns the read data in an array of <see cref="T:System.Byte" />.
|
||||
Reads a block of bytes from the specified <see cref="T:System.IO.Stream" />
|
||||
and returns the read data in an array of <see cref="T:System.Byte" />.
|
||||
</summary>
|
||||
<returns>
|
||||
An array of <see cref="T:System.Byte" /> that receives the read data.
|
||||
|
@ -1,6 +1,6 @@
|
||||
<Overview>
|
||||
<Assemblies>
|
||||
<Assembly Name="websocket-sharp" Version="1.0.2.41223">
|
||||
<Assembly Name="websocket-sharp" Version="1.0.2.3113">
|
||||
<AssemblyPublicKey>[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 ]</AssemblyPublicKey>
|
||||
<Attributes>
|
||||
<Attribute>
|
||||
@ -866,7 +866,8 @@
|
||||
An <see cref="T:System.Int32" /> that contains the number of bytes to read.
|
||||
</param>
|
||||
<summary>
|
||||
Reads a block of bytes from the specified stream and returns the read data in an array of <see cref="T:System.Byte" />.
|
||||
Reads a block of bytes from the specified <see cref="T:System.IO.Stream" />
|
||||
and returns the read data in an array of <see cref="T:System.Byte" />.
|
||||
</summary>
|
||||
</Docs>
|
||||
<Link Type="WebSocketSharp.Ext" Member="M:WebSocketSharp.Ext.ReadBytes(System.IO.Stream,System.Int32)" />
|
||||
@ -928,7 +929,8 @@
|
||||
An <see cref="T:System.Int32" /> that contains the buffer size in bytes of each internal read.
|
||||
</param>
|
||||
<summary>
|
||||
Reads a block of bytes from the specified stream and returns the read data in an array of <see cref="T:System.Byte" />.
|
||||
Reads a block of bytes from the specified <see cref="T:System.IO.Stream" />
|
||||
and returns the read data in an array of <see cref="T:System.Byte" />.
|
||||
</summary>
|
||||
</Docs>
|
||||
<Link Type="WebSocketSharp.Ext" Member="M:WebSocketSharp.Ext.ReadBytes(System.IO.Stream,System.Int64,System.Int32)" />
|
||||
|
Loading…
Reference in New Issue
Block a user