Fix due to the modified WebSocket.cs
This commit is contained in:
parent
dc3a8f3836
commit
fa7aae6ae2
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.
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.
@ -1,5 +1,5 @@
|
|||||||
<Properties>
|
<Properties>
|
||||||
<MonoDevelop.Ide.Workspace ActiveConfiguration="Release_Ubuntu" />
|
<MonoDevelop.Ide.Workspace ActiveConfiguration="Debug_Ubuntu" />
|
||||||
<MonoDevelop.Ide.Workbench />
|
<MonoDevelop.Ide.Workbench />
|
||||||
<MonoDevelop.Ide.DebuggingService.Breakpoints>
|
<MonoDevelop.Ide.DebuggingService.Breakpoints>
|
||||||
<BreakpointStore />
|
<BreakpointStore />
|
||||||
|
@ -236,27 +236,34 @@ namespace WebSocketSharp
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static byte[] ReadBytes<TStream>(this TStream stream, ulong length, int bufferLength)
|
public static byte[] ReadBytes(this Stream stream, int length)
|
||||||
where TStream : System.IO.Stream
|
|
||||||
{
|
{
|
||||||
ulong count = length / (ulong)bufferLength;
|
var buffer = new byte[length];
|
||||||
int remainder = (int)(length % (ulong)bufferLength);
|
stream.Read(buffer, 0, length);
|
||||||
|
return buffer;
|
||||||
|
}
|
||||||
|
|
||||||
List<byte> readData = new List<byte>();
|
public static byte[] ReadBytes(this Stream stream, long length, int bufferLength)
|
||||||
byte[] buffer1 = new byte[bufferLength];
|
{
|
||||||
int readLen = 0;
|
var count = length / bufferLength;
|
||||||
|
var rem = length % bufferLength;
|
||||||
|
var readData = new List<byte>();
|
||||||
|
var readLen = 0;
|
||||||
|
var buffer = new byte[bufferLength];
|
||||||
|
|
||||||
count.Times(() =>
|
count.Times(() =>
|
||||||
{
|
{
|
||||||
readLen = stream.Read(buffer1, 0, bufferLength);
|
readLen = stream.Read(buffer, 0, bufferLength);
|
||||||
if (readLen > 0) readData.AddRange(buffer1.SubArray(0, readLen));
|
if (readLen > 0)
|
||||||
|
readData.AddRange(buffer.SubArray(0, readLen));
|
||||||
});
|
});
|
||||||
|
|
||||||
if (remainder > 0)
|
if (rem > 0)
|
||||||
{
|
{
|
||||||
byte[] buffer2 = new byte[remainder];
|
buffer = new byte[rem];
|
||||||
readLen = stream.Read(buffer2, 0, remainder);
|
readLen = stream.Read(buffer, 0, (int)rem);
|
||||||
if (readLen > 0) readData.AddRange(buffer2.SubArray(0, readLen));
|
if (readLen > 0)
|
||||||
|
readData.AddRange(buffer.SubArray(0, readLen));
|
||||||
}
|
}
|
||||||
|
|
||||||
return readData.ToArray();
|
return readData.ToArray();
|
||||||
@ -284,6 +291,11 @@ namespace WebSocketSharp
|
|||||||
((ulong)n).Times(act);
|
((ulong)n).Times(act);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static void Times(this long n, Action act)
|
||||||
|
{
|
||||||
|
((ulong)n).Times(act);
|
||||||
|
}
|
||||||
|
|
||||||
public static void Times(this ulong n, Action act)
|
public static void Times(this ulong n, Action act)
|
||||||
{
|
{
|
||||||
for (ulong i = 0; i < n; i++)
|
for (ulong i = 0; i < n; i++)
|
||||||
@ -300,6 +312,11 @@ namespace WebSocketSharp
|
|||||||
((ulong)n).Times(act);
|
((ulong)n).Times(act);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static void Times(this long n, Action<ulong> act)
|
||||||
|
{
|
||||||
|
((ulong)n).Times(act);
|
||||||
|
}
|
||||||
|
|
||||||
public static void Times(this ulong n, Action<ulong> act)
|
public static void Times(this ulong n, Action<ulong> act)
|
||||||
{
|
{
|
||||||
for (ulong i = 0; i < n; i++)
|
for (ulong i = 0; i < n; i++)
|
||||||
|
@ -290,7 +290,7 @@ namespace WebSocketSharp.Frame
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
buffer3 = stream.ReadBytes(buffer3Len, _readBufferLen);
|
buffer3 = stream.ReadBytes((long)buffer3Len, _readBufferLen);
|
||||||
|
|
||||||
if ((ulong)buffer3.LongLength < buffer3Len)
|
if ((ulong)buffer3.LongLength < buffer3Len)
|
||||||
{
|
{
|
||||||
|
@ -52,6 +52,7 @@ namespace WebSocketSharp
|
|||||||
{
|
{
|
||||||
#region Private Const Fields
|
#region Private Const Fields
|
||||||
|
|
||||||
|
private const int _fragmentLen = 1016; // Max value is int.MaxValue - 14.
|
||||||
private const string _guid = "258EAFA5-E914-47DA-95CA-C5AB0DC85B11";
|
private const string _guid = "258EAFA5-E914-47DA-95CA-C5AB0DC85B11";
|
||||||
private const string _version = "13";
|
private const string _version = "13";
|
||||||
|
|
||||||
@ -68,7 +69,6 @@ namespace WebSocketSharp
|
|||||||
private string _extensions;
|
private string _extensions;
|
||||||
private Object _forClose;
|
private Object _forClose;
|
||||||
private Object _forSend;
|
private Object _forSend;
|
||||||
private int _fragmentLen;
|
|
||||||
private bool _isClient;
|
private bool _isClient;
|
||||||
private bool _isSecure;
|
private bool _isSecure;
|
||||||
private string _protocol;
|
private string _protocol;
|
||||||
@ -90,7 +90,6 @@ namespace WebSocketSharp
|
|||||||
_extensions = String.Empty;
|
_extensions = String.Empty;
|
||||||
_forClose = new Object();
|
_forClose = new Object();
|
||||||
_forSend = new Object();
|
_forSend = new Object();
|
||||||
_fragmentLen = 1024; // Max value is int.MaxValue - 14.
|
|
||||||
_protocol = String.Empty;
|
_protocol = String.Empty;
|
||||||
_readyState = WsState.CONNECTING;
|
_readyState = WsState.CONNECTING;
|
||||||
_receivedPong = new AutoResetEvent(false);
|
_receivedPong = new AutoResetEvent(false);
|
||||||
@ -793,7 +792,7 @@ namespace WebSocketSharp
|
|||||||
if (_readyState == WsState.CONNECTING ||
|
if (_readyState == WsState.CONNECTING ||
|
||||||
_readyState == WsState.CLOSED)
|
_readyState == WsState.CLOSED)
|
||||||
{
|
{
|
||||||
var msg = "Connection isn't established or connection was closed.";
|
var msg = "Connection isn't established or has been closed.";
|
||||||
error(msg);
|
error(msg);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -826,22 +825,21 @@ namespace WebSocketSharp
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void send(Opcode opcode, PayloadData data)
|
private void send(Opcode opcode, byte[] data)
|
||||||
{
|
{
|
||||||
using (MemoryStream ms = new MemoryStream(data.ToBytes()))
|
using (MemoryStream ms = new MemoryStream(data))
|
||||||
{
|
{
|
||||||
send(opcode, ms);
|
send(opcode, ms);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void send<TStream>(Opcode opcode, TStream stream)
|
private void send(Opcode opcode, Stream stream)
|
||||||
where TStream : Stream
|
|
||||||
{
|
{
|
||||||
lock(_forSend)
|
lock (_forSend)
|
||||||
{
|
{
|
||||||
if (_readyState != WsState.OPEN)
|
if (_readyState != WsState.OPEN)
|
||||||
{
|
{
|
||||||
var msg = "Connection isn't established or connection was closed.";
|
var msg = "Connection isn't established or has been closed.";
|
||||||
error(msg);
|
error(msg);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -849,79 +847,47 @@ namespace WebSocketSharp
|
|||||||
var length = stream.Length;
|
var length = stream.Length;
|
||||||
if (length <= _fragmentLen)
|
if (length <= _fragmentLen)
|
||||||
{
|
{
|
||||||
var buffer = new byte[length];
|
var buffer = stream.ReadBytes((int)length);
|
||||||
stream.Read(buffer, 0, (int)length);
|
send(Fin.FINAL, opcode, buffer);
|
||||||
var frame = createFrame(Fin.FINAL, opcode, new PayloadData(buffer));
|
return;
|
||||||
send(frame);
|
|
||||||
}
|
}
|
||||||
else
|
|
||||||
{
|
|
||||||
sendFragmented(opcode, stream);
|
sendFragmented(opcode, stream);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
private ulong sendFragmented<TStream>(Opcode opcode, TStream stream)
|
private void send(Fin fin, Opcode opcode, byte[] data)
|
||||||
where TStream : Stream
|
|
||||||
{
|
{
|
||||||
WsFrame frame;
|
var payloadData = new PayloadData(data);
|
||||||
PayloadData payloadData;
|
var frame = createFrame(fin, opcode, payloadData);
|
||||||
|
|
||||||
byte[] buffer1 = new byte[_fragmentLen];
|
|
||||||
byte[] buffer2 = new byte[_fragmentLen];
|
|
||||||
ulong readLen = 0;
|
|
||||||
int tmpLen1 = 0;
|
|
||||||
int tmpLen2 = 0;
|
|
||||||
|
|
||||||
tmpLen1 = stream.Read(buffer1, 0, _fragmentLen);
|
|
||||||
while (tmpLen1 > 0)
|
|
||||||
{
|
|
||||||
payloadData = new PayloadData(buffer1.SubArray(0, tmpLen1));
|
|
||||||
|
|
||||||
tmpLen2 = stream.Read(buffer2, 0, _fragmentLen);
|
|
||||||
if (tmpLen2 > 0)
|
|
||||||
{
|
|
||||||
if (readLen > 0)
|
|
||||||
{
|
|
||||||
frame = createFrame(Fin.MORE, Opcode.CONT, payloadData);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
frame = createFrame(Fin.MORE, opcode, payloadData);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
if (readLen > 0)
|
|
||||||
{
|
|
||||||
frame = createFrame(Fin.FINAL, Opcode.CONT, payloadData);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
frame = createFrame(Fin.FINAL, opcode, payloadData);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
readLen += (ulong)tmpLen1;
|
|
||||||
send(frame);
|
|
||||||
|
|
||||||
if (tmpLen2 == 0) break;
|
|
||||||
payloadData = new PayloadData(buffer2.SubArray(0, tmpLen2));
|
|
||||||
|
|
||||||
tmpLen1 = stream.Read(buffer1, 0, _fragmentLen);
|
|
||||||
if (tmpLen1 > 0)
|
|
||||||
{
|
|
||||||
frame = createFrame(Fin.MORE, Opcode.CONT, payloadData);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
frame = createFrame(Fin.FINAL, Opcode.CONT, payloadData);
|
|
||||||
}
|
|
||||||
|
|
||||||
readLen += (ulong)tmpLen2;
|
|
||||||
send(frame);
|
send(frame);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private long sendFragmented(Opcode opcode, Stream stream)
|
||||||
|
{
|
||||||
|
var length = stream.Length;
|
||||||
|
var quo = length / _fragmentLen;
|
||||||
|
var rem = length % _fragmentLen;
|
||||||
|
var count = rem == 0 ? quo - 2 : quo - 1;
|
||||||
|
|
||||||
|
// First
|
||||||
|
var buffer = new byte[_fragmentLen];
|
||||||
|
long readLen = stream.Read(buffer, 0, _fragmentLen);
|
||||||
|
send(Fin.MORE, opcode, buffer);
|
||||||
|
|
||||||
|
// Mid
|
||||||
|
count.Times(() =>
|
||||||
|
{
|
||||||
|
readLen += stream.Read(buffer, 0, _fragmentLen);
|
||||||
|
send(Fin.MORE, Opcode.CONT, buffer);
|
||||||
|
});
|
||||||
|
|
||||||
|
// Final
|
||||||
|
if (rem != 0)
|
||||||
|
buffer = new byte[rem];
|
||||||
|
readLen += stream.Read(buffer, 0, buffer.Length);
|
||||||
|
send(Fin.FINAL, Opcode.CONT, buffer);
|
||||||
|
|
||||||
return readLen;
|
return readLen;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1049,14 +1015,13 @@ namespace WebSocketSharp
|
|||||||
|
|
||||||
public void Send(string data)
|
public void Send(string data)
|
||||||
{
|
{
|
||||||
var payloadData = new PayloadData(data);
|
var buffer = Encoding.UTF8.GetBytes(data);
|
||||||
send(Opcode.TEXT, payloadData);
|
send(Opcode.TEXT, buffer);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Send(byte[] data)
|
public void Send(byte[] data)
|
||||||
{
|
{
|
||||||
var payloadData = new PayloadData(data);
|
send(Opcode.BINARY, data);
|
||||||
send(Opcode.BINARY, payloadData);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Send(FileInfo file)
|
public void Send(FileInfo file)
|
||||||
|
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.
Loading…
Reference in New Issue
Block a user